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 DJ |
5 | 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, |
6 | 2008 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" |
a77053c2 | 48 | |
9f976b41 | 49 | #include "gdb_assert.h" |
034dad6f | 50 | #include "mi/mi-common.h" |
c906108c SS |
51 | |
52 | /* Prototypes for local functions */ | |
53 | ||
96baa820 | 54 | static void signals_info (char *, int); |
c906108c | 55 | |
96baa820 | 56 | static void handle_command (char *, int); |
c906108c | 57 | |
96baa820 | 58 | static void sig_print_info (enum target_signal); |
c906108c | 59 | |
96baa820 | 60 | static void sig_print_header (void); |
c906108c | 61 | |
74b7792f | 62 | static void resume_cleanups (void *); |
c906108c | 63 | |
96baa820 | 64 | static int hook_stop_stub (void *); |
c906108c | 65 | |
96baa820 JM |
66 | static int restore_selected_frame (void *); |
67 | ||
68 | static void build_infrun (void); | |
69 | ||
4ef3f3be | 70 | static int follow_fork (void); |
96baa820 JM |
71 | |
72 | static void set_schedlock_func (char *args, int from_tty, | |
488f131b | 73 | struct cmd_list_element *c); |
96baa820 | 74 | |
96baa820 JM |
75 | struct execution_control_state; |
76 | ||
77 | static int currently_stepping (struct execution_control_state *ecs); | |
78 | ||
79 | static void xdb_handle_command (char *args, int from_tty); | |
80 | ||
6a6b96b9 | 81 | static int prepare_to_proceed (int); |
ea67f13b | 82 | |
96baa820 | 83 | void _initialize_infrun (void); |
43ff13b4 | 84 | |
5fbbeb29 CF |
85 | /* When set, stop the 'step' command if we enter a function which has |
86 | no line number information. The normal behavior is that we step | |
87 | over such function. */ | |
88 | int step_stop_if_no_debug = 0; | |
920d2a44 AC |
89 | static void |
90 | show_step_stop_if_no_debug (struct ui_file *file, int from_tty, | |
91 | struct cmd_list_element *c, const char *value) | |
92 | { | |
93 | fprintf_filtered (file, _("Mode of the step operation is %s.\n"), value); | |
94 | } | |
5fbbeb29 | 95 | |
43ff13b4 | 96 | /* In asynchronous mode, but simulating synchronous execution. */ |
96baa820 | 97 | |
43ff13b4 JM |
98 | int sync_execution = 0; |
99 | ||
c906108c SS |
100 | /* wait_for_inferior and normal_stop use this to notify the user |
101 | when the inferior stopped in a different thread than it had been | |
96baa820 JM |
102 | running in. */ |
103 | ||
39f77062 | 104 | static ptid_t previous_inferior_ptid; |
7a292a7a | 105 | |
237fc4c9 PA |
106 | int debug_displaced = 0; |
107 | static void | |
108 | show_debug_displaced (struct ui_file *file, int from_tty, | |
109 | struct cmd_list_element *c, const char *value) | |
110 | { | |
111 | fprintf_filtered (file, _("Displace stepping debugging is %s.\n"), value); | |
112 | } | |
113 | ||
527159b7 | 114 | static int debug_infrun = 0; |
920d2a44 AC |
115 | static void |
116 | show_debug_infrun (struct ui_file *file, int from_tty, | |
117 | struct cmd_list_element *c, const char *value) | |
118 | { | |
119 | fprintf_filtered (file, _("Inferior debugging is %s.\n"), value); | |
120 | } | |
527159b7 | 121 | |
d4f3574e SS |
122 | /* If the program uses ELF-style shared libraries, then calls to |
123 | functions in shared libraries go through stubs, which live in a | |
124 | table called the PLT (Procedure Linkage Table). The first time the | |
125 | function is called, the stub sends control to the dynamic linker, | |
126 | which looks up the function's real address, patches the stub so | |
127 | that future calls will go directly to the function, and then passes | |
128 | control to the function. | |
129 | ||
130 | If we are stepping at the source level, we don't want to see any of | |
131 | this --- we just want to skip over the stub and the dynamic linker. | |
132 | The simple approach is to single-step until control leaves the | |
133 | dynamic linker. | |
134 | ||
ca557f44 AC |
135 | However, on some systems (e.g., Red Hat's 5.2 distribution) the |
136 | dynamic linker calls functions in the shared C library, so you | |
137 | can't tell from the PC alone whether the dynamic linker is still | |
138 | running. In this case, we use a step-resume breakpoint to get us | |
139 | past the dynamic linker, as if we were using "next" to step over a | |
140 | function call. | |
d4f3574e SS |
141 | |
142 | IN_SOLIB_DYNSYM_RESOLVE_CODE says whether we're in the dynamic | |
143 | linker code or not. Normally, this means we single-step. However, | |
144 | if SKIP_SOLIB_RESOLVER then returns non-zero, then its value is an | |
145 | address where we can place a step-resume breakpoint to get past the | |
146 | linker's symbol resolution function. | |
147 | ||
148 | IN_SOLIB_DYNSYM_RESOLVE_CODE can generally be implemented in a | |
149 | pretty portable way, by comparing the PC against the address ranges | |
150 | of the dynamic linker's sections. | |
151 | ||
152 | SKIP_SOLIB_RESOLVER is generally going to be system-specific, since | |
153 | it depends on internal details of the dynamic linker. It's usually | |
154 | not too hard to figure out where to put a breakpoint, but it | |
155 | certainly isn't portable. SKIP_SOLIB_RESOLVER should do plenty of | |
156 | sanity checking. If it can't figure things out, returning zero and | |
157 | getting the (possibly confusing) stepping behavior is better than | |
158 | signalling an error, which will obscure the change in the | |
159 | inferior's state. */ | |
c906108c | 160 | |
c906108c SS |
161 | /* This function returns TRUE if pc is the address of an instruction |
162 | that lies within the dynamic linker (such as the event hook, or the | |
163 | dld itself). | |
164 | ||
165 | This function must be used only when a dynamic linker event has | |
166 | been caught, and the inferior is being stepped out of the hook, or | |
167 | undefined results are guaranteed. */ | |
168 | ||
169 | #ifndef SOLIB_IN_DYNAMIC_LINKER | |
170 | #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0 | |
171 | #endif | |
172 | ||
c2c6d25f | 173 | |
7a292a7a SS |
174 | /* Convert the #defines into values. This is temporary until wfi control |
175 | flow is completely sorted out. */ | |
176 | ||
692590c1 MS |
177 | #ifndef CANNOT_STEP_HW_WATCHPOINTS |
178 | #define CANNOT_STEP_HW_WATCHPOINTS 0 | |
179 | #else | |
180 | #undef CANNOT_STEP_HW_WATCHPOINTS | |
181 | #define CANNOT_STEP_HW_WATCHPOINTS 1 | |
182 | #endif | |
183 | ||
c906108c SS |
184 | /* Tables of how to react to signals; the user sets them. */ |
185 | ||
186 | static unsigned char *signal_stop; | |
187 | static unsigned char *signal_print; | |
188 | static unsigned char *signal_program; | |
189 | ||
190 | #define SET_SIGS(nsigs,sigs,flags) \ | |
191 | do { \ | |
192 | int signum = (nsigs); \ | |
193 | while (signum-- > 0) \ | |
194 | if ((sigs)[signum]) \ | |
195 | (flags)[signum] = 1; \ | |
196 | } while (0) | |
197 | ||
198 | #define UNSET_SIGS(nsigs,sigs,flags) \ | |
199 | do { \ | |
200 | int signum = (nsigs); \ | |
201 | while (signum-- > 0) \ | |
202 | if ((sigs)[signum]) \ | |
203 | (flags)[signum] = 0; \ | |
204 | } while (0) | |
205 | ||
39f77062 KB |
206 | /* Value to pass to target_resume() to cause all threads to resume */ |
207 | ||
208 | #define RESUME_ALL (pid_to_ptid (-1)) | |
c906108c SS |
209 | |
210 | /* Command list pointer for the "stop" placeholder. */ | |
211 | ||
212 | static struct cmd_list_element *stop_command; | |
213 | ||
c906108c SS |
214 | /* Function inferior was in as of last step command. */ |
215 | ||
216 | static struct symbol *step_start_function; | |
217 | ||
ca67fcb8 | 218 | /* Nonzero if we are presently stepping over a breakpoint. |
c906108c | 219 | |
ca67fcb8 VP |
220 | If we hit a breakpoint or watchpoint, and then continue, |
221 | we need to single step the current thread with breakpoints | |
222 | disabled, to avoid hitting the same breakpoint or | |
223 | watchpoint again. And we should step just a single | |
224 | thread and keep other threads stopped, so that | |
225 | other threads don't miss breakpoints while they are removed. | |
226 | ||
227 | So, this variable simultaneously means that we need to single | |
228 | step the current thread, keep other threads stopped, and that | |
229 | breakpoints should be removed while we step. | |
230 | ||
231 | This variable is set either: | |
232 | - in proceed, when we resume inferior on user's explicit request | |
233 | - in keep_going, if handle_inferior_event decides we need to | |
234 | step over breakpoint. | |
235 | ||
236 | The variable is cleared in clear_proceed_status, called every | |
237 | time before we call proceed. The proceed calls wait_for_inferior, | |
238 | which calls handle_inferior_event in a loop, and until | |
239 | wait_for_inferior exits, this variable is changed only by keep_going. */ | |
240 | ||
241 | static int stepping_over_breakpoint; | |
c906108c | 242 | |
c906108c SS |
243 | /* Nonzero if we want to give control to the user when we're notified |
244 | of shared library events by the dynamic linker. */ | |
245 | static int stop_on_solib_events; | |
920d2a44 AC |
246 | static void |
247 | show_stop_on_solib_events (struct ui_file *file, int from_tty, | |
248 | struct cmd_list_element *c, const char *value) | |
249 | { | |
250 | fprintf_filtered (file, _("Stopping for shared library events is %s.\n"), | |
251 | value); | |
252 | } | |
c906108c | 253 | |
c906108c SS |
254 | /* Nonzero means expecting a trace trap |
255 | and should stop the inferior and return silently when it happens. */ | |
256 | ||
257 | int stop_after_trap; | |
258 | ||
259 | /* Nonzero means expecting a trap and caller will handle it themselves. | |
260 | It is used after attach, due to attaching to a process; | |
261 | when running in the shell before the child program has been exec'd; | |
262 | and when running some kinds of remote stuff (FIXME?). */ | |
263 | ||
c0236d92 | 264 | enum stop_kind stop_soon; |
c906108c SS |
265 | |
266 | /* Nonzero if proceed is being used for a "finish" command or a similar | |
267 | situation when stop_registers should be saved. */ | |
268 | ||
269 | int proceed_to_finish; | |
270 | ||
271 | /* Save register contents here when about to pop a stack dummy frame, | |
272 | if-and-only-if proceed_to_finish is set. | |
273 | Thus this contains the return value from the called function (assuming | |
274 | values are returned in a register). */ | |
275 | ||
72cec141 | 276 | struct regcache *stop_registers; |
c906108c | 277 | |
c906108c SS |
278 | /* Nonzero after stop if current stack frame should be printed. */ |
279 | ||
280 | static int stop_print_frame; | |
281 | ||
282 | static struct breakpoint *step_resume_breakpoint = NULL; | |
c906108c | 283 | |
e02bc4cc | 284 | /* This is a cached copy of the pid/waitstatus of the last event |
9a4105ab AC |
285 | returned by target_wait()/deprecated_target_wait_hook(). This |
286 | information is returned by get_last_target_status(). */ | |
39f77062 | 287 | static ptid_t target_last_wait_ptid; |
e02bc4cc DS |
288 | static struct target_waitstatus target_last_waitstatus; |
289 | ||
c906108c SS |
290 | /* This is used to remember when a fork, vfork or exec event |
291 | was caught by a catchpoint, and thus the event is to be | |
292 | followed at the next resume of the inferior, and not | |
293 | immediately. */ | |
294 | static struct | |
488f131b JB |
295 | { |
296 | enum target_waitkind kind; | |
297 | struct | |
c906108c | 298 | { |
488f131b | 299 | int parent_pid; |
488f131b | 300 | int child_pid; |
c906108c | 301 | } |
488f131b JB |
302 | fork_event; |
303 | char *execd_pathname; | |
304 | } | |
c906108c SS |
305 | pending_follow; |
306 | ||
53904c9e AC |
307 | static const char follow_fork_mode_child[] = "child"; |
308 | static const char follow_fork_mode_parent[] = "parent"; | |
309 | ||
488f131b | 310 | static const char *follow_fork_mode_kind_names[] = { |
53904c9e AC |
311 | follow_fork_mode_child, |
312 | follow_fork_mode_parent, | |
313 | NULL | |
ef346e04 | 314 | }; |
c906108c | 315 | |
53904c9e | 316 | static const char *follow_fork_mode_string = follow_fork_mode_parent; |
920d2a44 AC |
317 | static void |
318 | show_follow_fork_mode_string (struct ui_file *file, int from_tty, | |
319 | struct cmd_list_element *c, const char *value) | |
320 | { | |
321 | fprintf_filtered (file, _("\ | |
322 | Debugger response to a program call of fork or vfork is \"%s\".\n"), | |
323 | value); | |
324 | } | |
c906108c SS |
325 | \f |
326 | ||
6604731b | 327 | static int |
4ef3f3be | 328 | follow_fork (void) |
c906108c | 329 | { |
ea1dd7bc | 330 | int follow_child = (follow_fork_mode_string == follow_fork_mode_child); |
c906108c | 331 | |
6604731b | 332 | return target_follow_fork (follow_child); |
c906108c SS |
333 | } |
334 | ||
6604731b DJ |
335 | void |
336 | follow_inferior_reset_breakpoints (void) | |
c906108c | 337 | { |
6604731b DJ |
338 | /* Was there a step_resume breakpoint? (There was if the user |
339 | did a "next" at the fork() call.) If so, explicitly reset its | |
340 | thread number. | |
341 | ||
342 | step_resumes are a form of bp that are made to be per-thread. | |
343 | Since we created the step_resume bp when the parent process | |
344 | was being debugged, and now are switching to the child process, | |
345 | from the breakpoint package's viewpoint, that's a switch of | |
346 | "threads". We must update the bp's notion of which thread | |
347 | it is for, or it'll be ignored when it triggers. */ | |
348 | ||
349 | if (step_resume_breakpoint) | |
350 | breakpoint_re_set_thread (step_resume_breakpoint); | |
351 | ||
352 | /* Reinsert all breakpoints in the child. The user may have set | |
353 | breakpoints after catching the fork, in which case those | |
354 | were never set in the child, but only in the parent. This makes | |
355 | sure the inserted breakpoints match the breakpoint list. */ | |
356 | ||
357 | breakpoint_re_set (); | |
358 | insert_breakpoints (); | |
c906108c | 359 | } |
c906108c | 360 | |
1adeb98a FN |
361 | /* EXECD_PATHNAME is assumed to be non-NULL. */ |
362 | ||
c906108c | 363 | static void |
96baa820 | 364 | follow_exec (int pid, char *execd_pathname) |
c906108c | 365 | { |
c906108c | 366 | int saved_pid = pid; |
7a292a7a SS |
367 | struct target_ops *tgt; |
368 | ||
c906108c SS |
369 | /* This is an exec event that we actually wish to pay attention to. |
370 | Refresh our symbol table to the newly exec'd program, remove any | |
371 | momentary bp's, etc. | |
372 | ||
373 | If there are breakpoints, they aren't really inserted now, | |
374 | since the exec() transformed our inferior into a fresh set | |
375 | of instructions. | |
376 | ||
377 | We want to preserve symbolic breakpoints on the list, since | |
378 | we have hopes that they can be reset after the new a.out's | |
379 | symbol table is read. | |
380 | ||
381 | However, any "raw" breakpoints must be removed from the list | |
382 | (e.g., the solib bp's), since their address is probably invalid | |
383 | now. | |
384 | ||
385 | And, we DON'T want to call delete_breakpoints() here, since | |
386 | that may write the bp's "shadow contents" (the instruction | |
387 | value that was overwritten witha TRAP instruction). Since | |
388 | we now have a new a.out, those shadow contents aren't valid. */ | |
389 | update_breakpoints_after_exec (); | |
390 | ||
391 | /* If there was one, it's gone now. We cannot truly step-to-next | |
392 | statement through an exec(). */ | |
393 | step_resume_breakpoint = NULL; | |
394 | step_range_start = 0; | |
395 | step_range_end = 0; | |
396 | ||
c906108c | 397 | /* What is this a.out's name? */ |
a3f17187 | 398 | printf_unfiltered (_("Executing new program: %s\n"), execd_pathname); |
c906108c SS |
399 | |
400 | /* We've followed the inferior through an exec. Therefore, the | |
401 | inferior has essentially been killed & reborn. */ | |
7a292a7a | 402 | |
c906108c | 403 | gdb_flush (gdb_stdout); |
e85a822c | 404 | generic_mourn_inferior (); |
488f131b | 405 | /* Because mourn_inferior resets inferior_ptid. */ |
e85a822c DJ |
406 | inferior_ptid = pid_to_ptid (saved_pid); |
407 | ||
408 | if (gdb_sysroot && *gdb_sysroot) | |
409 | { | |
410 | char *name = alloca (strlen (gdb_sysroot) | |
411 | + strlen (execd_pathname) | |
412 | + 1); | |
413 | strcpy (name, gdb_sysroot); | |
414 | strcat (name, execd_pathname); | |
415 | execd_pathname = name; | |
416 | } | |
c906108c SS |
417 | |
418 | /* That a.out is now the one to use. */ | |
419 | exec_file_attach (execd_pathname, 0); | |
420 | ||
421 | /* And also is where symbols can be found. */ | |
1adeb98a | 422 | symbol_file_add_main (execd_pathname, 0); |
c906108c SS |
423 | |
424 | /* Reset the shared library package. This ensures that we get | |
425 | a shlib event when the child reaches "_start", at which point | |
426 | the dld will have had a chance to initialize the child. */ | |
e85a822c | 427 | no_shared_libraries (NULL, 0); |
7a292a7a | 428 | #ifdef SOLIB_CREATE_INFERIOR_HOOK |
39f77062 | 429 | SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid)); |
a77053c2 MK |
430 | #else |
431 | solib_create_inferior_hook (); | |
7a292a7a | 432 | #endif |
c906108c SS |
433 | |
434 | /* Reinsert all breakpoints. (Those which were symbolic have | |
435 | been reset to the proper address in the new a.out, thanks | |
436 | to symbol_file_command...) */ | |
437 | insert_breakpoints (); | |
438 | ||
439 | /* The next resume of this inferior should bring it to the shlib | |
440 | startup breakpoints. (If the user had also set bp's on | |
441 | "main" from the old (parent) process, then they'll auto- | |
442 | matically get reset there in the new process.) */ | |
c906108c SS |
443 | } |
444 | ||
445 | /* Non-zero if we just simulating a single-step. This is needed | |
446 | because we cannot remove the breakpoints in the inferior process | |
447 | until after the `wait' in `wait_for_inferior'. */ | |
448 | static int singlestep_breakpoints_inserted_p = 0; | |
9f976b41 DJ |
449 | |
450 | /* The thread we inserted single-step breakpoints for. */ | |
451 | static ptid_t singlestep_ptid; | |
452 | ||
fd48f117 DJ |
453 | /* PC when we started this single-step. */ |
454 | static CORE_ADDR singlestep_pc; | |
455 | ||
9f976b41 DJ |
456 | /* If another thread hit the singlestep breakpoint, we save the original |
457 | thread here so that we can resume single-stepping it later. */ | |
458 | static ptid_t saved_singlestep_ptid; | |
459 | static int stepping_past_singlestep_breakpoint; | |
6a6b96b9 | 460 | |
ca67fcb8 VP |
461 | /* If not equal to null_ptid, this means that after stepping over breakpoint |
462 | is finished, we need to switch to deferred_step_ptid, and step it. | |
463 | ||
464 | The use case is when one thread has hit a breakpoint, and then the user | |
465 | has switched to another thread and issued 'step'. We need to step over | |
466 | breakpoint in the thread which hit the breakpoint, but then continue | |
467 | stepping the thread user has selected. */ | |
468 | static ptid_t deferred_step_ptid; | |
c906108c | 469 | \f |
237fc4c9 PA |
470 | /* Displaced stepping. */ |
471 | ||
472 | /* In non-stop debugging mode, we must take special care to manage | |
473 | breakpoints properly; in particular, the traditional strategy for | |
474 | stepping a thread past a breakpoint it has hit is unsuitable. | |
475 | 'Displaced stepping' is a tactic for stepping one thread past a | |
476 | breakpoint it has hit while ensuring that other threads running | |
477 | concurrently will hit the breakpoint as they should. | |
478 | ||
479 | The traditional way to step a thread T off a breakpoint in a | |
480 | multi-threaded program in all-stop mode is as follows: | |
481 | ||
482 | a0) Initially, all threads are stopped, and breakpoints are not | |
483 | inserted. | |
484 | a1) We single-step T, leaving breakpoints uninserted. | |
485 | a2) We insert breakpoints, and resume all threads. | |
486 | ||
487 | In non-stop debugging, however, this strategy is unsuitable: we | |
488 | don't want to have to stop all threads in the system in order to | |
489 | continue or step T past a breakpoint. Instead, we use displaced | |
490 | stepping: | |
491 | ||
492 | n0) Initially, T is stopped, other threads are running, and | |
493 | breakpoints are inserted. | |
494 | n1) We copy the instruction "under" the breakpoint to a separate | |
495 | location, outside the main code stream, making any adjustments | |
496 | to the instruction, register, and memory state as directed by | |
497 | T's architecture. | |
498 | n2) We single-step T over the instruction at its new location. | |
499 | n3) We adjust the resulting register and memory state as directed | |
500 | by T's architecture. This includes resetting T's PC to point | |
501 | back into the main instruction stream. | |
502 | n4) We resume T. | |
503 | ||
504 | This approach depends on the following gdbarch methods: | |
505 | ||
506 | - gdbarch_max_insn_length and gdbarch_displaced_step_location | |
507 | indicate where to copy the instruction, and how much space must | |
508 | be reserved there. We use these in step n1. | |
509 | ||
510 | - gdbarch_displaced_step_copy_insn copies a instruction to a new | |
511 | address, and makes any necessary adjustments to the instruction, | |
512 | register contents, and memory. We use this in step n1. | |
513 | ||
514 | - gdbarch_displaced_step_fixup adjusts registers and memory after | |
515 | we have successfuly single-stepped the instruction, to yield the | |
516 | same effect the instruction would have had if we had executed it | |
517 | at its original address. We use this in step n3. | |
518 | ||
519 | - gdbarch_displaced_step_free_closure provides cleanup. | |
520 | ||
521 | The gdbarch_displaced_step_copy_insn and | |
522 | gdbarch_displaced_step_fixup functions must be written so that | |
523 | copying an instruction with gdbarch_displaced_step_copy_insn, | |
524 | single-stepping across the copied instruction, and then applying | |
525 | gdbarch_displaced_insn_fixup should have the same effects on the | |
526 | thread's memory and registers as stepping the instruction in place | |
527 | would have. Exactly which responsibilities fall to the copy and | |
528 | which fall to the fixup is up to the author of those functions. | |
529 | ||
530 | See the comments in gdbarch.sh for details. | |
531 | ||
532 | Note that displaced stepping and software single-step cannot | |
533 | currently be used in combination, although with some care I think | |
534 | they could be made to. Software single-step works by placing | |
535 | breakpoints on all possible subsequent instructions; if the | |
536 | displaced instruction is a PC-relative jump, those breakpoints | |
537 | could fall in very strange places --- on pages that aren't | |
538 | executable, or at addresses that are not proper instruction | |
539 | boundaries. (We do generally let other threads run while we wait | |
540 | to hit the software single-step breakpoint, and they might | |
541 | encounter such a corrupted instruction.) One way to work around | |
542 | this would be to have gdbarch_displaced_step_copy_insn fully | |
543 | simulate the effect of PC-relative instructions (and return NULL) | |
544 | on architectures that use software single-stepping. | |
545 | ||
546 | In non-stop mode, we can have independent and simultaneous step | |
547 | requests, so more than one thread may need to simultaneously step | |
548 | over a breakpoint. The current implementation assumes there is | |
549 | only one scratch space per process. In this case, we have to | |
550 | serialize access to the scratch space. If thread A wants to step | |
551 | over a breakpoint, but we are currently waiting for some other | |
552 | thread to complete a displaced step, we leave thread A stopped and | |
553 | place it in the displaced_step_request_queue. Whenever a displaced | |
554 | step finishes, we pick the next thread in the queue and start a new | |
555 | displaced step operation on it. See displaced_step_prepare and | |
556 | displaced_step_fixup for details. */ | |
557 | ||
558 | /* If this is not null_ptid, this is the thread carrying out a | |
559 | displaced single-step. This thread's state will require fixing up | |
560 | once it has completed its step. */ | |
561 | static ptid_t displaced_step_ptid; | |
562 | ||
563 | struct displaced_step_request | |
564 | { | |
565 | ptid_t ptid; | |
566 | struct displaced_step_request *next; | |
567 | }; | |
568 | ||
569 | /* A queue of pending displaced stepping requests. */ | |
570 | struct displaced_step_request *displaced_step_request_queue; | |
571 | ||
572 | /* The architecture the thread had when we stepped it. */ | |
573 | static struct gdbarch *displaced_step_gdbarch; | |
574 | ||
575 | /* The closure provided gdbarch_displaced_step_copy_insn, to be used | |
576 | for post-step cleanup. */ | |
577 | static struct displaced_step_closure *displaced_step_closure; | |
578 | ||
579 | /* The address of the original instruction, and the copy we made. */ | |
580 | static CORE_ADDR displaced_step_original, displaced_step_copy; | |
581 | ||
582 | /* Saved contents of copy area. */ | |
583 | static gdb_byte *displaced_step_saved_copy; | |
584 | ||
585 | /* When this is non-zero, we are allowed to use displaced stepping, if | |
586 | the architecture supports it. When this is zero, we use | |
587 | traditional the hold-and-step approach. */ | |
588 | int can_use_displaced_stepping = 1; | |
589 | static void | |
590 | show_can_use_displaced_stepping (struct ui_file *file, int from_tty, | |
591 | struct cmd_list_element *c, | |
592 | const char *value) | |
593 | { | |
594 | fprintf_filtered (file, _("\ | |
595 | Debugger's willingness to use displaced stepping to step over " | |
596 | "breakpoints is %s.\n"), value); | |
597 | } | |
598 | ||
599 | /* Return non-zero if displaced stepping is enabled, and can be used | |
600 | with GDBARCH. */ | |
601 | static int | |
602 | use_displaced_stepping (struct gdbarch *gdbarch) | |
603 | { | |
604 | return (can_use_displaced_stepping | |
605 | && gdbarch_displaced_step_copy_insn_p (gdbarch)); | |
606 | } | |
607 | ||
608 | /* Clean out any stray displaced stepping state. */ | |
609 | static void | |
610 | displaced_step_clear (void) | |
611 | { | |
612 | /* Indicate that there is no cleanup pending. */ | |
613 | displaced_step_ptid = null_ptid; | |
614 | ||
615 | if (displaced_step_closure) | |
616 | { | |
617 | gdbarch_displaced_step_free_closure (displaced_step_gdbarch, | |
618 | displaced_step_closure); | |
619 | displaced_step_closure = NULL; | |
620 | } | |
621 | } | |
622 | ||
623 | static void | |
624 | cleanup_displaced_step_closure (void *ptr) | |
625 | { | |
626 | struct displaced_step_closure *closure = ptr; | |
627 | ||
628 | gdbarch_displaced_step_free_closure (current_gdbarch, closure); | |
629 | } | |
630 | ||
631 | /* Dump LEN bytes at BUF in hex to FILE, followed by a newline. */ | |
632 | void | |
633 | displaced_step_dump_bytes (struct ui_file *file, | |
634 | const gdb_byte *buf, | |
635 | size_t len) | |
636 | { | |
637 | int i; | |
638 | ||
639 | for (i = 0; i < len; i++) | |
640 | fprintf_unfiltered (file, "%02x ", buf[i]); | |
641 | fputs_unfiltered ("\n", file); | |
642 | } | |
643 | ||
644 | /* Prepare to single-step, using displaced stepping. | |
645 | ||
646 | Note that we cannot use displaced stepping when we have a signal to | |
647 | deliver. If we have a signal to deliver and an instruction to step | |
648 | over, then after the step, there will be no indication from the | |
649 | target whether the thread entered a signal handler or ignored the | |
650 | signal and stepped over the instruction successfully --- both cases | |
651 | result in a simple SIGTRAP. In the first case we mustn't do a | |
652 | fixup, and in the second case we must --- but we can't tell which. | |
653 | Comments in the code for 'random signals' in handle_inferior_event | |
654 | explain how we handle this case instead. | |
655 | ||
656 | Returns 1 if preparing was successful -- this thread is going to be | |
657 | stepped now; or 0 if displaced stepping this thread got queued. */ | |
658 | static int | |
659 | displaced_step_prepare (ptid_t ptid) | |
660 | { | |
661 | struct cleanup *old_cleanups; | |
662 | struct regcache *regcache = get_thread_regcache (ptid); | |
663 | struct gdbarch *gdbarch = get_regcache_arch (regcache); | |
664 | CORE_ADDR original, copy; | |
665 | ULONGEST len; | |
666 | struct displaced_step_closure *closure; | |
667 | ||
668 | /* We should never reach this function if the architecture does not | |
669 | support displaced stepping. */ | |
670 | gdb_assert (gdbarch_displaced_step_copy_insn_p (gdbarch)); | |
671 | ||
672 | /* For the first cut, we're displaced stepping one thread at a | |
673 | time. */ | |
674 | ||
675 | if (!ptid_equal (displaced_step_ptid, null_ptid)) | |
676 | { | |
677 | /* Already waiting for a displaced step to finish. Defer this | |
678 | request and place in queue. */ | |
679 | struct displaced_step_request *req, *new_req; | |
680 | ||
681 | if (debug_displaced) | |
682 | fprintf_unfiltered (gdb_stdlog, | |
683 | "displaced: defering step of %s\n", | |
684 | target_pid_to_str (ptid)); | |
685 | ||
686 | new_req = xmalloc (sizeof (*new_req)); | |
687 | new_req->ptid = ptid; | |
688 | new_req->next = NULL; | |
689 | ||
690 | if (displaced_step_request_queue) | |
691 | { | |
692 | for (req = displaced_step_request_queue; | |
693 | req && req->next; | |
694 | req = req->next) | |
695 | ; | |
696 | req->next = new_req; | |
697 | } | |
698 | else | |
699 | displaced_step_request_queue = new_req; | |
700 | ||
701 | return 0; | |
702 | } | |
703 | else | |
704 | { | |
705 | if (debug_displaced) | |
706 | fprintf_unfiltered (gdb_stdlog, | |
707 | "displaced: stepping %s now\n", | |
708 | target_pid_to_str (ptid)); | |
709 | } | |
710 | ||
711 | displaced_step_clear (); | |
712 | ||
713 | original = read_pc_pid (ptid); | |
714 | ||
715 | copy = gdbarch_displaced_step_location (gdbarch); | |
716 | len = gdbarch_max_insn_length (gdbarch); | |
717 | ||
718 | /* Save the original contents of the copy area. */ | |
719 | displaced_step_saved_copy = xmalloc (len); | |
720 | old_cleanups = make_cleanup (free_current_contents, | |
721 | &displaced_step_saved_copy); | |
722 | read_memory (copy, displaced_step_saved_copy, len); | |
723 | if (debug_displaced) | |
724 | { | |
725 | fprintf_unfiltered (gdb_stdlog, "displaced: saved 0x%s: ", | |
726 | paddr_nz (copy)); | |
727 | displaced_step_dump_bytes (gdb_stdlog, displaced_step_saved_copy, len); | |
728 | }; | |
729 | ||
730 | closure = gdbarch_displaced_step_copy_insn (gdbarch, | |
731 | original, copy, regcache); | |
732 | ||
733 | /* We don't support the fully-simulated case at present. */ | |
734 | gdb_assert (closure); | |
735 | ||
736 | make_cleanup (cleanup_displaced_step_closure, closure); | |
737 | ||
738 | /* Resume execution at the copy. */ | |
739 | write_pc_pid (copy, ptid); | |
740 | ||
741 | discard_cleanups (old_cleanups); | |
742 | ||
743 | if (debug_displaced) | |
744 | fprintf_unfiltered (gdb_stdlog, "displaced: displaced pc to 0x%s\n", | |
745 | paddr_nz (copy)); | |
746 | ||
747 | /* Save the information we need to fix things up if the step | |
748 | succeeds. */ | |
749 | displaced_step_ptid = ptid; | |
750 | displaced_step_gdbarch = gdbarch; | |
751 | displaced_step_closure = closure; | |
752 | displaced_step_original = original; | |
753 | displaced_step_copy = copy; | |
754 | return 1; | |
755 | } | |
756 | ||
757 | static void | |
758 | displaced_step_clear_cleanup (void *ignore) | |
759 | { | |
760 | displaced_step_clear (); | |
761 | } | |
762 | ||
763 | static void | |
764 | write_memory_ptid (ptid_t ptid, CORE_ADDR memaddr, const gdb_byte *myaddr, int len) | |
765 | { | |
766 | struct cleanup *ptid_cleanup = save_inferior_ptid (); | |
767 | inferior_ptid = ptid; | |
768 | write_memory (memaddr, myaddr, len); | |
769 | do_cleanups (ptid_cleanup); | |
770 | } | |
771 | ||
772 | static void | |
773 | displaced_step_fixup (ptid_t event_ptid, enum target_signal signal) | |
774 | { | |
775 | struct cleanup *old_cleanups; | |
776 | ||
777 | /* Was this event for the pid we displaced? */ | |
778 | if (ptid_equal (displaced_step_ptid, null_ptid) | |
779 | || ! ptid_equal (displaced_step_ptid, event_ptid)) | |
780 | return; | |
781 | ||
782 | old_cleanups = make_cleanup (displaced_step_clear_cleanup, 0); | |
783 | ||
784 | /* Restore the contents of the copy area. */ | |
785 | { | |
786 | ULONGEST len = gdbarch_max_insn_length (displaced_step_gdbarch); | |
787 | write_memory_ptid (displaced_step_ptid, displaced_step_copy, | |
788 | displaced_step_saved_copy, len); | |
789 | if (debug_displaced) | |
790 | fprintf_unfiltered (gdb_stdlog, "displaced: restored 0x%s\n", | |
791 | paddr_nz (displaced_step_copy)); | |
792 | } | |
793 | ||
794 | /* Did the instruction complete successfully? */ | |
795 | if (signal == TARGET_SIGNAL_TRAP) | |
796 | { | |
797 | /* Fix up the resulting state. */ | |
798 | gdbarch_displaced_step_fixup (displaced_step_gdbarch, | |
799 | displaced_step_closure, | |
800 | displaced_step_original, | |
801 | displaced_step_copy, | |
802 | get_thread_regcache (displaced_step_ptid)); | |
803 | } | |
804 | else | |
805 | { | |
806 | /* Since the instruction didn't complete, all we can do is | |
807 | relocate the PC. */ | |
808 | CORE_ADDR pc = read_pc_pid (event_ptid); | |
809 | pc = displaced_step_original + (pc - displaced_step_copy); | |
810 | write_pc_pid (pc, event_ptid); | |
811 | } | |
812 | ||
813 | do_cleanups (old_cleanups); | |
814 | ||
815 | /* Are there any pending displaced stepping requests? If so, run | |
816 | one now. */ | |
817 | if (displaced_step_request_queue) | |
818 | { | |
819 | struct displaced_step_request *head; | |
820 | ptid_t ptid; | |
821 | ||
822 | head = displaced_step_request_queue; | |
823 | ptid = head->ptid; | |
824 | displaced_step_request_queue = head->next; | |
825 | xfree (head); | |
826 | ||
827 | if (debug_displaced) | |
828 | fprintf_unfiltered (gdb_stdlog, | |
829 | "displaced: stepping queued %s now\n", | |
830 | target_pid_to_str (ptid)); | |
831 | ||
832 | ||
833 | displaced_step_ptid = null_ptid; | |
834 | displaced_step_prepare (ptid); | |
835 | target_resume (ptid, 1, TARGET_SIGNAL_0); | |
836 | } | |
837 | } | |
838 | ||
839 | \f | |
840 | /* Resuming. */ | |
c906108c SS |
841 | |
842 | /* Things to clean up if we QUIT out of resume (). */ | |
c906108c | 843 | static void |
74b7792f | 844 | resume_cleanups (void *ignore) |
c906108c SS |
845 | { |
846 | normal_stop (); | |
847 | } | |
848 | ||
53904c9e AC |
849 | static const char schedlock_off[] = "off"; |
850 | static const char schedlock_on[] = "on"; | |
851 | static const char schedlock_step[] = "step"; | |
488f131b | 852 | static const char *scheduler_enums[] = { |
ef346e04 AC |
853 | schedlock_off, |
854 | schedlock_on, | |
855 | schedlock_step, | |
856 | NULL | |
857 | }; | |
920d2a44 AC |
858 | static const char *scheduler_mode = schedlock_off; |
859 | static void | |
860 | show_scheduler_mode (struct ui_file *file, int from_tty, | |
861 | struct cmd_list_element *c, const char *value) | |
862 | { | |
863 | fprintf_filtered (file, _("\ | |
864 | Mode for locking scheduler during execution is \"%s\".\n"), | |
865 | value); | |
866 | } | |
c906108c SS |
867 | |
868 | static void | |
96baa820 | 869 | set_schedlock_func (char *args, int from_tty, struct cmd_list_element *c) |
c906108c | 870 | { |
eefe576e AC |
871 | if (!target_can_lock_scheduler) |
872 | { | |
873 | scheduler_mode = schedlock_off; | |
874 | error (_("Target '%s' cannot support this command."), target_shortname); | |
875 | } | |
c906108c SS |
876 | } |
877 | ||
878 | ||
879 | /* Resume the inferior, but allow a QUIT. This is useful if the user | |
880 | wants to interrupt some lengthy single-stepping operation | |
881 | (for child processes, the SIGINT goes to the inferior, and so | |
882 | we get a SIGINT random_signal, but for remote debugging and perhaps | |
883 | other targets, that's not true). | |
884 | ||
885 | STEP nonzero if we should step (zero to continue instead). | |
886 | SIG is the signal to give the inferior (zero for none). */ | |
887 | void | |
96baa820 | 888 | resume (int step, enum target_signal sig) |
c906108c SS |
889 | { |
890 | int should_resume = 1; | |
74b7792f | 891 | struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0); |
237fc4c9 | 892 | CORE_ADDR pc = read_pc (); |
c906108c SS |
893 | QUIT; |
894 | ||
527159b7 | 895 | if (debug_infrun) |
237fc4c9 PA |
896 | fprintf_unfiltered (gdb_stdlog, |
897 | "infrun: resume (step=%d, signal=%d), " | |
898 | "stepping_over_breakpoint=%d\n", | |
899 | step, sig, stepping_over_breakpoint); | |
c906108c | 900 | |
692590c1 MS |
901 | /* Some targets (e.g. Solaris x86) have a kernel bug when stepping |
902 | over an instruction that causes a page fault without triggering | |
903 | a hardware watchpoint. The kernel properly notices that it shouldn't | |
904 | stop, because the hardware watchpoint is not triggered, but it forgets | |
905 | the step request and continues the program normally. | |
906 | Work around the problem by removing hardware watchpoints if a step is | |
907 | requested, GDB will check for a hardware watchpoint trigger after the | |
908 | step anyway. */ | |
c36b740a | 909 | if (CANNOT_STEP_HW_WATCHPOINTS && step) |
692590c1 | 910 | remove_hw_watchpoints (); |
488f131b | 911 | |
692590c1 | 912 | |
c2c6d25f JM |
913 | /* Normally, by the time we reach `resume', the breakpoints are either |
914 | removed or inserted, as appropriate. The exception is if we're sitting | |
915 | at a permanent breakpoint; we need to step over it, but permanent | |
916 | breakpoints can't be removed. So we have to test for it here. */ | |
237fc4c9 | 917 | if (breakpoint_here_p (pc) == permanent_breakpoint_here) |
6d350bb5 UW |
918 | { |
919 | if (gdbarch_skip_permanent_breakpoint_p (current_gdbarch)) | |
594f7785 UW |
920 | gdbarch_skip_permanent_breakpoint (current_gdbarch, |
921 | get_current_regcache ()); | |
6d350bb5 UW |
922 | else |
923 | error (_("\ | |
924 | The program is stopped at a permanent breakpoint, but GDB does not know\n\ | |
925 | how to step past a permanent breakpoint on this architecture. Try using\n\ | |
926 | a command like `return' or `jump' to continue execution.")); | |
927 | } | |
c2c6d25f | 928 | |
237fc4c9 PA |
929 | /* If enabled, step over breakpoints by executing a copy of the |
930 | instruction at a different address. | |
931 | ||
932 | We can't use displaced stepping when we have a signal to deliver; | |
933 | the comments for displaced_step_prepare explain why. The | |
934 | comments in the handle_inferior event for dealing with 'random | |
935 | signals' explain what we do instead. */ | |
936 | if (use_displaced_stepping (current_gdbarch) | |
937 | && stepping_over_breakpoint | |
938 | && sig == TARGET_SIGNAL_0) | |
939 | { | |
940 | if (!displaced_step_prepare (inferior_ptid)) | |
941 | /* Got placed in displaced stepping queue. Will be resumed | |
942 | later when all the currently queued displaced stepping | |
943 | requests finish. */ | |
944 | return; | |
945 | } | |
946 | ||
1c0fdd0e | 947 | if (step && gdbarch_software_single_step_p (current_gdbarch)) |
c906108c SS |
948 | { |
949 | /* Do it the hard way, w/temp breakpoints */ | |
1c0fdd0e | 950 | if (gdbarch_software_single_step (current_gdbarch, get_current_frame ())) |
e6590a1b UW |
951 | { |
952 | /* ...and don't ask hardware to do it. */ | |
953 | step = 0; | |
954 | /* and do not pull these breakpoints until after a `wait' in | |
955 | `wait_for_inferior' */ | |
956 | singlestep_breakpoints_inserted_p = 1; | |
957 | singlestep_ptid = inferior_ptid; | |
237fc4c9 | 958 | singlestep_pc = pc; |
e6590a1b | 959 | } |
c906108c SS |
960 | } |
961 | ||
c906108c | 962 | /* If there were any forks/vforks/execs that were caught and are |
6604731b | 963 | now to be followed, then do so. */ |
c906108c SS |
964 | switch (pending_follow.kind) |
965 | { | |
6604731b DJ |
966 | case TARGET_WAITKIND_FORKED: |
967 | case TARGET_WAITKIND_VFORKED: | |
c906108c | 968 | pending_follow.kind = TARGET_WAITKIND_SPURIOUS; |
6604731b DJ |
969 | if (follow_fork ()) |
970 | should_resume = 0; | |
c906108c SS |
971 | break; |
972 | ||
6604731b | 973 | case TARGET_WAITKIND_EXECD: |
c906108c | 974 | /* follow_exec is called as soon as the exec event is seen. */ |
6604731b | 975 | pending_follow.kind = TARGET_WAITKIND_SPURIOUS; |
c906108c SS |
976 | break; |
977 | ||
978 | default: | |
979 | break; | |
980 | } | |
c906108c SS |
981 | |
982 | /* Install inferior's terminal modes. */ | |
983 | target_terminal_inferior (); | |
984 | ||
985 | if (should_resume) | |
986 | { | |
39f77062 | 987 | ptid_t resume_ptid; |
dfcd3bfb | 988 | |
488f131b | 989 | resume_ptid = RESUME_ALL; /* Default */ |
ef5cf84e | 990 | |
cd76b0b7 VP |
991 | /* If STEP is set, it's a request to use hardware stepping |
992 | facilities. But in that case, we should never | |
993 | use singlestep breakpoint. */ | |
994 | gdb_assert (!(singlestep_breakpoints_inserted_p && step)); | |
995 | ||
996 | if (singlestep_breakpoints_inserted_p | |
997 | && stepping_past_singlestep_breakpoint) | |
c906108c | 998 | { |
cd76b0b7 VP |
999 | /* The situation here is as follows. In thread T1 we wanted to |
1000 | single-step. Lacking hardware single-stepping we've | |
1001 | set breakpoint at the PC of the next instruction -- call it | |
1002 | P. After resuming, we've hit that breakpoint in thread T2. | |
1003 | Now we've removed original breakpoint, inserted breakpoint | |
1004 | at P+1, and try to step to advance T2 past breakpoint. | |
1005 | We need to step only T2, as if T1 is allowed to freely run, | |
1006 | it can run past P, and if other threads are allowed to run, | |
1007 | they can hit breakpoint at P+1, and nested hits of single-step | |
1008 | breakpoints is not something we'd want -- that's complicated | |
1009 | to support, and has no value. */ | |
1010 | resume_ptid = inferior_ptid; | |
1011 | } | |
c906108c | 1012 | |
e842223a | 1013 | if ((step || singlestep_breakpoints_inserted_p) |
74960c60 | 1014 | && stepping_over_breakpoint) |
cd76b0b7 | 1015 | { |
74960c60 VP |
1016 | /* We're allowing a thread to run past a breakpoint it has |
1017 | hit, by single-stepping the thread with the breakpoint | |
1018 | removed. In which case, we need to single-step only this | |
1019 | thread, and keep others stopped, as they can miss this | |
1020 | breakpoint if allowed to run. | |
1021 | ||
1022 | The current code actually removes all breakpoints when | |
1023 | doing this, not just the one being stepped over, so if we | |
1024 | let other threads run, we can actually miss any | |
1025 | breakpoint, not just the one at PC. */ | |
ef5cf84e | 1026 | resume_ptid = inferior_ptid; |
c906108c | 1027 | } |
ef5cf84e | 1028 | |
8fb3e588 AC |
1029 | if ((scheduler_mode == schedlock_on) |
1030 | || (scheduler_mode == schedlock_step | |
1031 | && (step || singlestep_breakpoints_inserted_p))) | |
c906108c | 1032 | { |
ef5cf84e | 1033 | /* User-settable 'scheduler' mode requires solo thread resume. */ |
488f131b | 1034 | resume_ptid = inferior_ptid; |
c906108c | 1035 | } |
ef5cf84e | 1036 | |
e6cf7916 | 1037 | if (gdbarch_cannot_step_breakpoint (current_gdbarch)) |
c4ed33b9 AC |
1038 | { |
1039 | /* Most targets can step a breakpoint instruction, thus | |
1040 | executing it normally. But if this one cannot, just | |
1041 | continue and we will hit it anyway. */ | |
237fc4c9 | 1042 | if (step && breakpoint_inserted_here_p (pc)) |
c4ed33b9 AC |
1043 | step = 0; |
1044 | } | |
237fc4c9 PA |
1045 | |
1046 | if (debug_displaced | |
1047 | && use_displaced_stepping (current_gdbarch) | |
1048 | && stepping_over_breakpoint) | |
1049 | { | |
1050 | CORE_ADDR actual_pc = read_pc_pid (resume_ptid); | |
1051 | gdb_byte buf[4]; | |
1052 | ||
1053 | fprintf_unfiltered (gdb_stdlog, "displaced: run 0x%s: ", | |
1054 | paddr_nz (actual_pc)); | |
1055 | read_memory (actual_pc, buf, sizeof (buf)); | |
1056 | displaced_step_dump_bytes (gdb_stdlog, buf, sizeof (buf)); | |
1057 | } | |
1058 | ||
39f77062 | 1059 | target_resume (resume_ptid, step, sig); |
c906108c SS |
1060 | } |
1061 | ||
1062 | discard_cleanups (old_cleanups); | |
1063 | } | |
1064 | \f | |
237fc4c9 | 1065 | /* Proceeding. */ |
c906108c SS |
1066 | |
1067 | /* Clear out all variables saying what to do when inferior is continued. | |
1068 | First do this, then set the ones you want, then call `proceed'. */ | |
1069 | ||
1070 | void | |
96baa820 | 1071 | clear_proceed_status (void) |
c906108c | 1072 | { |
ca67fcb8 | 1073 | stepping_over_breakpoint = 0; |
c906108c SS |
1074 | step_range_start = 0; |
1075 | step_range_end = 0; | |
aa0cd9c1 | 1076 | step_frame_id = null_frame_id; |
5fbbeb29 | 1077 | step_over_calls = STEP_OVER_UNDEBUGGABLE; |
c906108c | 1078 | stop_after_trap = 0; |
c0236d92 | 1079 | stop_soon = NO_STOP_QUIETLY; |
c906108c SS |
1080 | proceed_to_finish = 0; |
1081 | breakpoint_proceeded = 1; /* We're about to proceed... */ | |
1082 | ||
d5c31457 UW |
1083 | if (stop_registers) |
1084 | { | |
1085 | regcache_xfree (stop_registers); | |
1086 | stop_registers = NULL; | |
1087 | } | |
1088 | ||
c906108c SS |
1089 | /* Discard any remaining commands or status from previous stop. */ |
1090 | bpstat_clear (&stop_bpstat); | |
1091 | } | |
1092 | ||
ea67f13b DJ |
1093 | /* This should be suitable for any targets that support threads. */ |
1094 | ||
1095 | static int | |
6a6b96b9 | 1096 | prepare_to_proceed (int step) |
ea67f13b DJ |
1097 | { |
1098 | ptid_t wait_ptid; | |
1099 | struct target_waitstatus wait_status; | |
1100 | ||
1101 | /* Get the last target status returned by target_wait(). */ | |
1102 | get_last_target_status (&wait_ptid, &wait_status); | |
1103 | ||
6a6b96b9 | 1104 | /* Make sure we were stopped at a breakpoint. */ |
ea67f13b | 1105 | if (wait_status.kind != TARGET_WAITKIND_STOPPED |
6a6b96b9 | 1106 | || wait_status.value.sig != TARGET_SIGNAL_TRAP) |
ea67f13b DJ |
1107 | { |
1108 | return 0; | |
1109 | } | |
1110 | ||
6a6b96b9 | 1111 | /* Switched over from WAIT_PID. */ |
ea67f13b | 1112 | if (!ptid_equal (wait_ptid, minus_one_ptid) |
6a6b96b9 UW |
1113 | && !ptid_equal (inferior_ptid, wait_ptid) |
1114 | && breakpoint_here_p (read_pc_pid (wait_ptid))) | |
ea67f13b | 1115 | { |
6a6b96b9 UW |
1116 | /* If stepping, remember current thread to switch back to. */ |
1117 | if (step) | |
ea67f13b | 1118 | { |
ca67fcb8 | 1119 | deferred_step_ptid = inferior_ptid; |
ea67f13b DJ |
1120 | } |
1121 | ||
6a6b96b9 UW |
1122 | /* Switch back to WAIT_PID thread. */ |
1123 | switch_to_thread (wait_ptid); | |
1124 | ||
8fb3e588 | 1125 | /* We return 1 to indicate that there is a breakpoint here, |
6a6b96b9 UW |
1126 | so we need to step over it before continuing to avoid |
1127 | hitting it straight away. */ | |
1128 | return 1; | |
ea67f13b DJ |
1129 | } |
1130 | ||
1131 | return 0; | |
ea67f13b | 1132 | } |
e4846b08 JJ |
1133 | |
1134 | /* Record the pc of the program the last time it stopped. This is | |
1135 | just used internally by wait_for_inferior, but need to be preserved | |
1136 | over calls to it and cleared when the inferior is started. */ | |
1137 | static CORE_ADDR prev_pc; | |
1138 | ||
c906108c SS |
1139 | /* Basic routine for continuing the program in various fashions. |
1140 | ||
1141 | ADDR is the address to resume at, or -1 for resume where stopped. | |
1142 | SIGGNAL is the signal to give it, or 0 for none, | |
c5aa993b | 1143 | or -1 for act according to how it stopped. |
c906108c | 1144 | STEP is nonzero if should trap after one instruction. |
c5aa993b JM |
1145 | -1 means return after that and print nothing. |
1146 | You should probably set various step_... variables | |
1147 | before calling here, if you are stepping. | |
c906108c SS |
1148 | |
1149 | You should call clear_proceed_status before calling proceed. */ | |
1150 | ||
1151 | void | |
96baa820 | 1152 | proceed (CORE_ADDR addr, enum target_signal siggnal, int step) |
c906108c SS |
1153 | { |
1154 | int oneproc = 0; | |
1155 | ||
1156 | if (step > 0) | |
1157 | step_start_function = find_pc_function (read_pc ()); | |
1158 | if (step < 0) | |
1159 | stop_after_trap = 1; | |
1160 | ||
2acceee2 | 1161 | if (addr == (CORE_ADDR) -1) |
c906108c | 1162 | { |
c906108c | 1163 | if (read_pc () == stop_pc && breakpoint_here_p (read_pc ())) |
3352ef37 AC |
1164 | /* There is a breakpoint at the address we will resume at, |
1165 | step one instruction before inserting breakpoints so that | |
1166 | we do not stop right away (and report a second hit at this | |
1167 | breakpoint). */ | |
c906108c | 1168 | oneproc = 1; |
3352ef37 AC |
1169 | else if (gdbarch_single_step_through_delay_p (current_gdbarch) |
1170 | && gdbarch_single_step_through_delay (current_gdbarch, | |
1171 | get_current_frame ())) | |
1172 | /* We stepped onto an instruction that needs to be stepped | |
1173 | again before re-inserting the breakpoint, do so. */ | |
c906108c SS |
1174 | oneproc = 1; |
1175 | } | |
1176 | else | |
1177 | { | |
1178 | write_pc (addr); | |
c906108c SS |
1179 | } |
1180 | ||
527159b7 | 1181 | if (debug_infrun) |
8a9de0e4 AC |
1182 | fprintf_unfiltered (gdb_stdlog, |
1183 | "infrun: proceed (addr=0x%s, signal=%d, step=%d)\n", | |
1184 | paddr_nz (addr), siggnal, step); | |
527159b7 | 1185 | |
c906108c SS |
1186 | /* In a multi-threaded task we may select another thread |
1187 | and then continue or step. | |
1188 | ||
1189 | But if the old thread was stopped at a breakpoint, it | |
1190 | will immediately cause another breakpoint stop without | |
1191 | any execution (i.e. it will report a breakpoint hit | |
1192 | incorrectly). So we must step over it first. | |
1193 | ||
ea67f13b | 1194 | prepare_to_proceed checks the current thread against the thread |
c906108c SS |
1195 | that reported the most recent event. If a step-over is required |
1196 | it returns TRUE and sets the current thread to the old thread. */ | |
6a6b96b9 | 1197 | if (prepare_to_proceed (step)) |
ea67f13b | 1198 | oneproc = 1; |
c906108c | 1199 | |
c906108c | 1200 | if (oneproc) |
74960c60 | 1201 | { |
74960c60 | 1202 | stepping_over_breakpoint = 1; |
237fc4c9 PA |
1203 | /* If displaced stepping is enabled, we can step over the |
1204 | breakpoint without hitting it, so leave all breakpoints | |
1205 | inserted. Otherwise we need to disable all breakpoints, step | |
1206 | one instruction, and then re-add them when that step is | |
1207 | finished. */ | |
1208 | if (!use_displaced_stepping (current_gdbarch)) | |
1209 | remove_breakpoints (); | |
74960c60 | 1210 | } |
237fc4c9 PA |
1211 | |
1212 | /* We can insert breakpoints if we're not trying to step over one, | |
1213 | or if we are stepping over one but we're using displaced stepping | |
1214 | to do so. */ | |
1215 | if (! stepping_over_breakpoint || use_displaced_stepping (current_gdbarch)) | |
c36b740a | 1216 | insert_breakpoints (); |
c906108c SS |
1217 | |
1218 | if (siggnal != TARGET_SIGNAL_DEFAULT) | |
1219 | stop_signal = siggnal; | |
1220 | /* If this signal should not be seen by program, | |
1221 | give it zero. Used for debugging signals. */ | |
1222 | else if (!signal_program[stop_signal]) | |
1223 | stop_signal = TARGET_SIGNAL_0; | |
1224 | ||
1225 | annotate_starting (); | |
1226 | ||
1227 | /* Make sure that output from GDB appears before output from the | |
1228 | inferior. */ | |
1229 | gdb_flush (gdb_stdout); | |
1230 | ||
e4846b08 JJ |
1231 | /* Refresh prev_pc value just prior to resuming. This used to be |
1232 | done in stop_stepping, however, setting prev_pc there did not handle | |
1233 | scenarios such as inferior function calls or returning from | |
1234 | a function via the return command. In those cases, the prev_pc | |
1235 | value was not set properly for subsequent commands. The prev_pc value | |
1236 | is used to initialize the starting line number in the ecs. With an | |
1237 | invalid value, the gdb next command ends up stopping at the position | |
1238 | represented by the next line table entry past our start position. | |
1239 | On platforms that generate one line table entry per line, this | |
1240 | is not a problem. However, on the ia64, the compiler generates | |
1241 | extraneous line table entries that do not increase the line number. | |
1242 | When we issue the gdb next command on the ia64 after an inferior call | |
1243 | or a return command, we often end up a few instructions forward, still | |
1244 | within the original line we started. | |
1245 | ||
1246 | An attempt was made to have init_execution_control_state () refresh | |
1247 | the prev_pc value before calculating the line number. This approach | |
1248 | did not work because on platforms that use ptrace, the pc register | |
1249 | cannot be read unless the inferior is stopped. At that point, we | |
1250 | are not guaranteed the inferior is stopped and so the read_pc () | |
1251 | call can fail. Setting the prev_pc value here ensures the value is | |
8fb3e588 | 1252 | updated correctly when the inferior is stopped. */ |
e4846b08 JJ |
1253 | prev_pc = read_pc (); |
1254 | ||
c906108c SS |
1255 | /* Resume inferior. */ |
1256 | resume (oneproc || step || bpstat_should_step (), stop_signal); | |
1257 | ||
1258 | /* Wait for it to stop (if not standalone) | |
1259 | and in any case decode why it stopped, and act accordingly. */ | |
43ff13b4 JM |
1260 | /* Do this only if we are not using the event loop, or if the target |
1261 | does not support asynchronous execution. */ | |
362646f5 | 1262 | if (!target_can_async_p ()) |
43ff13b4 | 1263 | { |
ae123ec6 | 1264 | wait_for_inferior (0); |
43ff13b4 JM |
1265 | normal_stop (); |
1266 | } | |
c906108c | 1267 | } |
c906108c SS |
1268 | \f |
1269 | ||
1270 | /* Start remote-debugging of a machine over a serial link. */ | |
96baa820 | 1271 | |
c906108c | 1272 | void |
8621d6a9 | 1273 | start_remote (int from_tty) |
c906108c SS |
1274 | { |
1275 | init_thread_list (); | |
1276 | init_wait_for_inferior (); | |
b0f4b84b | 1277 | stop_soon = STOP_QUIETLY_REMOTE; |
ca67fcb8 | 1278 | stepping_over_breakpoint = 0; |
43ff13b4 | 1279 | |
6426a772 JM |
1280 | /* Always go on waiting for the target, regardless of the mode. */ |
1281 | /* FIXME: cagney/1999-09-23: At present it isn't possible to | |
7e73cedf | 1282 | indicate to wait_for_inferior that a target should timeout if |
6426a772 JM |
1283 | nothing is returned (instead of just blocking). Because of this, |
1284 | targets expecting an immediate response need to, internally, set | |
1285 | things up so that the target_wait() is forced to eventually | |
1286 | timeout. */ | |
1287 | /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to | |
1288 | differentiate to its caller what the state of the target is after | |
1289 | the initial open has been performed. Here we're assuming that | |
1290 | the target has stopped. It should be possible to eventually have | |
1291 | target_open() return to the caller an indication that the target | |
1292 | is currently running and GDB state should be set to the same as | |
1293 | for an async run. */ | |
ae123ec6 | 1294 | wait_for_inferior (0); |
8621d6a9 DJ |
1295 | |
1296 | /* Now that the inferior has stopped, do any bookkeeping like | |
1297 | loading shared libraries. We want to do this before normal_stop, | |
1298 | so that the displayed frame is up to date. */ | |
1299 | post_create_inferior (¤t_target, from_tty); | |
1300 | ||
6426a772 | 1301 | normal_stop (); |
c906108c SS |
1302 | } |
1303 | ||
1304 | /* Initialize static vars when a new inferior begins. */ | |
1305 | ||
1306 | void | |
96baa820 | 1307 | init_wait_for_inferior (void) |
c906108c SS |
1308 | { |
1309 | /* These are meaningless until the first time through wait_for_inferior. */ | |
1310 | prev_pc = 0; | |
c906108c | 1311 | |
c906108c SS |
1312 | breakpoint_init_inferior (inf_starting); |
1313 | ||
1314 | /* Don't confuse first call to proceed(). */ | |
1315 | stop_signal = TARGET_SIGNAL_0; | |
1316 | ||
1317 | /* The first resume is not following a fork/vfork/exec. */ | |
1318 | pending_follow.kind = TARGET_WAITKIND_SPURIOUS; /* I.e., none. */ | |
c906108c | 1319 | |
c906108c | 1320 | clear_proceed_status (); |
9f976b41 DJ |
1321 | |
1322 | stepping_past_singlestep_breakpoint = 0; | |
ca67fcb8 | 1323 | deferred_step_ptid = null_ptid; |
ca005067 DJ |
1324 | |
1325 | target_last_wait_ptid = minus_one_ptid; | |
237fc4c9 PA |
1326 | |
1327 | displaced_step_clear (); | |
c906108c | 1328 | } |
237fc4c9 | 1329 | |
c906108c | 1330 | \f |
b83266a0 SS |
1331 | /* This enum encodes possible reasons for doing a target_wait, so that |
1332 | wfi can call target_wait in one place. (Ultimately the call will be | |
1333 | moved out of the infinite loop entirely.) */ | |
1334 | ||
c5aa993b JM |
1335 | enum infwait_states |
1336 | { | |
cd0fc7c3 SS |
1337 | infwait_normal_state, |
1338 | infwait_thread_hop_state, | |
d983da9c | 1339 | infwait_step_watch_state, |
cd0fc7c3 | 1340 | infwait_nonstep_watch_state |
b83266a0 SS |
1341 | }; |
1342 | ||
11cf8741 JM |
1343 | /* Why did the inferior stop? Used to print the appropriate messages |
1344 | to the interface from within handle_inferior_event(). */ | |
1345 | enum inferior_stop_reason | |
1346 | { | |
11cf8741 JM |
1347 | /* Step, next, nexti, stepi finished. */ |
1348 | END_STEPPING_RANGE, | |
11cf8741 JM |
1349 | /* Inferior terminated by signal. */ |
1350 | SIGNAL_EXITED, | |
1351 | /* Inferior exited. */ | |
1352 | EXITED, | |
1353 | /* Inferior received signal, and user asked to be notified. */ | |
1354 | SIGNAL_RECEIVED | |
1355 | }; | |
1356 | ||
cd0fc7c3 SS |
1357 | /* This structure contains what used to be local variables in |
1358 | wait_for_inferior. Probably many of them can return to being | |
1359 | locals in handle_inferior_event. */ | |
1360 | ||
c5aa993b | 1361 | struct execution_control_state |
488f131b JB |
1362 | { |
1363 | struct target_waitstatus ws; | |
1364 | struct target_waitstatus *wp; | |
ca67fcb8 VP |
1365 | /* Should we step over breakpoint next time keep_going |
1366 | is called? */ | |
1367 | int stepping_over_breakpoint; | |
488f131b JB |
1368 | int random_signal; |
1369 | CORE_ADDR stop_func_start; | |
1370 | CORE_ADDR stop_func_end; | |
1371 | char *stop_func_name; | |
1372 | struct symtab_and_line sal; | |
488f131b JB |
1373 | int current_line; |
1374 | struct symtab *current_symtab; | |
1375 | int handling_longjmp; /* FIXME */ | |
1376 | ptid_t ptid; | |
1377 | ptid_t saved_inferior_ptid; | |
68f53502 | 1378 | int step_after_step_resume_breakpoint; |
488f131b JB |
1379 | int stepping_through_solib_after_catch; |
1380 | bpstat stepping_through_solib_catchpoints; | |
488f131b JB |
1381 | int new_thread_event; |
1382 | struct target_waitstatus tmpstatus; | |
1383 | enum infwait_states infwait_state; | |
1384 | ptid_t waiton_ptid; | |
1385 | int wait_some_more; | |
1386 | }; | |
1387 | ||
1388 | void init_execution_control_state (struct execution_control_state *ecs); | |
1389 | ||
1390 | void handle_inferior_event (struct execution_control_state *ecs); | |
cd0fc7c3 | 1391 | |
c2c6d25f | 1392 | static void step_into_function (struct execution_control_state *ecs); |
44cbf7b5 | 1393 | static void insert_step_resume_breakpoint_at_frame (struct frame_info *step_frame); |
14e60db5 | 1394 | static void insert_step_resume_breakpoint_at_caller (struct frame_info *); |
44cbf7b5 AC |
1395 | static void insert_step_resume_breakpoint_at_sal (struct symtab_and_line sr_sal, |
1396 | struct frame_id sr_id); | |
104c1213 JM |
1397 | static void stop_stepping (struct execution_control_state *ecs); |
1398 | static void prepare_to_wait (struct execution_control_state *ecs); | |
d4f3574e | 1399 | static void keep_going (struct execution_control_state *ecs); |
488f131b JB |
1400 | static void print_stop_reason (enum inferior_stop_reason stop_reason, |
1401 | int stop_info); | |
104c1213 | 1402 | |
cd0fc7c3 | 1403 | /* Wait for control to return from inferior to debugger. |
ae123ec6 JB |
1404 | |
1405 | If TREAT_EXEC_AS_SIGTRAP is non-zero, then handle EXEC signals | |
1406 | as if they were SIGTRAP signals. This can be useful during | |
1407 | the startup sequence on some targets such as HP/UX, where | |
1408 | we receive an EXEC event instead of the expected SIGTRAP. | |
1409 | ||
cd0fc7c3 SS |
1410 | If inferior gets a signal, we may decide to start it up again |
1411 | instead of returning. That is why there is a loop in this function. | |
1412 | When this function actually returns it means the inferior | |
1413 | should be left stopped and GDB should read more commands. */ | |
1414 | ||
1415 | void | |
ae123ec6 | 1416 | wait_for_inferior (int treat_exec_as_sigtrap) |
cd0fc7c3 SS |
1417 | { |
1418 | struct cleanup *old_cleanups; | |
1419 | struct execution_control_state ecss; | |
1420 | struct execution_control_state *ecs; | |
c906108c | 1421 | |
527159b7 | 1422 | if (debug_infrun) |
ae123ec6 JB |
1423 | fprintf_unfiltered |
1424 | (gdb_stdlog, "infrun: wait_for_inferior (treat_exec_as_sigtrap=%d)\n", | |
1425 | treat_exec_as_sigtrap); | |
527159b7 | 1426 | |
8601f500 | 1427 | old_cleanups = make_cleanup (delete_step_resume_breakpoint, |
c906108c | 1428 | &step_resume_breakpoint); |
cd0fc7c3 SS |
1429 | |
1430 | /* wfi still stays in a loop, so it's OK just to take the address of | |
1431 | a local to get the ecs pointer. */ | |
1432 | ecs = &ecss; | |
1433 | ||
1434 | /* Fill in with reasonable starting values. */ | |
1435 | init_execution_control_state (ecs); | |
1436 | ||
c906108c | 1437 | /* We'll update this if & when we switch to a new thread. */ |
39f77062 | 1438 | previous_inferior_ptid = inferior_ptid; |
c906108c | 1439 | |
cd0fc7c3 SS |
1440 | overlay_cache_invalid = 1; |
1441 | ||
1442 | /* We have to invalidate the registers BEFORE calling target_wait | |
1443 | because they can be loaded from the target while in target_wait. | |
1444 | This makes remote debugging a bit more efficient for those | |
1445 | targets that provide critical registers as part of their normal | |
1446 | status mechanism. */ | |
1447 | ||
1448 | registers_changed (); | |
b83266a0 | 1449 | |
c906108c SS |
1450 | while (1) |
1451 | { | |
9a4105ab AC |
1452 | if (deprecated_target_wait_hook) |
1453 | ecs->ptid = deprecated_target_wait_hook (ecs->waiton_ptid, ecs->wp); | |
cd0fc7c3 | 1454 | else |
39f77062 | 1455 | ecs->ptid = target_wait (ecs->waiton_ptid, ecs->wp); |
c906108c | 1456 | |
ae123ec6 JB |
1457 | if (treat_exec_as_sigtrap && ecs->ws.kind == TARGET_WAITKIND_EXECD) |
1458 | { | |
1459 | xfree (ecs->ws.value.execd_pathname); | |
1460 | ecs->ws.kind = TARGET_WAITKIND_STOPPED; | |
1461 | ecs->ws.value.sig = TARGET_SIGNAL_TRAP; | |
1462 | } | |
1463 | ||
cd0fc7c3 SS |
1464 | /* Now figure out what to do with the result of the result. */ |
1465 | handle_inferior_event (ecs); | |
c906108c | 1466 | |
cd0fc7c3 SS |
1467 | if (!ecs->wait_some_more) |
1468 | break; | |
1469 | } | |
1470 | do_cleanups (old_cleanups); | |
1471 | } | |
c906108c | 1472 | |
43ff13b4 JM |
1473 | /* Asynchronous version of wait_for_inferior. It is called by the |
1474 | event loop whenever a change of state is detected on the file | |
1475 | descriptor corresponding to the target. It can be called more than | |
1476 | once to complete a single execution command. In such cases we need | |
1477 | to keep the state in a global variable ASYNC_ECSS. If it is the | |
1478 | last time that this function is called for a single execution | |
1479 | command, then report to the user that the inferior has stopped, and | |
1480 | do the necessary cleanups. */ | |
1481 | ||
1482 | struct execution_control_state async_ecss; | |
1483 | struct execution_control_state *async_ecs; | |
1484 | ||
1485 | void | |
fba45db2 | 1486 | fetch_inferior_event (void *client_data) |
43ff13b4 JM |
1487 | { |
1488 | static struct cleanup *old_cleanups; | |
1489 | ||
c5aa993b | 1490 | async_ecs = &async_ecss; |
43ff13b4 JM |
1491 | |
1492 | if (!async_ecs->wait_some_more) | |
1493 | { | |
43ff13b4 JM |
1494 | /* Fill in with reasonable starting values. */ |
1495 | init_execution_control_state (async_ecs); | |
1496 | ||
43ff13b4 | 1497 | /* We'll update this if & when we switch to a new thread. */ |
39f77062 | 1498 | previous_inferior_ptid = inferior_ptid; |
43ff13b4 JM |
1499 | |
1500 | overlay_cache_invalid = 1; | |
1501 | ||
1502 | /* We have to invalidate the registers BEFORE calling target_wait | |
c5aa993b JM |
1503 | because they can be loaded from the target while in target_wait. |
1504 | This makes remote debugging a bit more efficient for those | |
1505 | targets that provide critical registers as part of their normal | |
1506 | status mechanism. */ | |
43ff13b4 JM |
1507 | |
1508 | registers_changed (); | |
1509 | } | |
1510 | ||
9a4105ab | 1511 | if (deprecated_target_wait_hook) |
488f131b | 1512 | async_ecs->ptid = |
9a4105ab | 1513 | deprecated_target_wait_hook (async_ecs->waiton_ptid, async_ecs->wp); |
43ff13b4 | 1514 | else |
39f77062 | 1515 | async_ecs->ptid = target_wait (async_ecs->waiton_ptid, async_ecs->wp); |
43ff13b4 JM |
1516 | |
1517 | /* Now figure out what to do with the result of the result. */ | |
1518 | handle_inferior_event (async_ecs); | |
1519 | ||
1520 | if (!async_ecs->wait_some_more) | |
1521 | { | |
f107f563 VP |
1522 | delete_step_resume_breakpoint (&step_resume_breakpoint); |
1523 | ||
43ff13b4 | 1524 | normal_stop (); |
c2d11a7d JM |
1525 | if (step_multi && stop_step) |
1526 | inferior_event_handler (INF_EXEC_CONTINUE, NULL); | |
1527 | else | |
1528 | inferior_event_handler (INF_EXEC_COMPLETE, NULL); | |
43ff13b4 JM |
1529 | } |
1530 | } | |
1531 | ||
cd0fc7c3 SS |
1532 | /* Prepare an execution control state for looping through a |
1533 | wait_for_inferior-type loop. */ | |
1534 | ||
1535 | void | |
96baa820 | 1536 | init_execution_control_state (struct execution_control_state *ecs) |
cd0fc7c3 | 1537 | { |
ca67fcb8 | 1538 | ecs->stepping_over_breakpoint = 0; |
cd0fc7c3 | 1539 | ecs->random_signal = 0; |
68f53502 | 1540 | ecs->step_after_step_resume_breakpoint = 0; |
cd0fc7c3 | 1541 | ecs->handling_longjmp = 0; /* FIXME */ |
cd0fc7c3 SS |
1542 | ecs->stepping_through_solib_after_catch = 0; |
1543 | ecs->stepping_through_solib_catchpoints = NULL; | |
cd0fc7c3 SS |
1544 | ecs->sal = find_pc_line (prev_pc, 0); |
1545 | ecs->current_line = ecs->sal.line; | |
1546 | ecs->current_symtab = ecs->sal.symtab; | |
1547 | ecs->infwait_state = infwait_normal_state; | |
39f77062 | 1548 | ecs->waiton_ptid = pid_to_ptid (-1); |
cd0fc7c3 SS |
1549 | ecs->wp = &(ecs->ws); |
1550 | } | |
1551 | ||
e02bc4cc | 1552 | /* Return the cached copy of the last pid/waitstatus returned by |
9a4105ab AC |
1553 | target_wait()/deprecated_target_wait_hook(). The data is actually |
1554 | cached by handle_inferior_event(), which gets called immediately | |
1555 | after target_wait()/deprecated_target_wait_hook(). */ | |
e02bc4cc DS |
1556 | |
1557 | void | |
488f131b | 1558 | get_last_target_status (ptid_t *ptidp, struct target_waitstatus *status) |
e02bc4cc | 1559 | { |
39f77062 | 1560 | *ptidp = target_last_wait_ptid; |
e02bc4cc DS |
1561 | *status = target_last_waitstatus; |
1562 | } | |
1563 | ||
ac264b3b MS |
1564 | void |
1565 | nullify_last_target_wait_ptid (void) | |
1566 | { | |
1567 | target_last_wait_ptid = minus_one_ptid; | |
1568 | } | |
1569 | ||
dd80620e MS |
1570 | /* Switch thread contexts, maintaining "infrun state". */ |
1571 | ||
1572 | static void | |
1573 | context_switch (struct execution_control_state *ecs) | |
1574 | { | |
1575 | /* Caution: it may happen that the new thread (or the old one!) | |
1576 | is not in the thread list. In this case we must not attempt | |
1577 | to "switch context", or we run the risk that our context may | |
1578 | be lost. This may happen as a result of the target module | |
1579 | mishandling thread creation. */ | |
1580 | ||
fd48f117 DJ |
1581 | if (debug_infrun) |
1582 | { | |
1583 | fprintf_unfiltered (gdb_stdlog, "infrun: Switching context from %s ", | |
1584 | target_pid_to_str (inferior_ptid)); | |
1585 | fprintf_unfiltered (gdb_stdlog, "to %s\n", | |
1586 | target_pid_to_str (ecs->ptid)); | |
1587 | } | |
1588 | ||
dd80620e | 1589 | if (in_thread_list (inferior_ptid) && in_thread_list (ecs->ptid)) |
488f131b | 1590 | { /* Perform infrun state context switch: */ |
dd80620e | 1591 | /* Save infrun state for the old thread. */ |
0ce3d317 | 1592 | save_infrun_state (inferior_ptid, prev_pc, |
ca67fcb8 | 1593 | stepping_over_breakpoint, step_resume_breakpoint, |
15960608 | 1594 | step_range_start, |
aa0cd9c1 | 1595 | step_range_end, &step_frame_id, |
ca67fcb8 | 1596 | ecs->handling_longjmp, ecs->stepping_over_breakpoint, |
dd80620e MS |
1597 | ecs->stepping_through_solib_after_catch, |
1598 | ecs->stepping_through_solib_catchpoints, | |
f2c9ca08 | 1599 | ecs->current_line, ecs->current_symtab); |
dd80620e MS |
1600 | |
1601 | /* Load infrun state for the new thread. */ | |
0ce3d317 | 1602 | load_infrun_state (ecs->ptid, &prev_pc, |
ca67fcb8 | 1603 | &stepping_over_breakpoint, &step_resume_breakpoint, |
15960608 | 1604 | &step_range_start, |
aa0cd9c1 | 1605 | &step_range_end, &step_frame_id, |
ca67fcb8 | 1606 | &ecs->handling_longjmp, &ecs->stepping_over_breakpoint, |
dd80620e MS |
1607 | &ecs->stepping_through_solib_after_catch, |
1608 | &ecs->stepping_through_solib_catchpoints, | |
f2c9ca08 | 1609 | &ecs->current_line, &ecs->current_symtab); |
dd80620e | 1610 | } |
6a6b96b9 UW |
1611 | |
1612 | switch_to_thread (ecs->ptid); | |
dd80620e MS |
1613 | } |
1614 | ||
4fa8626c DJ |
1615 | static void |
1616 | adjust_pc_after_break (struct execution_control_state *ecs) | |
1617 | { | |
8aad930b | 1618 | CORE_ADDR breakpoint_pc; |
4fa8626c DJ |
1619 | |
1620 | /* If this target does not decrement the PC after breakpoints, then | |
1621 | we have nothing to do. */ | |
b798847d | 1622 | if (gdbarch_decr_pc_after_break (current_gdbarch) == 0) |
4fa8626c DJ |
1623 | return; |
1624 | ||
1625 | /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If | |
1626 | we aren't, just return. | |
9709f61c DJ |
1627 | |
1628 | We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not | |
b798847d UW |
1629 | affected by gdbarch_decr_pc_after_break. Other waitkinds which are |
1630 | implemented by software breakpoints should be handled through the normal | |
1631 | breakpoint layer. | |
8fb3e588 | 1632 | |
4fa8626c DJ |
1633 | NOTE drow/2004-01-31: On some targets, breakpoints may generate |
1634 | different signals (SIGILL or SIGEMT for instance), but it is less | |
1635 | clear where the PC is pointing afterwards. It may not match | |
b798847d UW |
1636 | gdbarch_decr_pc_after_break. I don't know any specific target that |
1637 | generates these signals at breakpoints (the code has been in GDB since at | |
1638 | least 1992) so I can not guess how to handle them here. | |
8fb3e588 | 1639 | |
e6cf7916 UW |
1640 | In earlier versions of GDB, a target with |
1641 | gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a | |
b798847d UW |
1642 | watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any |
1643 | target with both of these set in GDB history, and it seems unlikely to be | |
1644 | correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */ | |
4fa8626c DJ |
1645 | |
1646 | if (ecs->ws.kind != TARGET_WAITKIND_STOPPED) | |
1647 | return; | |
1648 | ||
1649 | if (ecs->ws.value.sig != TARGET_SIGNAL_TRAP) | |
1650 | return; | |
1651 | ||
8aad930b AC |
1652 | /* Find the location where (if we've hit a breakpoint) the |
1653 | breakpoint would be. */ | |
b798847d UW |
1654 | breakpoint_pc = read_pc_pid (ecs->ptid) - gdbarch_decr_pc_after_break |
1655 | (current_gdbarch); | |
8aad930b | 1656 | |
1c0fdd0e UW |
1657 | /* Check whether there actually is a software breakpoint inserted |
1658 | at that location. */ | |
1659 | if (software_breakpoint_inserted_here_p (breakpoint_pc)) | |
8aad930b | 1660 | { |
1c0fdd0e UW |
1661 | /* When using hardware single-step, a SIGTRAP is reported for both |
1662 | a completed single-step and a software breakpoint. Need to | |
1663 | differentiate between the two, as the latter needs adjusting | |
1664 | but the former does not. | |
1665 | ||
1666 | The SIGTRAP can be due to a completed hardware single-step only if | |
1667 | - we didn't insert software single-step breakpoints | |
1668 | - the thread to be examined is still the current thread | |
1669 | - this thread is currently being stepped | |
1670 | ||
1671 | If any of these events did not occur, we must have stopped due | |
1672 | to hitting a software breakpoint, and have to back up to the | |
1673 | breakpoint address. | |
1674 | ||
1675 | As a special case, we could have hardware single-stepped a | |
1676 | software breakpoint. In this case (prev_pc == breakpoint_pc), | |
1677 | we also need to back up to the breakpoint address. */ | |
1678 | ||
1679 | if (singlestep_breakpoints_inserted_p | |
1680 | || !ptid_equal (ecs->ptid, inferior_ptid) | |
1681 | || !currently_stepping (ecs) | |
1682 | || prev_pc == breakpoint_pc) | |
8aad930b AC |
1683 | write_pc_pid (breakpoint_pc, ecs->ptid); |
1684 | } | |
4fa8626c DJ |
1685 | } |
1686 | ||
cd0fc7c3 SS |
1687 | /* Given an execution control state that has been freshly filled in |
1688 | by an event from the inferior, figure out what it means and take | |
1689 | appropriate action. */ | |
c906108c | 1690 | |
cd0fc7c3 | 1691 | void |
96baa820 | 1692 | handle_inferior_event (struct execution_control_state *ecs) |
cd0fc7c3 | 1693 | { |
c8edd8b4 | 1694 | int sw_single_step_trap_p = 0; |
d983da9c DJ |
1695 | int stopped_by_watchpoint; |
1696 | int stepped_after_stopped_by_watchpoint = 0; | |
cd0fc7c3 | 1697 | |
e02bc4cc | 1698 | /* Cache the last pid/waitstatus. */ |
39f77062 | 1699 | target_last_wait_ptid = ecs->ptid; |
e02bc4cc DS |
1700 | target_last_waitstatus = *ecs->wp; |
1701 | ||
ca005067 DJ |
1702 | /* Always clear state belonging to the previous time we stopped. */ |
1703 | stop_stack_dummy = 0; | |
1704 | ||
4fa8626c DJ |
1705 | adjust_pc_after_break (ecs); |
1706 | ||
488f131b JB |
1707 | switch (ecs->infwait_state) |
1708 | { | |
1709 | case infwait_thread_hop_state: | |
527159b7 | 1710 | if (debug_infrun) |
8a9de0e4 | 1711 | fprintf_unfiltered (gdb_stdlog, "infrun: infwait_thread_hop_state\n"); |
488f131b JB |
1712 | /* Cancel the waiton_ptid. */ |
1713 | ecs->waiton_ptid = pid_to_ptid (-1); | |
65e82032 | 1714 | break; |
b83266a0 | 1715 | |
488f131b | 1716 | case infwait_normal_state: |
527159b7 | 1717 | if (debug_infrun) |
8a9de0e4 | 1718 | fprintf_unfiltered (gdb_stdlog, "infrun: infwait_normal_state\n"); |
d983da9c DJ |
1719 | break; |
1720 | ||
1721 | case infwait_step_watch_state: | |
1722 | if (debug_infrun) | |
1723 | fprintf_unfiltered (gdb_stdlog, | |
1724 | "infrun: infwait_step_watch_state\n"); | |
1725 | ||
1726 | stepped_after_stopped_by_watchpoint = 1; | |
488f131b | 1727 | break; |
b83266a0 | 1728 | |
488f131b | 1729 | case infwait_nonstep_watch_state: |
527159b7 | 1730 | if (debug_infrun) |
8a9de0e4 AC |
1731 | fprintf_unfiltered (gdb_stdlog, |
1732 | "infrun: infwait_nonstep_watch_state\n"); | |
488f131b | 1733 | insert_breakpoints (); |
c906108c | 1734 | |
488f131b JB |
1735 | /* FIXME-maybe: is this cleaner than setting a flag? Does it |
1736 | handle things like signals arriving and other things happening | |
1737 | in combination correctly? */ | |
1738 | stepped_after_stopped_by_watchpoint = 1; | |
1739 | break; | |
65e82032 AC |
1740 | |
1741 | default: | |
e2e0b3e5 | 1742 | internal_error (__FILE__, __LINE__, _("bad switch")); |
488f131b JB |
1743 | } |
1744 | ecs->infwait_state = infwait_normal_state; | |
c906108c | 1745 | |
35f196d9 | 1746 | reinit_frame_cache (); |
c906108c | 1747 | |
488f131b | 1748 | /* If it's a new process, add it to the thread database */ |
c906108c | 1749 | |
488f131b | 1750 | ecs->new_thread_event = (!ptid_equal (ecs->ptid, inferior_ptid) |
b9b5d7ea | 1751 | && !ptid_equal (ecs->ptid, minus_one_ptid) |
488f131b JB |
1752 | && !in_thread_list (ecs->ptid)); |
1753 | ||
1754 | if (ecs->ws.kind != TARGET_WAITKIND_EXITED | |
1755 | && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED && ecs->new_thread_event) | |
93815fbf | 1756 | add_thread (ecs->ptid); |
c906108c | 1757 | |
488f131b JB |
1758 | switch (ecs->ws.kind) |
1759 | { | |
1760 | case TARGET_WAITKIND_LOADED: | |
527159b7 | 1761 | if (debug_infrun) |
8a9de0e4 | 1762 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_LOADED\n"); |
b0f4b84b DJ |
1763 | /* Ignore gracefully during startup of the inferior, as it might |
1764 | be the shell which has just loaded some objects, otherwise | |
1765 | add the symbols for the newly loaded objects. Also ignore at | |
1766 | the beginning of an attach or remote session; we will query | |
1767 | the full list of libraries once the connection is | |
1768 | established. */ | |
c0236d92 | 1769 | if (stop_soon == NO_STOP_QUIETLY) |
488f131b | 1770 | { |
488f131b JB |
1771 | /* Check for any newly added shared libraries if we're |
1772 | supposed to be adding them automatically. Switch | |
1773 | terminal for any messages produced by | |
1774 | breakpoint_re_set. */ | |
1775 | target_terminal_ours_for_output (); | |
aff6338a | 1776 | /* NOTE: cagney/2003-11-25: Make certain that the target |
8fb3e588 AC |
1777 | stack's section table is kept up-to-date. Architectures, |
1778 | (e.g., PPC64), use the section table to perform | |
1779 | operations such as address => section name and hence | |
1780 | require the table to contain all sections (including | |
1781 | those found in shared libraries). */ | |
aff6338a | 1782 | /* NOTE: cagney/2003-11-25: Pass current_target and not |
8fb3e588 AC |
1783 | exec_ops to SOLIB_ADD. This is because current GDB is |
1784 | only tooled to propagate section_table changes out from | |
1785 | the "current_target" (see target_resize_to_sections), and | |
1786 | not up from the exec stratum. This, of course, isn't | |
1787 | right. "infrun.c" should only interact with the | |
1788 | exec/process stratum, instead relying on the target stack | |
1789 | to propagate relevant changes (stop, section table | |
1790 | changed, ...) up to other layers. */ | |
b0f4b84b | 1791 | #ifdef SOLIB_ADD |
aff6338a | 1792 | SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add); |
b0f4b84b DJ |
1793 | #else |
1794 | solib_add (NULL, 0, ¤t_target, auto_solib_add); | |
1795 | #endif | |
488f131b JB |
1796 | target_terminal_inferior (); |
1797 | ||
b0f4b84b DJ |
1798 | /* If requested, stop when the dynamic linker notifies |
1799 | gdb of events. This allows the user to get control | |
1800 | and place breakpoints in initializer routines for | |
1801 | dynamically loaded objects (among other things). */ | |
1802 | if (stop_on_solib_events) | |
1803 | { | |
1804 | stop_stepping (ecs); | |
1805 | return; | |
1806 | } | |
1807 | ||
1808 | /* NOTE drow/2007-05-11: This might be a good place to check | |
1809 | for "catch load". */ | |
488f131b | 1810 | } |
b0f4b84b DJ |
1811 | |
1812 | /* If we are skipping through a shell, or through shared library | |
1813 | loading that we aren't interested in, resume the program. If | |
1814 | we're running the program normally, also resume. But stop if | |
1815 | we're attaching or setting up a remote connection. */ | |
1816 | if (stop_soon == STOP_QUIETLY || stop_soon == NO_STOP_QUIETLY) | |
1817 | { | |
74960c60 VP |
1818 | /* Loading of shared libraries might have changed breakpoint |
1819 | addresses. Make sure new breakpoints are inserted. */ | |
0b02b92d UW |
1820 | if (stop_soon == NO_STOP_QUIETLY |
1821 | && !breakpoints_always_inserted_mode ()) | |
74960c60 | 1822 | insert_breakpoints (); |
b0f4b84b DJ |
1823 | resume (0, TARGET_SIGNAL_0); |
1824 | prepare_to_wait (ecs); | |
1825 | return; | |
1826 | } | |
1827 | ||
1828 | break; | |
c5aa993b | 1829 | |
488f131b | 1830 | case TARGET_WAITKIND_SPURIOUS: |
527159b7 | 1831 | if (debug_infrun) |
8a9de0e4 | 1832 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SPURIOUS\n"); |
488f131b JB |
1833 | resume (0, TARGET_SIGNAL_0); |
1834 | prepare_to_wait (ecs); | |
1835 | return; | |
c5aa993b | 1836 | |
488f131b | 1837 | case TARGET_WAITKIND_EXITED: |
527159b7 | 1838 | if (debug_infrun) |
8a9de0e4 | 1839 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_EXITED\n"); |
488f131b JB |
1840 | target_terminal_ours (); /* Must do this before mourn anyway */ |
1841 | print_stop_reason (EXITED, ecs->ws.value.integer); | |
1842 | ||
1843 | /* Record the exit code in the convenience variable $_exitcode, so | |
1844 | that the user can inspect this again later. */ | |
1845 | set_internalvar (lookup_internalvar ("_exitcode"), | |
1846 | value_from_longest (builtin_type_int, | |
1847 | (LONGEST) ecs->ws.value.integer)); | |
1848 | gdb_flush (gdb_stdout); | |
1849 | target_mourn_inferior (); | |
1c0fdd0e | 1850 | singlestep_breakpoints_inserted_p = 0; |
488f131b JB |
1851 | stop_print_frame = 0; |
1852 | stop_stepping (ecs); | |
1853 | return; | |
c5aa993b | 1854 | |
488f131b | 1855 | case TARGET_WAITKIND_SIGNALLED: |
527159b7 | 1856 | if (debug_infrun) |
8a9de0e4 | 1857 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SIGNALLED\n"); |
488f131b JB |
1858 | stop_print_frame = 0; |
1859 | stop_signal = ecs->ws.value.sig; | |
1860 | target_terminal_ours (); /* Must do this before mourn anyway */ | |
c5aa993b | 1861 | |
488f131b JB |
1862 | /* Note: By definition of TARGET_WAITKIND_SIGNALLED, we shouldn't |
1863 | reach here unless the inferior is dead. However, for years | |
1864 | target_kill() was called here, which hints that fatal signals aren't | |
1865 | really fatal on some systems. If that's true, then some changes | |
1866 | may be needed. */ | |
1867 | target_mourn_inferior (); | |
c906108c | 1868 | |
488f131b | 1869 | print_stop_reason (SIGNAL_EXITED, stop_signal); |
1c0fdd0e | 1870 | singlestep_breakpoints_inserted_p = 0; |
488f131b JB |
1871 | stop_stepping (ecs); |
1872 | return; | |
c906108c | 1873 | |
488f131b JB |
1874 | /* The following are the only cases in which we keep going; |
1875 | the above cases end in a continue or goto. */ | |
1876 | case TARGET_WAITKIND_FORKED: | |
deb3b17b | 1877 | case TARGET_WAITKIND_VFORKED: |
527159b7 | 1878 | if (debug_infrun) |
8a9de0e4 | 1879 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_FORKED\n"); |
488f131b JB |
1880 | stop_signal = TARGET_SIGNAL_TRAP; |
1881 | pending_follow.kind = ecs->ws.kind; | |
1882 | ||
8e7d2c16 DJ |
1883 | pending_follow.fork_event.parent_pid = PIDGET (ecs->ptid); |
1884 | pending_follow.fork_event.child_pid = ecs->ws.value.related_pid; | |
c906108c | 1885 | |
5a2901d9 DJ |
1886 | if (!ptid_equal (ecs->ptid, inferior_ptid)) |
1887 | { | |
1888 | context_switch (ecs); | |
35f196d9 | 1889 | reinit_frame_cache (); |
5a2901d9 DJ |
1890 | } |
1891 | ||
488f131b | 1892 | stop_pc = read_pc (); |
675bf4cb | 1893 | |
d983da9c | 1894 | stop_bpstat = bpstat_stop_status (stop_pc, ecs->ptid); |
675bf4cb | 1895 | |
488f131b | 1896 | ecs->random_signal = !bpstat_explains_signal (stop_bpstat); |
04e68871 DJ |
1897 | |
1898 | /* If no catchpoint triggered for this, then keep going. */ | |
1899 | if (ecs->random_signal) | |
1900 | { | |
1901 | stop_signal = TARGET_SIGNAL_0; | |
1902 | keep_going (ecs); | |
1903 | return; | |
1904 | } | |
488f131b JB |
1905 | goto process_event_stop_test; |
1906 | ||
1907 | case TARGET_WAITKIND_EXECD: | |
527159b7 | 1908 | if (debug_infrun) |
fc5261f2 | 1909 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_EXECD\n"); |
488f131b JB |
1910 | stop_signal = TARGET_SIGNAL_TRAP; |
1911 | ||
488f131b JB |
1912 | pending_follow.execd_pathname = |
1913 | savestring (ecs->ws.value.execd_pathname, | |
1914 | strlen (ecs->ws.value.execd_pathname)); | |
1915 | ||
488f131b JB |
1916 | /* This causes the eventpoints and symbol table to be reset. Must |
1917 | do this now, before trying to determine whether to stop. */ | |
1918 | follow_exec (PIDGET (inferior_ptid), pending_follow.execd_pathname); | |
1919 | xfree (pending_follow.execd_pathname); | |
c906108c | 1920 | |
488f131b JB |
1921 | stop_pc = read_pc_pid (ecs->ptid); |
1922 | ecs->saved_inferior_ptid = inferior_ptid; | |
1923 | inferior_ptid = ecs->ptid; | |
675bf4cb | 1924 | |
d983da9c | 1925 | stop_bpstat = bpstat_stop_status (stop_pc, ecs->ptid); |
675bf4cb | 1926 | |
488f131b JB |
1927 | ecs->random_signal = !bpstat_explains_signal (stop_bpstat); |
1928 | inferior_ptid = ecs->saved_inferior_ptid; | |
04e68871 | 1929 | |
5a2901d9 DJ |
1930 | if (!ptid_equal (ecs->ptid, inferior_ptid)) |
1931 | { | |
1932 | context_switch (ecs); | |
35f196d9 | 1933 | reinit_frame_cache (); |
5a2901d9 DJ |
1934 | } |
1935 | ||
04e68871 DJ |
1936 | /* If no catchpoint triggered for this, then keep going. */ |
1937 | if (ecs->random_signal) | |
1938 | { | |
1939 | stop_signal = TARGET_SIGNAL_0; | |
1940 | keep_going (ecs); | |
1941 | return; | |
1942 | } | |
488f131b JB |
1943 | goto process_event_stop_test; |
1944 | ||
b4dc5ffa MK |
1945 | /* Be careful not to try to gather much state about a thread |
1946 | that's in a syscall. It's frequently a losing proposition. */ | |
488f131b | 1947 | case TARGET_WAITKIND_SYSCALL_ENTRY: |
527159b7 | 1948 | if (debug_infrun) |
8a9de0e4 | 1949 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SYSCALL_ENTRY\n"); |
488f131b JB |
1950 | resume (0, TARGET_SIGNAL_0); |
1951 | prepare_to_wait (ecs); | |
1952 | return; | |
c906108c | 1953 | |
488f131b JB |
1954 | /* Before examining the threads further, step this thread to |
1955 | get it entirely out of the syscall. (We get notice of the | |
1956 | event when the thread is just on the verge of exiting a | |
1957 | syscall. Stepping one instruction seems to get it back | |
b4dc5ffa | 1958 | into user code.) */ |
488f131b | 1959 | case TARGET_WAITKIND_SYSCALL_RETURN: |
527159b7 | 1960 | if (debug_infrun) |
8a9de0e4 | 1961 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SYSCALL_RETURN\n"); |
488f131b | 1962 | target_resume (ecs->ptid, 1, TARGET_SIGNAL_0); |
488f131b JB |
1963 | prepare_to_wait (ecs); |
1964 | return; | |
c906108c | 1965 | |
488f131b | 1966 | case TARGET_WAITKIND_STOPPED: |
527159b7 | 1967 | if (debug_infrun) |
8a9de0e4 | 1968 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_STOPPED\n"); |
488f131b JB |
1969 | stop_signal = ecs->ws.value.sig; |
1970 | break; | |
c906108c | 1971 | |
488f131b JB |
1972 | /* We had an event in the inferior, but we are not interested |
1973 | in handling it at this level. The lower layers have already | |
8e7d2c16 | 1974 | done what needs to be done, if anything. |
8fb3e588 AC |
1975 | |
1976 | One of the possible circumstances for this is when the | |
1977 | inferior produces output for the console. The inferior has | |
1978 | not stopped, and we are ignoring the event. Another possible | |
1979 | circumstance is any event which the lower level knows will be | |
1980 | reported multiple times without an intervening resume. */ | |
488f131b | 1981 | case TARGET_WAITKIND_IGNORE: |
527159b7 | 1982 | if (debug_infrun) |
8a9de0e4 | 1983 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_IGNORE\n"); |
8e7d2c16 | 1984 | prepare_to_wait (ecs); |
488f131b JB |
1985 | return; |
1986 | } | |
c906108c | 1987 | |
488f131b JB |
1988 | /* We may want to consider not doing a resume here in order to give |
1989 | the user a chance to play with the new thread. It might be good | |
1990 | to make that a user-settable option. */ | |
c906108c | 1991 | |
488f131b JB |
1992 | /* At this point, all threads are stopped (happens automatically in |
1993 | either the OS or the native code). Therefore we need to continue | |
1994 | all threads in order to make progress. */ | |
1995 | if (ecs->new_thread_event) | |
1996 | { | |
1997 | target_resume (RESUME_ALL, 0, TARGET_SIGNAL_0); | |
1998 | prepare_to_wait (ecs); | |
1999 | return; | |
2000 | } | |
c906108c | 2001 | |
237fc4c9 PA |
2002 | /* Do we need to clean up the state of a thread that has completed a |
2003 | displaced single-step? (Doing so usually affects the PC, so do | |
2004 | it here, before we set stop_pc.) */ | |
2005 | displaced_step_fixup (ecs->ptid, stop_signal); | |
2006 | ||
488f131b JB |
2007 | stop_pc = read_pc_pid (ecs->ptid); |
2008 | ||
527159b7 | 2009 | if (debug_infrun) |
237fc4c9 PA |
2010 | { |
2011 | fprintf_unfiltered (gdb_stdlog, "infrun: stop_pc = 0x%s\n", | |
2012 | paddr_nz (stop_pc)); | |
2013 | if (STOPPED_BY_WATCHPOINT (&ecs->ws)) | |
2014 | { | |
2015 | CORE_ADDR addr; | |
2016 | fprintf_unfiltered (gdb_stdlog, "infrun: stopped by watchpoint\n"); | |
2017 | ||
2018 | if (target_stopped_data_address (¤t_target, &addr)) | |
2019 | fprintf_unfiltered (gdb_stdlog, | |
2020 | "infrun: stopped data address = 0x%s\n", | |
2021 | paddr_nz (addr)); | |
2022 | else | |
2023 | fprintf_unfiltered (gdb_stdlog, | |
2024 | "infrun: (no data address available)\n"); | |
2025 | } | |
2026 | } | |
527159b7 | 2027 | |
9f976b41 DJ |
2028 | if (stepping_past_singlestep_breakpoint) |
2029 | { | |
1c0fdd0e | 2030 | gdb_assert (singlestep_breakpoints_inserted_p); |
9f976b41 DJ |
2031 | gdb_assert (ptid_equal (singlestep_ptid, ecs->ptid)); |
2032 | gdb_assert (!ptid_equal (singlestep_ptid, saved_singlestep_ptid)); | |
2033 | ||
2034 | stepping_past_singlestep_breakpoint = 0; | |
2035 | ||
2036 | /* We've either finished single-stepping past the single-step | |
8fb3e588 AC |
2037 | breakpoint, or stopped for some other reason. It would be nice if |
2038 | we could tell, but we can't reliably. */ | |
9f976b41 | 2039 | if (stop_signal == TARGET_SIGNAL_TRAP) |
8fb3e588 | 2040 | { |
527159b7 | 2041 | if (debug_infrun) |
8a9de0e4 | 2042 | fprintf_unfiltered (gdb_stdlog, "infrun: stepping_past_singlestep_breakpoint\n"); |
9f976b41 | 2043 | /* Pull the single step breakpoints out of the target. */ |
e0cd558a | 2044 | remove_single_step_breakpoints (); |
9f976b41 DJ |
2045 | singlestep_breakpoints_inserted_p = 0; |
2046 | ||
2047 | ecs->random_signal = 0; | |
2048 | ||
2049 | ecs->ptid = saved_singlestep_ptid; | |
2050 | context_switch (ecs); | |
9a4105ab AC |
2051 | if (deprecated_context_hook) |
2052 | deprecated_context_hook (pid_to_thread_id (ecs->ptid)); | |
9f976b41 DJ |
2053 | |
2054 | resume (1, TARGET_SIGNAL_0); | |
2055 | prepare_to_wait (ecs); | |
2056 | return; | |
2057 | } | |
2058 | } | |
2059 | ||
2060 | stepping_past_singlestep_breakpoint = 0; | |
2061 | ||
ca67fcb8 | 2062 | if (!ptid_equal (deferred_step_ptid, null_ptid)) |
6a6b96b9 | 2063 | { |
6a6b96b9 UW |
2064 | /* If we stopped for some other reason than single-stepping, ignore |
2065 | the fact that we were supposed to switch back. */ | |
2066 | if (stop_signal == TARGET_SIGNAL_TRAP) | |
2067 | { | |
2068 | if (debug_infrun) | |
2069 | fprintf_unfiltered (gdb_stdlog, | |
ca67fcb8 | 2070 | "infrun: handling deferred step\n"); |
6a6b96b9 UW |
2071 | |
2072 | /* Pull the single step breakpoints out of the target. */ | |
2073 | if (singlestep_breakpoints_inserted_p) | |
2074 | { | |
2075 | remove_single_step_breakpoints (); | |
2076 | singlestep_breakpoints_inserted_p = 0; | |
2077 | } | |
2078 | ||
2079 | /* Note: We do not call context_switch at this point, as the | |
2080 | context is already set up for stepping the original thread. */ | |
ca67fcb8 VP |
2081 | switch_to_thread (deferred_step_ptid); |
2082 | deferred_step_ptid = null_ptid; | |
6a6b96b9 UW |
2083 | /* Suppress spurious "Switching to ..." message. */ |
2084 | previous_inferior_ptid = inferior_ptid; | |
2085 | ||
2086 | resume (1, TARGET_SIGNAL_0); | |
2087 | prepare_to_wait (ecs); | |
2088 | return; | |
2089 | } | |
ca67fcb8 VP |
2090 | |
2091 | deferred_step_ptid = null_ptid; | |
6a6b96b9 UW |
2092 | } |
2093 | ||
488f131b JB |
2094 | /* See if a thread hit a thread-specific breakpoint that was meant for |
2095 | another thread. If so, then step that thread past the breakpoint, | |
2096 | and continue it. */ | |
2097 | ||
2098 | if (stop_signal == TARGET_SIGNAL_TRAP) | |
2099 | { | |
9f976b41 DJ |
2100 | int thread_hop_needed = 0; |
2101 | ||
f8d40ec8 JB |
2102 | /* Check if a regular breakpoint has been hit before checking |
2103 | for a potential single step breakpoint. Otherwise, GDB will | |
2104 | not see this breakpoint hit when stepping onto breakpoints. */ | |
c36b740a | 2105 | if (regular_breakpoint_inserted_here_p (stop_pc)) |
488f131b | 2106 | { |
c5aa993b | 2107 | ecs->random_signal = 0; |
4fa8626c | 2108 | if (!breakpoint_thread_match (stop_pc, ecs->ptid)) |
9f976b41 DJ |
2109 | thread_hop_needed = 1; |
2110 | } | |
1c0fdd0e | 2111 | else if (singlestep_breakpoints_inserted_p) |
9f976b41 | 2112 | { |
fd48f117 DJ |
2113 | /* We have not context switched yet, so this should be true |
2114 | no matter which thread hit the singlestep breakpoint. */ | |
2115 | gdb_assert (ptid_equal (inferior_ptid, singlestep_ptid)); | |
2116 | if (debug_infrun) | |
2117 | fprintf_unfiltered (gdb_stdlog, "infrun: software single step " | |
2118 | "trap for %s\n", | |
2119 | target_pid_to_str (ecs->ptid)); | |
2120 | ||
9f976b41 DJ |
2121 | ecs->random_signal = 0; |
2122 | /* The call to in_thread_list is necessary because PTIDs sometimes | |
2123 | change when we go from single-threaded to multi-threaded. If | |
2124 | the singlestep_ptid is still in the list, assume that it is | |
2125 | really different from ecs->ptid. */ | |
2126 | if (!ptid_equal (singlestep_ptid, ecs->ptid) | |
2127 | && in_thread_list (singlestep_ptid)) | |
2128 | { | |
fd48f117 DJ |
2129 | /* If the PC of the thread we were trying to single-step |
2130 | has changed, discard this event (which we were going | |
2131 | to ignore anyway), and pretend we saw that thread | |
2132 | trap. This prevents us continuously moving the | |
2133 | single-step breakpoint forward, one instruction at a | |
2134 | time. If the PC has changed, then the thread we were | |
2135 | trying to single-step has trapped or been signalled, | |
2136 | but the event has not been reported to GDB yet. | |
2137 | ||
2138 | There might be some cases where this loses signal | |
2139 | information, if a signal has arrived at exactly the | |
2140 | same time that the PC changed, but this is the best | |
2141 | we can do with the information available. Perhaps we | |
2142 | should arrange to report all events for all threads | |
2143 | when they stop, or to re-poll the remote looking for | |
2144 | this particular thread (i.e. temporarily enable | |
2145 | schedlock). */ | |
2146 | if (read_pc_pid (singlestep_ptid) != singlestep_pc) | |
2147 | { | |
2148 | if (debug_infrun) | |
2149 | fprintf_unfiltered (gdb_stdlog, "infrun: unexpected thread," | |
2150 | " but expected thread advanced also\n"); | |
2151 | ||
2152 | /* The current context still belongs to | |
2153 | singlestep_ptid. Don't swap here, since that's | |
2154 | the context we want to use. Just fudge our | |
2155 | state and continue. */ | |
2156 | ecs->ptid = singlestep_ptid; | |
2157 | stop_pc = read_pc_pid (ecs->ptid); | |
2158 | } | |
2159 | else | |
2160 | { | |
2161 | if (debug_infrun) | |
2162 | fprintf_unfiltered (gdb_stdlog, | |
2163 | "infrun: unexpected thread\n"); | |
2164 | ||
2165 | thread_hop_needed = 1; | |
2166 | stepping_past_singlestep_breakpoint = 1; | |
2167 | saved_singlestep_ptid = singlestep_ptid; | |
2168 | } | |
9f976b41 DJ |
2169 | } |
2170 | } | |
2171 | ||
2172 | if (thread_hop_needed) | |
8fb3e588 | 2173 | { |
237fc4c9 | 2174 | int remove_status = 0; |
8fb3e588 | 2175 | |
527159b7 | 2176 | if (debug_infrun) |
8a9de0e4 | 2177 | fprintf_unfiltered (gdb_stdlog, "infrun: thread_hop_needed\n"); |
527159b7 | 2178 | |
8fb3e588 AC |
2179 | /* Saw a breakpoint, but it was hit by the wrong thread. |
2180 | Just continue. */ | |
2181 | ||
1c0fdd0e | 2182 | if (singlestep_breakpoints_inserted_p) |
488f131b | 2183 | { |
8fb3e588 | 2184 | /* Pull the single step breakpoints out of the target. */ |
e0cd558a | 2185 | remove_single_step_breakpoints (); |
8fb3e588 AC |
2186 | singlestep_breakpoints_inserted_p = 0; |
2187 | } | |
2188 | ||
237fc4c9 PA |
2189 | /* If the arch can displace step, don't remove the |
2190 | breakpoints. */ | |
2191 | if (!use_displaced_stepping (current_gdbarch)) | |
2192 | remove_status = remove_breakpoints (); | |
2193 | ||
8fb3e588 AC |
2194 | /* Did we fail to remove breakpoints? If so, try |
2195 | to set the PC past the bp. (There's at least | |
2196 | one situation in which we can fail to remove | |
2197 | the bp's: On HP-UX's that use ttrace, we can't | |
2198 | change the address space of a vforking child | |
2199 | process until the child exits (well, okay, not | |
2200 | then either :-) or execs. */ | |
2201 | if (remove_status != 0) | |
9d9cd7ac | 2202 | error (_("Cannot step over breakpoint hit in wrong thread")); |
8fb3e588 AC |
2203 | else |
2204 | { /* Single step */ | |
8fb3e588 AC |
2205 | if (!ptid_equal (inferior_ptid, ecs->ptid)) |
2206 | context_switch (ecs); | |
2207 | ecs->waiton_ptid = ecs->ptid; | |
2208 | ecs->wp = &(ecs->ws); | |
ca67fcb8 | 2209 | ecs->stepping_over_breakpoint = 1; |
8fb3e588 AC |
2210 | |
2211 | ecs->infwait_state = infwait_thread_hop_state; | |
2212 | keep_going (ecs); | |
2213 | registers_changed (); | |
2214 | return; | |
2215 | } | |
488f131b | 2216 | } |
1c0fdd0e | 2217 | else if (singlestep_breakpoints_inserted_p) |
8fb3e588 AC |
2218 | { |
2219 | sw_single_step_trap_p = 1; | |
2220 | ecs->random_signal = 0; | |
2221 | } | |
488f131b JB |
2222 | } |
2223 | else | |
2224 | ecs->random_signal = 1; | |
c906108c | 2225 | |
488f131b | 2226 | /* See if something interesting happened to the non-current thread. If |
b40c7d58 DJ |
2227 | so, then switch to that thread. */ |
2228 | if (!ptid_equal (ecs->ptid, inferior_ptid)) | |
488f131b | 2229 | { |
527159b7 | 2230 | if (debug_infrun) |
8a9de0e4 | 2231 | fprintf_unfiltered (gdb_stdlog, "infrun: context switch\n"); |
527159b7 | 2232 | |
488f131b | 2233 | context_switch (ecs); |
c5aa993b | 2234 | |
9a4105ab AC |
2235 | if (deprecated_context_hook) |
2236 | deprecated_context_hook (pid_to_thread_id (ecs->ptid)); | |
488f131b | 2237 | } |
c906108c | 2238 | |
1c0fdd0e | 2239 | if (singlestep_breakpoints_inserted_p) |
488f131b JB |
2240 | { |
2241 | /* Pull the single step breakpoints out of the target. */ | |
e0cd558a | 2242 | remove_single_step_breakpoints (); |
488f131b JB |
2243 | singlestep_breakpoints_inserted_p = 0; |
2244 | } | |
c906108c | 2245 | |
d983da9c DJ |
2246 | if (stepped_after_stopped_by_watchpoint) |
2247 | stopped_by_watchpoint = 0; | |
2248 | else | |
2249 | stopped_by_watchpoint = watchpoints_triggered (&ecs->ws); | |
2250 | ||
2251 | /* If necessary, step over this watchpoint. We'll be back to display | |
2252 | it in a moment. */ | |
2253 | if (stopped_by_watchpoint | |
2254 | && (HAVE_STEPPABLE_WATCHPOINT | |
2255 | || gdbarch_have_nonsteppable_watchpoint (current_gdbarch))) | |
488f131b | 2256 | { |
488f131b JB |
2257 | /* At this point, we are stopped at an instruction which has |
2258 | attempted to write to a piece of memory under control of | |
2259 | a watchpoint. The instruction hasn't actually executed | |
2260 | yet. If we were to evaluate the watchpoint expression | |
2261 | now, we would get the old value, and therefore no change | |
2262 | would seem to have occurred. | |
2263 | ||
2264 | In order to make watchpoints work `right', we really need | |
2265 | to complete the memory write, and then evaluate the | |
d983da9c DJ |
2266 | watchpoint expression. We do this by single-stepping the |
2267 | target. | |
2268 | ||
2269 | It may not be necessary to disable the watchpoint to stop over | |
2270 | it. For example, the PA can (with some kernel cooperation) | |
2271 | single step over a watchpoint without disabling the watchpoint. | |
2272 | ||
2273 | It is far more common to need to disable a watchpoint to step | |
2274 | the inferior over it. If we have non-steppable watchpoints, | |
2275 | we must disable the current watchpoint; it's simplest to | |
2276 | disable all watchpoints and breakpoints. */ | |
2277 | ||
2278 | if (!HAVE_STEPPABLE_WATCHPOINT) | |
2279 | remove_breakpoints (); | |
488f131b JB |
2280 | registers_changed (); |
2281 | target_resume (ecs->ptid, 1, TARGET_SIGNAL_0); /* Single step */ | |
488f131b | 2282 | ecs->waiton_ptid = ecs->ptid; |
d983da9c DJ |
2283 | if (HAVE_STEPPABLE_WATCHPOINT) |
2284 | ecs->infwait_state = infwait_step_watch_state; | |
2285 | else | |
2286 | ecs->infwait_state = infwait_nonstep_watch_state; | |
488f131b JB |
2287 | prepare_to_wait (ecs); |
2288 | return; | |
2289 | } | |
2290 | ||
488f131b JB |
2291 | ecs->stop_func_start = 0; |
2292 | ecs->stop_func_end = 0; | |
2293 | ecs->stop_func_name = 0; | |
2294 | /* Don't care about return value; stop_func_start and stop_func_name | |
2295 | will both be 0 if it doesn't work. */ | |
2296 | find_pc_partial_function (stop_pc, &ecs->stop_func_name, | |
2297 | &ecs->stop_func_start, &ecs->stop_func_end); | |
cbf3b44a UW |
2298 | ecs->stop_func_start |
2299 | += gdbarch_deprecated_function_start_offset (current_gdbarch); | |
ca67fcb8 | 2300 | ecs->stepping_over_breakpoint = 0; |
488f131b JB |
2301 | bpstat_clear (&stop_bpstat); |
2302 | stop_step = 0; | |
488f131b JB |
2303 | stop_print_frame = 1; |
2304 | ecs->random_signal = 0; | |
2305 | stopped_by_random_signal = 0; | |
488f131b | 2306 | |
3352ef37 | 2307 | if (stop_signal == TARGET_SIGNAL_TRAP |
ca67fcb8 | 2308 | && stepping_over_breakpoint |
3352ef37 AC |
2309 | && gdbarch_single_step_through_delay_p (current_gdbarch) |
2310 | && currently_stepping (ecs)) | |
2311 | { | |
b50d7442 | 2312 | /* We're trying to step off a breakpoint. Turns out that we're |
3352ef37 AC |
2313 | also on an instruction that needs to be stepped multiple |
2314 | times before it's been fully executing. E.g., architectures | |
2315 | with a delay slot. It needs to be stepped twice, once for | |
2316 | the instruction and once for the delay slot. */ | |
2317 | int step_through_delay | |
2318 | = gdbarch_single_step_through_delay (current_gdbarch, | |
2319 | get_current_frame ()); | |
527159b7 | 2320 | if (debug_infrun && step_through_delay) |
8a9de0e4 | 2321 | fprintf_unfiltered (gdb_stdlog, "infrun: step through delay\n"); |
3352ef37 AC |
2322 | if (step_range_end == 0 && step_through_delay) |
2323 | { | |
2324 | /* The user issued a continue when stopped at a breakpoint. | |
2325 | Set up for another trap and get out of here. */ | |
ca67fcb8 | 2326 | ecs->stepping_over_breakpoint = 1; |
3352ef37 AC |
2327 | keep_going (ecs); |
2328 | return; | |
2329 | } | |
2330 | else if (step_through_delay) | |
2331 | { | |
2332 | /* The user issued a step when stopped at a breakpoint. | |
2333 | Maybe we should stop, maybe we should not - the delay | |
2334 | slot *might* correspond to a line of source. In any | |
ca67fcb8 VP |
2335 | case, don't decide that here, just set |
2336 | ecs->stepping_over_breakpoint, making sure we | |
2337 | single-step again before breakpoints are re-inserted. */ | |
2338 | ecs->stepping_over_breakpoint = 1; | |
3352ef37 AC |
2339 | } |
2340 | } | |
2341 | ||
488f131b JB |
2342 | /* Look at the cause of the stop, and decide what to do. |
2343 | The alternatives are: | |
2344 | 1) break; to really stop and return to the debugger, | |
2345 | 2) drop through to start up again | |
ca67fcb8 | 2346 | (set ecs->stepping_over_breakpoint to 1 to single step once) |
488f131b JB |
2347 | 3) set ecs->random_signal to 1, and the decision between 1 and 2 |
2348 | will be made according to the signal handling tables. */ | |
2349 | ||
2350 | /* First, distinguish signals caused by the debugger from signals | |
03cebad2 MK |
2351 | that have to do with the program's own actions. Note that |
2352 | breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending | |
2353 | on the operating system version. Here we detect when a SIGILL or | |
2354 | SIGEMT is really a breakpoint and change it to SIGTRAP. We do | |
2355 | something similar for SIGSEGV, since a SIGSEGV will be generated | |
2356 | when we're trying to execute a breakpoint instruction on a | |
2357 | non-executable stack. This happens for call dummy breakpoints | |
2358 | for architectures like SPARC that place call dummies on the | |
237fc4c9 | 2359 | stack. |
488f131b | 2360 | |
237fc4c9 PA |
2361 | If we're doing a displaced step past a breakpoint, then the |
2362 | breakpoint is always inserted at the original instruction; | |
2363 | non-standard signals can't be explained by the breakpoint. */ | |
488f131b | 2364 | if (stop_signal == TARGET_SIGNAL_TRAP |
237fc4c9 PA |
2365 | || (! stepping_over_breakpoint |
2366 | && breakpoint_inserted_here_p (stop_pc) | |
8fb3e588 AC |
2367 | && (stop_signal == TARGET_SIGNAL_ILL |
2368 | || stop_signal == TARGET_SIGNAL_SEGV | |
2369 | || stop_signal == TARGET_SIGNAL_EMT)) | |
b0f4b84b DJ |
2370 | || stop_soon == STOP_QUIETLY || stop_soon == STOP_QUIETLY_NO_SIGSTOP |
2371 | || stop_soon == STOP_QUIETLY_REMOTE) | |
488f131b JB |
2372 | { |
2373 | if (stop_signal == TARGET_SIGNAL_TRAP && stop_after_trap) | |
2374 | { | |
527159b7 | 2375 | if (debug_infrun) |
8a9de0e4 | 2376 | fprintf_unfiltered (gdb_stdlog, "infrun: stopped\n"); |
488f131b JB |
2377 | stop_print_frame = 0; |
2378 | stop_stepping (ecs); | |
2379 | return; | |
2380 | } | |
c54cfec8 EZ |
2381 | |
2382 | /* This is originated from start_remote(), start_inferior() and | |
2383 | shared libraries hook functions. */ | |
b0f4b84b | 2384 | if (stop_soon == STOP_QUIETLY || stop_soon == STOP_QUIETLY_REMOTE) |
488f131b | 2385 | { |
527159b7 | 2386 | if (debug_infrun) |
8a9de0e4 | 2387 | fprintf_unfiltered (gdb_stdlog, "infrun: quietly stopped\n"); |
488f131b JB |
2388 | stop_stepping (ecs); |
2389 | return; | |
2390 | } | |
2391 | ||
c54cfec8 EZ |
2392 | /* This originates from attach_command(). We need to overwrite |
2393 | the stop_signal here, because some kernels don't ignore a | |
a0ef4274 DJ |
2394 | SIGSTOP in a subsequent ptrace(PTRACE_CONT,SIGSTOP) call. |
2395 | See more comments in inferior.h. On the other hand, if we | |
2396 | get a non-SIGSTOP, report it to the user - assume the backend | |
2397 | will handle the SIGSTOP if it should show up later. */ | |
2398 | if (stop_soon == STOP_QUIETLY_NO_SIGSTOP | |
2399 | && stop_signal == TARGET_SIGNAL_STOP) | |
c54cfec8 EZ |
2400 | { |
2401 | stop_stepping (ecs); | |
a0ef4274 | 2402 | stop_signal = TARGET_SIGNAL_0; |
c54cfec8 EZ |
2403 | return; |
2404 | } | |
2405 | ||
fba57f8f VP |
2406 | /* See if there is a breakpoint at the current PC. */ |
2407 | stop_bpstat = bpstat_stop_status (stop_pc, ecs->ptid); | |
2408 | ||
2409 | /* Following in case break condition called a | |
2410 | function. */ | |
2411 | stop_print_frame = 1; | |
488f131b | 2412 | |
73dd234f | 2413 | /* NOTE: cagney/2003-03-29: These two checks for a random signal |
8fb3e588 AC |
2414 | at one stage in the past included checks for an inferior |
2415 | function call's call dummy's return breakpoint. The original | |
2416 | comment, that went with the test, read: | |
73dd234f | 2417 | |
8fb3e588 AC |
2418 | ``End of a stack dummy. Some systems (e.g. Sony news) give |
2419 | another signal besides SIGTRAP, so check here as well as | |
2420 | above.'' | |
73dd234f AC |
2421 | |
2422 | If someone ever tries to get get call dummys on a | |
2423 | non-executable stack to work (where the target would stop | |
03cebad2 MK |
2424 | with something like a SIGSEGV), then those tests might need |
2425 | to be re-instated. Given, however, that the tests were only | |
73dd234f | 2426 | enabled when momentary breakpoints were not being used, I |
03cebad2 MK |
2427 | suspect that it won't be the case. |
2428 | ||
8fb3e588 AC |
2429 | NOTE: kettenis/2004-02-05: Indeed such checks don't seem to |
2430 | be necessary for call dummies on a non-executable stack on | |
2431 | SPARC. */ | |
73dd234f | 2432 | |
488f131b JB |
2433 | if (stop_signal == TARGET_SIGNAL_TRAP) |
2434 | ecs->random_signal | |
2435 | = !(bpstat_explains_signal (stop_bpstat) | |
ca67fcb8 | 2436 | || stepping_over_breakpoint |
488f131b | 2437 | || (step_range_end && step_resume_breakpoint == NULL)); |
488f131b JB |
2438 | else |
2439 | { | |
73dd234f | 2440 | ecs->random_signal = !bpstat_explains_signal (stop_bpstat); |
488f131b JB |
2441 | if (!ecs->random_signal) |
2442 | stop_signal = TARGET_SIGNAL_TRAP; | |
2443 | } | |
2444 | } | |
2445 | ||
2446 | /* When we reach this point, we've pretty much decided | |
2447 | that the reason for stopping must've been a random | |
2448 | (unexpected) signal. */ | |
2449 | ||
2450 | else | |
2451 | ecs->random_signal = 1; | |
488f131b | 2452 | |
04e68871 | 2453 | process_event_stop_test: |
488f131b JB |
2454 | /* For the program's own signals, act according to |
2455 | the signal handling tables. */ | |
2456 | ||
2457 | if (ecs->random_signal) | |
2458 | { | |
2459 | /* Signal not for debugging purposes. */ | |
2460 | int printed = 0; | |
2461 | ||
527159b7 | 2462 | if (debug_infrun) |
8a9de0e4 | 2463 | fprintf_unfiltered (gdb_stdlog, "infrun: random signal %d\n", stop_signal); |
527159b7 | 2464 | |
488f131b JB |
2465 | stopped_by_random_signal = 1; |
2466 | ||
2467 | if (signal_print[stop_signal]) | |
2468 | { | |
2469 | printed = 1; | |
2470 | target_terminal_ours_for_output (); | |
2471 | print_stop_reason (SIGNAL_RECEIVED, stop_signal); | |
2472 | } | |
a0ef4274 | 2473 | if (signal_stop_state (stop_signal)) |
488f131b JB |
2474 | { |
2475 | stop_stepping (ecs); | |
2476 | return; | |
2477 | } | |
2478 | /* If not going to stop, give terminal back | |
2479 | if we took it away. */ | |
2480 | else if (printed) | |
2481 | target_terminal_inferior (); | |
2482 | ||
2483 | /* Clear the signal if it should not be passed. */ | |
2484 | if (signal_program[stop_signal] == 0) | |
2485 | stop_signal = TARGET_SIGNAL_0; | |
2486 | ||
68f53502 | 2487 | if (prev_pc == read_pc () |
74960c60 | 2488 | && stepping_over_breakpoint |
68f53502 AC |
2489 | && step_resume_breakpoint == NULL) |
2490 | { | |
2491 | /* We were just starting a new sequence, attempting to | |
2492 | single-step off of a breakpoint and expecting a SIGTRAP. | |
237fc4c9 | 2493 | Instead this signal arrives. This signal will take us out |
68f53502 AC |
2494 | of the stepping range so GDB needs to remember to, when |
2495 | the signal handler returns, resume stepping off that | |
2496 | breakpoint. */ | |
2497 | /* To simplify things, "continue" is forced to use the same | |
2498 | code paths as single-step - set a breakpoint at the | |
2499 | signal return address and then, once hit, step off that | |
2500 | breakpoint. */ | |
237fc4c9 PA |
2501 | if (debug_infrun) |
2502 | fprintf_unfiltered (gdb_stdlog, | |
2503 | "infrun: signal arrived while stepping over " | |
2504 | "breakpoint\n"); | |
d3169d93 | 2505 | |
44cbf7b5 | 2506 | insert_step_resume_breakpoint_at_frame (get_current_frame ()); |
68f53502 | 2507 | ecs->step_after_step_resume_breakpoint = 1; |
9d799f85 AC |
2508 | keep_going (ecs); |
2509 | return; | |
68f53502 | 2510 | } |
9d799f85 AC |
2511 | |
2512 | if (step_range_end != 0 | |
2513 | && stop_signal != TARGET_SIGNAL_0 | |
2514 | && stop_pc >= step_range_start && stop_pc < step_range_end | |
2515 | && frame_id_eq (get_frame_id (get_current_frame ()), | |
2516 | step_frame_id) | |
2517 | && step_resume_breakpoint == NULL) | |
d303a6c7 AC |
2518 | { |
2519 | /* The inferior is about to take a signal that will take it | |
2520 | out of the single step range. Set a breakpoint at the | |
2521 | current PC (which is presumably where the signal handler | |
2522 | will eventually return) and then allow the inferior to | |
2523 | run free. | |
2524 | ||
2525 | Note that this is only needed for a signal delivered | |
2526 | while in the single-step range. Nested signals aren't a | |
2527 | problem as they eventually all return. */ | |
237fc4c9 PA |
2528 | if (debug_infrun) |
2529 | fprintf_unfiltered (gdb_stdlog, | |
2530 | "infrun: signal may take us out of " | |
2531 | "single-step range\n"); | |
2532 | ||
44cbf7b5 | 2533 | insert_step_resume_breakpoint_at_frame (get_current_frame ()); |
9d799f85 AC |
2534 | keep_going (ecs); |
2535 | return; | |
d303a6c7 | 2536 | } |
9d799f85 AC |
2537 | |
2538 | /* Note: step_resume_breakpoint may be non-NULL. This occures | |
2539 | when either there's a nested signal, or when there's a | |
2540 | pending signal enabled just as the signal handler returns | |
2541 | (leaving the inferior at the step-resume-breakpoint without | |
2542 | actually executing it). Either way continue until the | |
2543 | breakpoint is really hit. */ | |
488f131b JB |
2544 | keep_going (ecs); |
2545 | return; | |
2546 | } | |
2547 | ||
2548 | /* Handle cases caused by hitting a breakpoint. */ | |
2549 | { | |
2550 | CORE_ADDR jmp_buf_pc; | |
2551 | struct bpstat_what what; | |
2552 | ||
2553 | what = bpstat_what (stop_bpstat); | |
2554 | ||
2555 | if (what.call_dummy) | |
2556 | { | |
2557 | stop_stack_dummy = 1; | |
c5aa993b | 2558 | } |
c906108c | 2559 | |
488f131b | 2560 | switch (what.main_action) |
c5aa993b | 2561 | { |
488f131b JB |
2562 | case BPSTAT_WHAT_SET_LONGJMP_RESUME: |
2563 | /* If we hit the breakpoint at longjmp, disable it for the | |
2564 | duration of this command. Then, install a temporary | |
2565 | breakpoint at the target of the jmp_buf. */ | |
527159b7 | 2566 | if (debug_infrun) |
8802d8ed | 2567 | fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME\n"); |
488f131b | 2568 | disable_longjmp_breakpoint (); |
91104499 | 2569 | if (!gdbarch_get_longjmp_target_p (current_gdbarch) |
60ade65d UW |
2570 | || !gdbarch_get_longjmp_target (current_gdbarch, |
2571 | get_current_frame (), &jmp_buf_pc)) | |
c5aa993b | 2572 | { |
488f131b | 2573 | keep_going (ecs); |
104c1213 | 2574 | return; |
c5aa993b | 2575 | } |
488f131b JB |
2576 | |
2577 | /* Need to blow away step-resume breakpoint, as it | |
2578 | interferes with us */ | |
2579 | if (step_resume_breakpoint != NULL) | |
104c1213 | 2580 | { |
488f131b | 2581 | delete_step_resume_breakpoint (&step_resume_breakpoint); |
104c1213 | 2582 | } |
c906108c | 2583 | |
8fb3e588 | 2584 | set_longjmp_resume_breakpoint (jmp_buf_pc, null_frame_id); |
488f131b JB |
2585 | ecs->handling_longjmp = 1; /* FIXME */ |
2586 | keep_going (ecs); | |
2587 | return; | |
c906108c | 2588 | |
488f131b | 2589 | case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME: |
527159b7 | 2590 | if (debug_infrun) |
8802d8ed | 2591 | fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME\n"); |
488f131b JB |
2592 | disable_longjmp_breakpoint (); |
2593 | ecs->handling_longjmp = 0; /* FIXME */ | |
78b6a731 | 2594 | break; |
488f131b JB |
2595 | |
2596 | case BPSTAT_WHAT_SINGLE: | |
527159b7 | 2597 | if (debug_infrun) |
8802d8ed | 2598 | fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_SINGLE\n"); |
ca67fcb8 | 2599 | ecs->stepping_over_breakpoint = 1; |
488f131b JB |
2600 | /* Still need to check other stuff, at least the case |
2601 | where we are stepping and step out of the right range. */ | |
2602 | break; | |
c906108c | 2603 | |
488f131b | 2604 | case BPSTAT_WHAT_STOP_NOISY: |
527159b7 | 2605 | if (debug_infrun) |
8802d8ed | 2606 | fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STOP_NOISY\n"); |
488f131b | 2607 | stop_print_frame = 1; |
c906108c | 2608 | |
d303a6c7 AC |
2609 | /* We are about to nuke the step_resume_breakpointt via the |
2610 | cleanup chain, so no need to worry about it here. */ | |
c5aa993b | 2611 | |
488f131b JB |
2612 | stop_stepping (ecs); |
2613 | return; | |
c5aa993b | 2614 | |
488f131b | 2615 | case BPSTAT_WHAT_STOP_SILENT: |
527159b7 | 2616 | if (debug_infrun) |
8802d8ed | 2617 | fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STOP_SILENT\n"); |
488f131b | 2618 | stop_print_frame = 0; |
c5aa993b | 2619 | |
d303a6c7 AC |
2620 | /* We are about to nuke the step_resume_breakpoin via the |
2621 | cleanup chain, so no need to worry about it here. */ | |
c5aa993b | 2622 | |
488f131b | 2623 | stop_stepping (ecs); |
e441088d | 2624 | return; |
c5aa993b | 2625 | |
488f131b JB |
2626 | case BPSTAT_WHAT_STEP_RESUME: |
2627 | /* This proably demands a more elegant solution, but, yeah | |
2628 | right... | |
c5aa993b | 2629 | |
488f131b JB |
2630 | This function's use of the simple variable |
2631 | step_resume_breakpoint doesn't seem to accomodate | |
2632 | simultaneously active step-resume bp's, although the | |
2633 | breakpoint list certainly can. | |
c5aa993b | 2634 | |
488f131b JB |
2635 | If we reach here and step_resume_breakpoint is already |
2636 | NULL, then apparently we have multiple active | |
2637 | step-resume bp's. We'll just delete the breakpoint we | |
2638 | stopped at, and carry on. | |
2639 | ||
2640 | Correction: what the code currently does is delete a | |
2641 | step-resume bp, but it makes no effort to ensure that | |
2642 | the one deleted is the one currently stopped at. MVS */ | |
c5aa993b | 2643 | |
527159b7 | 2644 | if (debug_infrun) |
8802d8ed | 2645 | fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STEP_RESUME\n"); |
527159b7 | 2646 | |
488f131b JB |
2647 | if (step_resume_breakpoint == NULL) |
2648 | { | |
2649 | step_resume_breakpoint = | |
2650 | bpstat_find_step_resume_breakpoint (stop_bpstat); | |
2651 | } | |
2652 | delete_step_resume_breakpoint (&step_resume_breakpoint); | |
68f53502 AC |
2653 | if (ecs->step_after_step_resume_breakpoint) |
2654 | { | |
2655 | /* Back when the step-resume breakpoint was inserted, we | |
2656 | were trying to single-step off a breakpoint. Go back | |
2657 | to doing that. */ | |
2658 | ecs->step_after_step_resume_breakpoint = 0; | |
ca67fcb8 | 2659 | ecs->stepping_over_breakpoint = 1; |
68f53502 AC |
2660 | keep_going (ecs); |
2661 | return; | |
2662 | } | |
488f131b JB |
2663 | break; |
2664 | ||
488f131b JB |
2665 | case BPSTAT_WHAT_CHECK_SHLIBS: |
2666 | case BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK: | |
c906108c | 2667 | { |
527159b7 | 2668 | if (debug_infrun) |
8802d8ed | 2669 | fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_CHECK_SHLIBS\n"); |
488f131b JB |
2670 | |
2671 | /* Check for any newly added shared libraries if we're | |
2672 | supposed to be adding them automatically. Switch | |
2673 | terminal for any messages produced by | |
2674 | breakpoint_re_set. */ | |
2675 | target_terminal_ours_for_output (); | |
aff6338a | 2676 | /* NOTE: cagney/2003-11-25: Make certain that the target |
8fb3e588 AC |
2677 | stack's section table is kept up-to-date. Architectures, |
2678 | (e.g., PPC64), use the section table to perform | |
2679 | operations such as address => section name and hence | |
2680 | require the table to contain all sections (including | |
2681 | those found in shared libraries). */ | |
aff6338a | 2682 | /* NOTE: cagney/2003-11-25: Pass current_target and not |
8fb3e588 AC |
2683 | exec_ops to SOLIB_ADD. This is because current GDB is |
2684 | only tooled to propagate section_table changes out from | |
2685 | the "current_target" (see target_resize_to_sections), and | |
2686 | not up from the exec stratum. This, of course, isn't | |
2687 | right. "infrun.c" should only interact with the | |
2688 | exec/process stratum, instead relying on the target stack | |
2689 | to propagate relevant changes (stop, section table | |
2690 | changed, ...) up to other layers. */ | |
a77053c2 | 2691 | #ifdef SOLIB_ADD |
aff6338a | 2692 | SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add); |
a77053c2 MK |
2693 | #else |
2694 | solib_add (NULL, 0, ¤t_target, auto_solib_add); | |
2695 | #endif | |
488f131b JB |
2696 | target_terminal_inferior (); |
2697 | ||
488f131b JB |
2698 | /* If requested, stop when the dynamic linker notifies |
2699 | gdb of events. This allows the user to get control | |
2700 | and place breakpoints in initializer routines for | |
2701 | dynamically loaded objects (among other things). */ | |
877522db | 2702 | if (stop_on_solib_events || stop_stack_dummy) |
d4f3574e | 2703 | { |
488f131b | 2704 | stop_stepping (ecs); |
d4f3574e SS |
2705 | return; |
2706 | } | |
c5aa993b | 2707 | |
488f131b JB |
2708 | /* If we stopped due to an explicit catchpoint, then the |
2709 | (see above) call to SOLIB_ADD pulled in any symbols | |
2710 | from a newly-loaded library, if appropriate. | |
2711 | ||
2712 | We do want the inferior to stop, but not where it is | |
2713 | now, which is in the dynamic linker callback. Rather, | |
2714 | we would like it stop in the user's program, just after | |
2715 | the call that caused this catchpoint to trigger. That | |
2716 | gives the user a more useful vantage from which to | |
2717 | examine their program's state. */ | |
8fb3e588 AC |
2718 | else if (what.main_action |
2719 | == BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK) | |
c906108c | 2720 | { |
488f131b JB |
2721 | /* ??rehrauer: If I could figure out how to get the |
2722 | right return PC from here, we could just set a temp | |
2723 | breakpoint and resume. I'm not sure we can without | |
2724 | cracking open the dld's shared libraries and sniffing | |
2725 | their unwind tables and text/data ranges, and that's | |
2726 | not a terribly portable notion. | |
2727 | ||
2728 | Until that time, we must step the inferior out of the | |
2729 | dld callback, and also out of the dld itself (and any | |
2730 | code or stubs in libdld.sl, such as "shl_load" and | |
2731 | friends) until we reach non-dld code. At that point, | |
2732 | we can stop stepping. */ | |
2733 | bpstat_get_triggered_catchpoints (stop_bpstat, | |
2734 | &ecs-> | |
2735 | stepping_through_solib_catchpoints); | |
2736 | ecs->stepping_through_solib_after_catch = 1; | |
2737 | ||
2738 | /* Be sure to lift all breakpoints, so the inferior does | |
2739 | actually step past this point... */ | |
ca67fcb8 | 2740 | ecs->stepping_over_breakpoint = 1; |
488f131b | 2741 | break; |
c906108c | 2742 | } |
c5aa993b | 2743 | else |
c5aa993b | 2744 | { |
488f131b | 2745 | /* We want to step over this breakpoint, then keep going. */ |
ca67fcb8 | 2746 | ecs->stepping_over_breakpoint = 1; |
488f131b | 2747 | break; |
c5aa993b | 2748 | } |
488f131b | 2749 | } |
488f131b | 2750 | break; |
c906108c | 2751 | |
488f131b JB |
2752 | case BPSTAT_WHAT_LAST: |
2753 | /* Not a real code, but listed here to shut up gcc -Wall. */ | |
c906108c | 2754 | |
488f131b JB |
2755 | case BPSTAT_WHAT_KEEP_CHECKING: |
2756 | break; | |
2757 | } | |
2758 | } | |
c906108c | 2759 | |
488f131b JB |
2760 | /* We come here if we hit a breakpoint but should not |
2761 | stop for it. Possibly we also were stepping | |
2762 | and should stop for that. So fall through and | |
2763 | test for stepping. But, if not stepping, | |
2764 | do not stop. */ | |
c906108c | 2765 | |
9d1ff73f MS |
2766 | /* Are we stepping to get the inferior out of the dynamic linker's |
2767 | hook (and possibly the dld itself) after catching a shlib | |
2768 | event? */ | |
488f131b JB |
2769 | if (ecs->stepping_through_solib_after_catch) |
2770 | { | |
2771 | #if defined(SOLIB_ADD) | |
2772 | /* Have we reached our destination? If not, keep going. */ | |
2773 | if (SOLIB_IN_DYNAMIC_LINKER (PIDGET (ecs->ptid), stop_pc)) | |
2774 | { | |
527159b7 | 2775 | if (debug_infrun) |
8a9de0e4 | 2776 | fprintf_unfiltered (gdb_stdlog, "infrun: stepping in dynamic linker\n"); |
ca67fcb8 | 2777 | ecs->stepping_over_breakpoint = 1; |
488f131b | 2778 | keep_going (ecs); |
104c1213 | 2779 | return; |
488f131b JB |
2780 | } |
2781 | #endif | |
527159b7 | 2782 | if (debug_infrun) |
8a9de0e4 | 2783 | fprintf_unfiltered (gdb_stdlog, "infrun: step past dynamic linker\n"); |
488f131b JB |
2784 | /* Else, stop and report the catchpoint(s) whose triggering |
2785 | caused us to begin stepping. */ | |
2786 | ecs->stepping_through_solib_after_catch = 0; | |
2787 | bpstat_clear (&stop_bpstat); | |
2788 | stop_bpstat = bpstat_copy (ecs->stepping_through_solib_catchpoints); | |
2789 | bpstat_clear (&ecs->stepping_through_solib_catchpoints); | |
2790 | stop_print_frame = 1; | |
2791 | stop_stepping (ecs); | |
2792 | return; | |
2793 | } | |
c906108c | 2794 | |
488f131b JB |
2795 | if (step_resume_breakpoint) |
2796 | { | |
527159b7 | 2797 | if (debug_infrun) |
d3169d93 DJ |
2798 | fprintf_unfiltered (gdb_stdlog, |
2799 | "infrun: step-resume breakpoint is inserted\n"); | |
527159b7 | 2800 | |
488f131b JB |
2801 | /* Having a step-resume breakpoint overrides anything |
2802 | else having to do with stepping commands until | |
2803 | that breakpoint is reached. */ | |
488f131b JB |
2804 | keep_going (ecs); |
2805 | return; | |
2806 | } | |
c5aa993b | 2807 | |
488f131b JB |
2808 | if (step_range_end == 0) |
2809 | { | |
527159b7 | 2810 | if (debug_infrun) |
8a9de0e4 | 2811 | fprintf_unfiltered (gdb_stdlog, "infrun: no stepping, continue\n"); |
488f131b | 2812 | /* Likewise if we aren't even stepping. */ |
488f131b JB |
2813 | keep_going (ecs); |
2814 | return; | |
2815 | } | |
c5aa993b | 2816 | |
488f131b | 2817 | /* If stepping through a line, keep going if still within it. |
c906108c | 2818 | |
488f131b JB |
2819 | Note that step_range_end is the address of the first instruction |
2820 | beyond the step range, and NOT the address of the last instruction | |
2821 | within it! */ | |
2822 | if (stop_pc >= step_range_start && stop_pc < step_range_end) | |
2823 | { | |
527159b7 | 2824 | if (debug_infrun) |
8a9de0e4 | 2825 | fprintf_unfiltered (gdb_stdlog, "infrun: stepping inside range [0x%s-0x%s]\n", |
527159b7 RC |
2826 | paddr_nz (step_range_start), |
2827 | paddr_nz (step_range_end)); | |
488f131b JB |
2828 | keep_going (ecs); |
2829 | return; | |
2830 | } | |
c5aa993b | 2831 | |
488f131b | 2832 | /* We stepped out of the stepping range. */ |
c906108c | 2833 | |
488f131b JB |
2834 | /* If we are stepping at the source level and entered the runtime |
2835 | loader dynamic symbol resolution code, we keep on single stepping | |
2836 | until we exit the run time loader code and reach the callee's | |
2837 | address. */ | |
2838 | if (step_over_calls == STEP_OVER_UNDEBUGGABLE | |
a77053c2 MK |
2839 | #ifdef IN_SOLIB_DYNSYM_RESOLVE_CODE |
2840 | && IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc) | |
2841 | #else | |
2842 | && in_solib_dynsym_resolve_code (stop_pc) | |
2843 | #endif | |
2844 | ) | |
488f131b | 2845 | { |
4c8c40e6 MK |
2846 | CORE_ADDR pc_after_resolver = |
2847 | gdbarch_skip_solib_resolver (current_gdbarch, stop_pc); | |
c906108c | 2848 | |
527159b7 | 2849 | if (debug_infrun) |
8a9de0e4 | 2850 | fprintf_unfiltered (gdb_stdlog, "infrun: stepped into dynsym resolve code\n"); |
527159b7 | 2851 | |
488f131b JB |
2852 | if (pc_after_resolver) |
2853 | { | |
2854 | /* Set up a step-resume breakpoint at the address | |
2855 | indicated by SKIP_SOLIB_RESOLVER. */ | |
2856 | struct symtab_and_line sr_sal; | |
fe39c653 | 2857 | init_sal (&sr_sal); |
488f131b JB |
2858 | sr_sal.pc = pc_after_resolver; |
2859 | ||
44cbf7b5 | 2860 | insert_step_resume_breakpoint_at_sal (sr_sal, null_frame_id); |
c5aa993b | 2861 | } |
c906108c | 2862 | |
488f131b JB |
2863 | keep_going (ecs); |
2864 | return; | |
2865 | } | |
c906108c | 2866 | |
42edda50 AC |
2867 | if (step_range_end != 1 |
2868 | && (step_over_calls == STEP_OVER_UNDEBUGGABLE | |
2869 | || step_over_calls == STEP_OVER_ALL) | |
2870 | && get_frame_type (get_current_frame ()) == SIGTRAMP_FRAME) | |
488f131b | 2871 | { |
527159b7 | 2872 | if (debug_infrun) |
8a9de0e4 | 2873 | fprintf_unfiltered (gdb_stdlog, "infrun: stepped into signal trampoline\n"); |
42edda50 | 2874 | /* The inferior, while doing a "step" or "next", has ended up in |
8fb3e588 AC |
2875 | a signal trampoline (either by a signal being delivered or by |
2876 | the signal handler returning). Just single-step until the | |
2877 | inferior leaves the trampoline (either by calling the handler | |
2878 | or returning). */ | |
488f131b JB |
2879 | keep_going (ecs); |
2880 | return; | |
2881 | } | |
c906108c | 2882 | |
c17eaafe DJ |
2883 | /* Check for subroutine calls. The check for the current frame |
2884 | equalling the step ID is not necessary - the check of the | |
2885 | previous frame's ID is sufficient - but it is a common case and | |
2886 | cheaper than checking the previous frame's ID. | |
14e60db5 DJ |
2887 | |
2888 | NOTE: frame_id_eq will never report two invalid frame IDs as | |
2889 | being equal, so to get into this block, both the current and | |
2890 | previous frame must have valid frame IDs. */ | |
c17eaafe DJ |
2891 | if (!frame_id_eq (get_frame_id (get_current_frame ()), step_frame_id) |
2892 | && frame_id_eq (frame_unwind_id (get_current_frame ()), step_frame_id)) | |
488f131b | 2893 | { |
95918acb | 2894 | CORE_ADDR real_stop_pc; |
8fb3e588 | 2895 | |
527159b7 | 2896 | if (debug_infrun) |
8a9de0e4 | 2897 | fprintf_unfiltered (gdb_stdlog, "infrun: stepped into subroutine\n"); |
527159b7 | 2898 | |
95918acb AC |
2899 | if ((step_over_calls == STEP_OVER_NONE) |
2900 | || ((step_range_end == 1) | |
2901 | && in_prologue (prev_pc, ecs->stop_func_start))) | |
2902 | { | |
2903 | /* I presume that step_over_calls is only 0 when we're | |
2904 | supposed to be stepping at the assembly language level | |
2905 | ("stepi"). Just stop. */ | |
2906 | /* Also, maybe we just did a "nexti" inside a prolog, so we | |
2907 | thought it was a subroutine call but it was not. Stop as | |
2908 | well. FENN */ | |
2909 | stop_step = 1; | |
2910 | print_stop_reason (END_STEPPING_RANGE, 0); | |
2911 | stop_stepping (ecs); | |
2912 | return; | |
2913 | } | |
8fb3e588 | 2914 | |
8567c30f AC |
2915 | if (step_over_calls == STEP_OVER_ALL) |
2916 | { | |
2917 | /* We're doing a "next", set a breakpoint at callee's return | |
2918 | address (the address at which the caller will | |
2919 | resume). */ | |
14e60db5 | 2920 | insert_step_resume_breakpoint_at_caller (get_current_frame ()); |
8567c30f AC |
2921 | keep_going (ecs); |
2922 | return; | |
2923 | } | |
a53c66de | 2924 | |
95918acb | 2925 | /* If we are in a function call trampoline (a stub between the |
8fb3e588 AC |
2926 | calling routine and the real function), locate the real |
2927 | function. That's what tells us (a) whether we want to step | |
2928 | into it at all, and (b) what prologue we want to run to the | |
2929 | end of, if we do step into it. */ | |
52f729a7 | 2930 | real_stop_pc = skip_language_trampoline (get_current_frame (), stop_pc); |
95918acb | 2931 | if (real_stop_pc == 0) |
52f729a7 UW |
2932 | real_stop_pc = gdbarch_skip_trampoline_code |
2933 | (current_gdbarch, get_current_frame (), stop_pc); | |
95918acb AC |
2934 | if (real_stop_pc != 0) |
2935 | ecs->stop_func_start = real_stop_pc; | |
8fb3e588 | 2936 | |
a77053c2 MK |
2937 | if ( |
2938 | #ifdef IN_SOLIB_DYNSYM_RESOLVE_CODE | |
2939 | IN_SOLIB_DYNSYM_RESOLVE_CODE (ecs->stop_func_start) | |
2940 | #else | |
2941 | in_solib_dynsym_resolve_code (ecs->stop_func_start) | |
2942 | #endif | |
2943 | ) | |
1b2bfbb9 RC |
2944 | { |
2945 | struct symtab_and_line sr_sal; | |
2946 | init_sal (&sr_sal); | |
2947 | sr_sal.pc = ecs->stop_func_start; | |
2948 | ||
44cbf7b5 | 2949 | insert_step_resume_breakpoint_at_sal (sr_sal, null_frame_id); |
8fb3e588 AC |
2950 | keep_going (ecs); |
2951 | return; | |
1b2bfbb9 RC |
2952 | } |
2953 | ||
95918acb | 2954 | /* If we have line number information for the function we are |
8fb3e588 | 2955 | thinking of stepping into, step into it. |
95918acb | 2956 | |
8fb3e588 AC |
2957 | If there are several symtabs at that PC (e.g. with include |
2958 | files), just want to know whether *any* of them have line | |
2959 | numbers. find_pc_line handles this. */ | |
95918acb AC |
2960 | { |
2961 | struct symtab_and_line tmp_sal; | |
8fb3e588 | 2962 | |
95918acb AC |
2963 | tmp_sal = find_pc_line (ecs->stop_func_start, 0); |
2964 | if (tmp_sal.line != 0) | |
2965 | { | |
2966 | step_into_function (ecs); | |
2967 | return; | |
2968 | } | |
2969 | } | |
2970 | ||
2971 | /* If we have no line number and the step-stop-if-no-debug is | |
8fb3e588 AC |
2972 | set, we stop the step so that the user has a chance to switch |
2973 | in assembly mode. */ | |
95918acb AC |
2974 | if (step_over_calls == STEP_OVER_UNDEBUGGABLE && step_stop_if_no_debug) |
2975 | { | |
2976 | stop_step = 1; | |
2977 | print_stop_reason (END_STEPPING_RANGE, 0); | |
2978 | stop_stepping (ecs); | |
2979 | return; | |
2980 | } | |
2981 | ||
2982 | /* Set a breakpoint at callee's return address (the address at | |
8fb3e588 | 2983 | which the caller will resume). */ |
14e60db5 | 2984 | insert_step_resume_breakpoint_at_caller (get_current_frame ()); |
95918acb | 2985 | keep_going (ecs); |
488f131b | 2986 | return; |
488f131b | 2987 | } |
c906108c | 2988 | |
488f131b JB |
2989 | /* If we're in the return path from a shared library trampoline, |
2990 | we want to proceed through the trampoline when stepping. */ | |
e76f05fa UW |
2991 | if (gdbarch_in_solib_return_trampoline (current_gdbarch, |
2992 | stop_pc, ecs->stop_func_name)) | |
488f131b | 2993 | { |
488f131b | 2994 | /* Determine where this trampoline returns. */ |
52f729a7 UW |
2995 | CORE_ADDR real_stop_pc; |
2996 | real_stop_pc = gdbarch_skip_trampoline_code | |
2997 | (current_gdbarch, get_current_frame (), stop_pc); | |
c906108c | 2998 | |
527159b7 | 2999 | if (debug_infrun) |
8a9de0e4 | 3000 | fprintf_unfiltered (gdb_stdlog, "infrun: stepped into solib return tramp\n"); |
527159b7 | 3001 | |
488f131b | 3002 | /* Only proceed through if we know where it's going. */ |
d764a824 | 3003 | if (real_stop_pc) |
488f131b JB |
3004 | { |
3005 | /* And put the step-breakpoint there and go until there. */ | |
3006 | struct symtab_and_line sr_sal; | |
3007 | ||
fe39c653 | 3008 | init_sal (&sr_sal); /* initialize to zeroes */ |
d764a824 | 3009 | sr_sal.pc = real_stop_pc; |
488f131b | 3010 | sr_sal.section = find_pc_overlay (sr_sal.pc); |
44cbf7b5 AC |
3011 | |
3012 | /* Do not specify what the fp should be when we stop since | |
3013 | on some machines the prologue is where the new fp value | |
3014 | is established. */ | |
3015 | insert_step_resume_breakpoint_at_sal (sr_sal, null_frame_id); | |
c906108c | 3016 | |
488f131b JB |
3017 | /* Restart without fiddling with the step ranges or |
3018 | other state. */ | |
3019 | keep_going (ecs); | |
3020 | return; | |
3021 | } | |
3022 | } | |
c906108c | 3023 | |
7ed0fe66 DJ |
3024 | ecs->sal = find_pc_line (stop_pc, 0); |
3025 | ||
1b2bfbb9 RC |
3026 | /* NOTE: tausq/2004-05-24: This if block used to be done before all |
3027 | the trampoline processing logic, however, there are some trampolines | |
3028 | that have no names, so we should do trampoline handling first. */ | |
3029 | if (step_over_calls == STEP_OVER_UNDEBUGGABLE | |
7ed0fe66 DJ |
3030 | && ecs->stop_func_name == NULL |
3031 | && ecs->sal.line == 0) | |
1b2bfbb9 | 3032 | { |
527159b7 | 3033 | if (debug_infrun) |
8a9de0e4 | 3034 | fprintf_unfiltered (gdb_stdlog, "infrun: stepped into undebuggable function\n"); |
527159b7 | 3035 | |
1b2bfbb9 | 3036 | /* The inferior just stepped into, or returned to, an |
7ed0fe66 DJ |
3037 | undebuggable function (where there is no debugging information |
3038 | and no line number corresponding to the address where the | |
1b2bfbb9 RC |
3039 | inferior stopped). Since we want to skip this kind of code, |
3040 | we keep going until the inferior returns from this | |
14e60db5 DJ |
3041 | function - unless the user has asked us not to (via |
3042 | set step-mode) or we no longer know how to get back | |
3043 | to the call site. */ | |
3044 | if (step_stop_if_no_debug | |
3045 | || !frame_id_p (frame_unwind_id (get_current_frame ()))) | |
1b2bfbb9 RC |
3046 | { |
3047 | /* If we have no line number and the step-stop-if-no-debug | |
3048 | is set, we stop the step so that the user has a chance to | |
3049 | switch in assembly mode. */ | |
3050 | stop_step = 1; | |
3051 | print_stop_reason (END_STEPPING_RANGE, 0); | |
3052 | stop_stepping (ecs); | |
3053 | return; | |
3054 | } | |
3055 | else | |
3056 | { | |
3057 | /* Set a breakpoint at callee's return address (the address | |
3058 | at which the caller will resume). */ | |
14e60db5 | 3059 | insert_step_resume_breakpoint_at_caller (get_current_frame ()); |
1b2bfbb9 RC |
3060 | keep_going (ecs); |
3061 | return; | |
3062 | } | |
3063 | } | |
3064 | ||
3065 | if (step_range_end == 1) | |
3066 | { | |
3067 | /* It is stepi or nexti. We always want to stop stepping after | |
3068 | one instruction. */ | |
527159b7 | 3069 | if (debug_infrun) |
8a9de0e4 | 3070 | fprintf_unfiltered (gdb_stdlog, "infrun: stepi/nexti\n"); |
1b2bfbb9 RC |
3071 | stop_step = 1; |
3072 | print_stop_reason (END_STEPPING_RANGE, 0); | |
3073 | stop_stepping (ecs); | |
3074 | return; | |
3075 | } | |
3076 | ||
488f131b JB |
3077 | if (ecs->sal.line == 0) |
3078 | { | |
3079 | /* We have no line number information. That means to stop | |
3080 | stepping (does this always happen right after one instruction, | |
3081 | when we do "s" in a function with no line numbers, | |
3082 | or can this happen as a result of a return or longjmp?). */ | |
527159b7 | 3083 | if (debug_infrun) |
8a9de0e4 | 3084 | fprintf_unfiltered (gdb_stdlog, "infrun: no line number info\n"); |
488f131b JB |
3085 | stop_step = 1; |
3086 | print_stop_reason (END_STEPPING_RANGE, 0); | |
3087 | stop_stepping (ecs); | |
3088 | return; | |
3089 | } | |
c906108c | 3090 | |
488f131b JB |
3091 | if ((stop_pc == ecs->sal.pc) |
3092 | && (ecs->current_line != ecs->sal.line | |
3093 | || ecs->current_symtab != ecs->sal.symtab)) | |
3094 | { | |
3095 | /* We are at the start of a different line. So stop. Note that | |
3096 | we don't stop if we step into the middle of a different line. | |
3097 | That is said to make things like for (;;) statements work | |
3098 | better. */ | |
527159b7 | 3099 | if (debug_infrun) |
8a9de0e4 | 3100 | fprintf_unfiltered (gdb_stdlog, "infrun: stepped to a different line\n"); |
488f131b JB |
3101 | stop_step = 1; |
3102 | print_stop_reason (END_STEPPING_RANGE, 0); | |
3103 | stop_stepping (ecs); | |
3104 | return; | |
3105 | } | |
c906108c | 3106 | |
488f131b | 3107 | /* We aren't done stepping. |
c906108c | 3108 | |
488f131b JB |
3109 | Optimize by setting the stepping range to the line. |
3110 | (We might not be in the original line, but if we entered a | |
3111 | new line in mid-statement, we continue stepping. This makes | |
3112 | things like for(;;) statements work better.) */ | |
c906108c | 3113 | |
488f131b JB |
3114 | step_range_start = ecs->sal.pc; |
3115 | step_range_end = ecs->sal.end; | |
aa0cd9c1 | 3116 | step_frame_id = get_frame_id (get_current_frame ()); |
488f131b JB |
3117 | ecs->current_line = ecs->sal.line; |
3118 | ecs->current_symtab = ecs->sal.symtab; | |
3119 | ||
aa0cd9c1 AC |
3120 | /* In the case where we just stepped out of a function into the |
3121 | middle of a line of the caller, continue stepping, but | |
3122 | step_frame_id must be modified to current frame */ | |
65815ea1 AC |
3123 | #if 0 |
3124 | /* NOTE: cagney/2003-10-16: I think this frame ID inner test is too | |
3125 | generous. It will trigger on things like a step into a frameless | |
3126 | stackless leaf function. I think the logic should instead look | |
3127 | at the unwound frame ID has that should give a more robust | |
3128 | indication of what happened. */ | |
8fb3e588 AC |
3129 | if (step - ID == current - ID) |
3130 | still stepping in same function; | |
3131 | else if (step - ID == unwind (current - ID)) | |
3132 | stepped into a function; | |
3133 | else | |
3134 | stepped out of a function; | |
3135 | /* Of course this assumes that the frame ID unwind code is robust | |
3136 | and we're willing to introduce frame unwind logic into this | |
3137 | function. Fortunately, those days are nearly upon us. */ | |
65815ea1 | 3138 | #endif |
488f131b | 3139 | { |
09a7aba8 UW |
3140 | struct frame_info *frame = get_current_frame (); |
3141 | struct frame_id current_frame = get_frame_id (frame); | |
3142 | if (!(frame_id_inner (get_frame_arch (frame), current_frame, | |
3143 | step_frame_id))) | |
aa0cd9c1 | 3144 | step_frame_id = current_frame; |
488f131b | 3145 | } |
c906108c | 3146 | |
527159b7 | 3147 | if (debug_infrun) |
8a9de0e4 | 3148 | fprintf_unfiltered (gdb_stdlog, "infrun: keep going\n"); |
488f131b | 3149 | keep_going (ecs); |
104c1213 JM |
3150 | } |
3151 | ||
3152 | /* Are we in the middle of stepping? */ | |
3153 | ||
3154 | static int | |
3155 | currently_stepping (struct execution_control_state *ecs) | |
3156 | { | |
d303a6c7 | 3157 | return ((!ecs->handling_longjmp |
104c1213 | 3158 | && ((step_range_end && step_resume_breakpoint == NULL) |
ca67fcb8 | 3159 | || stepping_over_breakpoint)) |
104c1213 JM |
3160 | || ecs->stepping_through_solib_after_catch |
3161 | || bpstat_should_step ()); | |
3162 | } | |
c906108c | 3163 | |
c2c6d25f JM |
3164 | /* Subroutine call with source code we should not step over. Do step |
3165 | to the first line of code in it. */ | |
3166 | ||
3167 | static void | |
3168 | step_into_function (struct execution_control_state *ecs) | |
3169 | { | |
3170 | struct symtab *s; | |
3171 | struct symtab_and_line sr_sal; | |
3172 | ||
3173 | s = find_pc_symtab (stop_pc); | |
3174 | if (s && s->language != language_asm) | |
a433963d UW |
3175 | ecs->stop_func_start = gdbarch_skip_prologue |
3176 | (current_gdbarch, ecs->stop_func_start); | |
c2c6d25f JM |
3177 | |
3178 | ecs->sal = find_pc_line (ecs->stop_func_start, 0); | |
3179 | /* Use the step_resume_break to step until the end of the prologue, | |
3180 | even if that involves jumps (as it seems to on the vax under | |
3181 | 4.2). */ | |
3182 | /* If the prologue ends in the middle of a source line, continue to | |
3183 | the end of that source line (if it is still within the function). | |
3184 | Otherwise, just go to end of prologue. */ | |
c2c6d25f JM |
3185 | if (ecs->sal.end |
3186 | && ecs->sal.pc != ecs->stop_func_start | |
3187 | && ecs->sal.end < ecs->stop_func_end) | |
3188 | ecs->stop_func_start = ecs->sal.end; | |
c2c6d25f | 3189 | |
2dbd5e30 KB |
3190 | /* Architectures which require breakpoint adjustment might not be able |
3191 | to place a breakpoint at the computed address. If so, the test | |
3192 | ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust | |
3193 | ecs->stop_func_start to an address at which a breakpoint may be | |
3194 | legitimately placed. | |
8fb3e588 | 3195 | |
2dbd5e30 KB |
3196 | Note: kevinb/2004-01-19: On FR-V, if this adjustment is not |
3197 | made, GDB will enter an infinite loop when stepping through | |
3198 | optimized code consisting of VLIW instructions which contain | |
3199 | subinstructions corresponding to different source lines. On | |
3200 | FR-V, it's not permitted to place a breakpoint on any but the | |
3201 | first subinstruction of a VLIW instruction. When a breakpoint is | |
3202 | set, GDB will adjust the breakpoint address to the beginning of | |
3203 | the VLIW instruction. Thus, we need to make the corresponding | |
3204 | adjustment here when computing the stop address. */ | |
8fb3e588 | 3205 | |
2dbd5e30 KB |
3206 | if (gdbarch_adjust_breakpoint_address_p (current_gdbarch)) |
3207 | { | |
3208 | ecs->stop_func_start | |
3209 | = gdbarch_adjust_breakpoint_address (current_gdbarch, | |
8fb3e588 | 3210 | ecs->stop_func_start); |
2dbd5e30 KB |
3211 | } |
3212 | ||
c2c6d25f JM |
3213 | if (ecs->stop_func_start == stop_pc) |
3214 | { | |
3215 | /* We are already there: stop now. */ | |
3216 | stop_step = 1; | |
488f131b | 3217 | print_stop_reason (END_STEPPING_RANGE, 0); |
c2c6d25f JM |
3218 | stop_stepping (ecs); |
3219 | return; | |
3220 | } | |
3221 | else | |
3222 | { | |
3223 | /* Put the step-breakpoint there and go until there. */ | |
fe39c653 | 3224 | init_sal (&sr_sal); /* initialize to zeroes */ |
c2c6d25f JM |
3225 | sr_sal.pc = ecs->stop_func_start; |
3226 | sr_sal.section = find_pc_overlay (ecs->stop_func_start); | |
44cbf7b5 | 3227 | |
c2c6d25f | 3228 | /* Do not specify what the fp should be when we stop since on |
488f131b JB |
3229 | some machines the prologue is where the new fp value is |
3230 | established. */ | |
44cbf7b5 | 3231 | insert_step_resume_breakpoint_at_sal (sr_sal, null_frame_id); |
c2c6d25f JM |
3232 | |
3233 | /* And make sure stepping stops right away then. */ | |
3234 | step_range_end = step_range_start; | |
3235 | } | |
3236 | keep_going (ecs); | |
3237 | } | |
d4f3574e | 3238 | |
d3169d93 | 3239 | /* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID. |
44cbf7b5 AC |
3240 | This is used to both functions and to skip over code. */ |
3241 | ||
3242 | static void | |
3243 | insert_step_resume_breakpoint_at_sal (struct symtab_and_line sr_sal, | |
3244 | struct frame_id sr_id) | |
3245 | { | |
3246 | /* There should never be more than one step-resume breakpoint per | |
3247 | thread, so we should never be setting a new | |
3248 | step_resume_breakpoint when one is already active. */ | |
3249 | gdb_assert (step_resume_breakpoint == NULL); | |
d3169d93 DJ |
3250 | |
3251 | if (debug_infrun) | |
3252 | fprintf_unfiltered (gdb_stdlog, | |
3253 | "infrun: inserting step-resume breakpoint at 0x%s\n", | |
3254 | paddr_nz (sr_sal.pc)); | |
3255 | ||
44cbf7b5 AC |
3256 | step_resume_breakpoint = set_momentary_breakpoint (sr_sal, sr_id, |
3257 | bp_step_resume); | |
44cbf7b5 | 3258 | } |
7ce450bd | 3259 | |
d3169d93 | 3260 | /* Insert a "step-resume breakpoint" at RETURN_FRAME.pc. This is used |
14e60db5 | 3261 | to skip a potential signal handler. |
7ce450bd | 3262 | |
14e60db5 DJ |
3263 | This is called with the interrupted function's frame. The signal |
3264 | handler, when it returns, will resume the interrupted function at | |
3265 | RETURN_FRAME.pc. */ | |
d303a6c7 AC |
3266 | |
3267 | static void | |
44cbf7b5 | 3268 | insert_step_resume_breakpoint_at_frame (struct frame_info *return_frame) |
d303a6c7 AC |
3269 | { |
3270 | struct symtab_and_line sr_sal; | |
3271 | ||
f4c1edd8 | 3272 | gdb_assert (return_frame != NULL); |
d303a6c7 AC |
3273 | init_sal (&sr_sal); /* initialize to zeros */ |
3274 | ||
bf6ae464 UW |
3275 | sr_sal.pc = gdbarch_addr_bits_remove |
3276 | (current_gdbarch, get_frame_pc (return_frame)); | |
d303a6c7 AC |
3277 | sr_sal.section = find_pc_overlay (sr_sal.pc); |
3278 | ||
44cbf7b5 | 3279 | insert_step_resume_breakpoint_at_sal (sr_sal, get_frame_id (return_frame)); |
d303a6c7 AC |
3280 | } |
3281 | ||
14e60db5 DJ |
3282 | /* Similar to insert_step_resume_breakpoint_at_frame, except |
3283 | but a breakpoint at the previous frame's PC. This is used to | |
3284 | skip a function after stepping into it (for "next" or if the called | |
3285 | function has no debugging information). | |
3286 | ||
3287 | The current function has almost always been reached by single | |
3288 | stepping a call or return instruction. NEXT_FRAME belongs to the | |
3289 | current function, and the breakpoint will be set at the caller's | |
3290 | resume address. | |
3291 | ||
3292 | This is a separate function rather than reusing | |
3293 | insert_step_resume_breakpoint_at_frame in order to avoid | |
3294 | get_prev_frame, which may stop prematurely (see the implementation | |
3295 | of frame_unwind_id for an example). */ | |
3296 | ||
3297 | static void | |
3298 | insert_step_resume_breakpoint_at_caller (struct frame_info *next_frame) | |
3299 | { | |
3300 | struct symtab_and_line sr_sal; | |
3301 | ||
3302 | /* We shouldn't have gotten here if we don't know where the call site | |
3303 | is. */ | |
3304 | gdb_assert (frame_id_p (frame_unwind_id (next_frame))); | |
3305 | ||
3306 | init_sal (&sr_sal); /* initialize to zeros */ | |
3307 | ||
bf6ae464 UW |
3308 | sr_sal.pc = gdbarch_addr_bits_remove |
3309 | (current_gdbarch, frame_pc_unwind (next_frame)); | |
14e60db5 DJ |
3310 | sr_sal.section = find_pc_overlay (sr_sal.pc); |
3311 | ||
3312 | insert_step_resume_breakpoint_at_sal (sr_sal, frame_unwind_id (next_frame)); | |
3313 | } | |
3314 | ||
104c1213 JM |
3315 | static void |
3316 | stop_stepping (struct execution_control_state *ecs) | |
3317 | { | |
527159b7 | 3318 | if (debug_infrun) |
8a9de0e4 | 3319 | fprintf_unfiltered (gdb_stdlog, "infrun: stop_stepping\n"); |
527159b7 | 3320 | |
cd0fc7c3 SS |
3321 | /* Let callers know we don't want to wait for the inferior anymore. */ |
3322 | ecs->wait_some_more = 0; | |
3323 | } | |
3324 | ||
d4f3574e SS |
3325 | /* This function handles various cases where we need to continue |
3326 | waiting for the inferior. */ | |
3327 | /* (Used to be the keep_going: label in the old wait_for_inferior) */ | |
3328 | ||
3329 | static void | |
3330 | keep_going (struct execution_control_state *ecs) | |
3331 | { | |
d4f3574e | 3332 | /* Save the pc before execution, to compare with pc after stop. */ |
488f131b | 3333 | prev_pc = read_pc (); /* Might have been DECR_AFTER_BREAK */ |
d4f3574e | 3334 | |
d4f3574e SS |
3335 | /* If we did not do break;, it means we should keep running the |
3336 | inferior and not return to debugger. */ | |
3337 | ||
ca67fcb8 | 3338 | if (stepping_over_breakpoint && stop_signal != TARGET_SIGNAL_TRAP) |
d4f3574e SS |
3339 | { |
3340 | /* We took a signal (which we are supposed to pass through to | |
488f131b JB |
3341 | the inferior, else we'd have done a break above) and we |
3342 | haven't yet gotten our trap. Simply continue. */ | |
d4f3574e SS |
3343 | resume (currently_stepping (ecs), stop_signal); |
3344 | } | |
3345 | else | |
3346 | { | |
3347 | /* Either the trap was not expected, but we are continuing | |
488f131b JB |
3348 | anyway (the user asked that this signal be passed to the |
3349 | child) | |
3350 | -- or -- | |
3351 | The signal was SIGTRAP, e.g. it was our signal, but we | |
3352 | decided we should resume from it. | |
d4f3574e | 3353 | |
c36b740a | 3354 | We're going to run this baby now! |
d4f3574e | 3355 | |
c36b740a VP |
3356 | Note that insert_breakpoints won't try to re-insert |
3357 | already inserted breakpoints. Therefore, we don't | |
3358 | care if breakpoints were already inserted, or not. */ | |
3359 | ||
45e8c884 VP |
3360 | if (ecs->stepping_over_breakpoint) |
3361 | { | |
237fc4c9 PA |
3362 | if (! use_displaced_stepping (current_gdbarch)) |
3363 | /* Since we can't do a displaced step, we have to remove | |
3364 | the breakpoint while we step it. To keep things | |
3365 | simple, we remove them all. */ | |
3366 | remove_breakpoints (); | |
45e8c884 VP |
3367 | } |
3368 | else | |
d4f3574e | 3369 | { |
e236ba44 | 3370 | struct gdb_exception e; |
569631c6 UW |
3371 | /* Stop stepping when inserting breakpoints |
3372 | has failed. */ | |
e236ba44 VP |
3373 | TRY_CATCH (e, RETURN_MASK_ERROR) |
3374 | { | |
3375 | insert_breakpoints (); | |
3376 | } | |
3377 | if (e.reason < 0) | |
d4f3574e SS |
3378 | { |
3379 | stop_stepping (ecs); | |
3380 | return; | |
3381 | } | |
d4f3574e SS |
3382 | } |
3383 | ||
ca67fcb8 | 3384 | stepping_over_breakpoint = ecs->stepping_over_breakpoint; |
d4f3574e SS |
3385 | |
3386 | /* Do not deliver SIGNAL_TRAP (except when the user explicitly | |
488f131b JB |
3387 | specifies that such a signal should be delivered to the |
3388 | target program). | |
3389 | ||
3390 | Typically, this would occure when a user is debugging a | |
3391 | target monitor on a simulator: the target monitor sets a | |
3392 | breakpoint; the simulator encounters this break-point and | |
3393 | halts the simulation handing control to GDB; GDB, noteing | |
3394 | that the break-point isn't valid, returns control back to the | |
3395 | simulator; the simulator then delivers the hardware | |
3396 | equivalent of a SIGNAL_TRAP to the program being debugged. */ | |
3397 | ||
3398 | if (stop_signal == TARGET_SIGNAL_TRAP && !signal_program[stop_signal]) | |
d4f3574e SS |
3399 | stop_signal = TARGET_SIGNAL_0; |
3400 | ||
d4f3574e SS |
3401 | |
3402 | resume (currently_stepping (ecs), stop_signal); | |
3403 | } | |
3404 | ||
488f131b | 3405 | prepare_to_wait (ecs); |
d4f3574e SS |
3406 | } |
3407 | ||
104c1213 JM |
3408 | /* This function normally comes after a resume, before |
3409 | handle_inferior_event exits. It takes care of any last bits of | |
3410 | housekeeping, and sets the all-important wait_some_more flag. */ | |
cd0fc7c3 | 3411 | |
104c1213 JM |
3412 | static void |
3413 | prepare_to_wait (struct execution_control_state *ecs) | |
cd0fc7c3 | 3414 | { |
527159b7 | 3415 | if (debug_infrun) |
8a9de0e4 | 3416 | fprintf_unfiltered (gdb_stdlog, "infrun: prepare_to_wait\n"); |
104c1213 JM |
3417 | if (ecs->infwait_state == infwait_normal_state) |
3418 | { | |
3419 | overlay_cache_invalid = 1; | |
3420 | ||
3421 | /* We have to invalidate the registers BEFORE calling | |
488f131b JB |
3422 | target_wait because they can be loaded from the target while |
3423 | in target_wait. This makes remote debugging a bit more | |
3424 | efficient for those targets that provide critical registers | |
3425 | as part of their normal status mechanism. */ | |
104c1213 JM |
3426 | |
3427 | registers_changed (); | |
39f77062 | 3428 | ecs->waiton_ptid = pid_to_ptid (-1); |
104c1213 JM |
3429 | ecs->wp = &(ecs->ws); |
3430 | } | |
3431 | /* This is the old end of the while loop. Let everybody know we | |
3432 | want to wait for the inferior some more and get called again | |
3433 | soon. */ | |
3434 | ecs->wait_some_more = 1; | |
c906108c | 3435 | } |
11cf8741 JM |
3436 | |
3437 | /* Print why the inferior has stopped. We always print something when | |
3438 | the inferior exits, or receives a signal. The rest of the cases are | |
3439 | dealt with later on in normal_stop() and print_it_typical(). Ideally | |
3440 | there should be a call to this function from handle_inferior_event() | |
3441 | each time stop_stepping() is called.*/ | |
3442 | static void | |
3443 | print_stop_reason (enum inferior_stop_reason stop_reason, int stop_info) | |
3444 | { | |
3445 | switch (stop_reason) | |
3446 | { | |
11cf8741 JM |
3447 | case END_STEPPING_RANGE: |
3448 | /* We are done with a step/next/si/ni command. */ | |
3449 | /* For now print nothing. */ | |
fb40c209 | 3450 | /* Print a message only if not in the middle of doing a "step n" |
488f131b | 3451 | operation for n > 1 */ |
fb40c209 | 3452 | if (!step_multi || !stop_step) |
9dc5e2a9 | 3453 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3454 | ui_out_field_string |
3455 | (uiout, "reason", | |
3456 | async_reason_lookup (EXEC_ASYNC_END_STEPPING_RANGE)); | |
11cf8741 | 3457 | break; |
11cf8741 JM |
3458 | case SIGNAL_EXITED: |
3459 | /* The inferior was terminated by a signal. */ | |
8b93c638 | 3460 | annotate_signalled (); |
9dc5e2a9 | 3461 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3462 | ui_out_field_string |
3463 | (uiout, "reason", | |
3464 | async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED)); | |
8b93c638 JM |
3465 | ui_out_text (uiout, "\nProgram terminated with signal "); |
3466 | annotate_signal_name (); | |
488f131b JB |
3467 | ui_out_field_string (uiout, "signal-name", |
3468 | target_signal_to_name (stop_info)); | |
8b93c638 JM |
3469 | annotate_signal_name_end (); |
3470 | ui_out_text (uiout, ", "); | |
3471 | annotate_signal_string (); | |
488f131b JB |
3472 | ui_out_field_string (uiout, "signal-meaning", |
3473 | target_signal_to_string (stop_info)); | |
8b93c638 JM |
3474 | annotate_signal_string_end (); |
3475 | ui_out_text (uiout, ".\n"); | |
3476 | ui_out_text (uiout, "The program no longer exists.\n"); | |
11cf8741 JM |
3477 | break; |
3478 | case EXITED: | |
3479 | /* The inferior program is finished. */ | |
8b93c638 JM |
3480 | annotate_exited (stop_info); |
3481 | if (stop_info) | |
3482 | { | |
9dc5e2a9 | 3483 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3484 | ui_out_field_string (uiout, "reason", |
3485 | async_reason_lookup (EXEC_ASYNC_EXITED)); | |
8b93c638 | 3486 | ui_out_text (uiout, "\nProgram exited with code "); |
488f131b JB |
3487 | ui_out_field_fmt (uiout, "exit-code", "0%o", |
3488 | (unsigned int) stop_info); | |
8b93c638 JM |
3489 | ui_out_text (uiout, ".\n"); |
3490 | } | |
3491 | else | |
3492 | { | |
9dc5e2a9 | 3493 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3494 | ui_out_field_string |
3495 | (uiout, "reason", | |
3496 | async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY)); | |
8b93c638 JM |
3497 | ui_out_text (uiout, "\nProgram exited normally.\n"); |
3498 | } | |
f17517ea AS |
3499 | /* Support the --return-child-result option. */ |
3500 | return_child_result_value = stop_info; | |
11cf8741 JM |
3501 | break; |
3502 | case SIGNAL_RECEIVED: | |
3503 | /* Signal received. The signal table tells us to print about | |
3504 | it. */ | |
8b93c638 JM |
3505 | annotate_signal (); |
3506 | ui_out_text (uiout, "\nProgram received signal "); | |
3507 | annotate_signal_name (); | |
84c6c83c | 3508 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3509 | ui_out_field_string |
3510 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED)); | |
488f131b JB |
3511 | ui_out_field_string (uiout, "signal-name", |
3512 | target_signal_to_name (stop_info)); | |
8b93c638 JM |
3513 | annotate_signal_name_end (); |
3514 | ui_out_text (uiout, ", "); | |
3515 | annotate_signal_string (); | |
488f131b JB |
3516 | ui_out_field_string (uiout, "signal-meaning", |
3517 | target_signal_to_string (stop_info)); | |
8b93c638 JM |
3518 | annotate_signal_string_end (); |
3519 | ui_out_text (uiout, ".\n"); | |
11cf8741 JM |
3520 | break; |
3521 | default: | |
8e65ff28 | 3522 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 3523 | _("print_stop_reason: unrecognized enum value")); |
11cf8741 JM |
3524 | break; |
3525 | } | |
3526 | } | |
c906108c | 3527 | \f |
43ff13b4 | 3528 | |
c906108c SS |
3529 | /* Here to return control to GDB when the inferior stops for real. |
3530 | Print appropriate messages, remove breakpoints, give terminal our modes. | |
3531 | ||
3532 | STOP_PRINT_FRAME nonzero means print the executing frame | |
3533 | (pc, function, args, file, line number and line text). | |
3534 | BREAKPOINTS_FAILED nonzero means stop was due to error | |
3535 | attempting to insert breakpoints. */ | |
3536 | ||
3537 | void | |
96baa820 | 3538 | normal_stop (void) |
c906108c | 3539 | { |
73b65bb0 DJ |
3540 | struct target_waitstatus last; |
3541 | ptid_t last_ptid; | |
3542 | ||
3543 | get_last_target_status (&last_ptid, &last); | |
3544 | ||
c906108c SS |
3545 | /* As with the notification of thread events, we want to delay |
3546 | notifying the user that we've switched thread context until | |
3547 | the inferior actually stops. | |
3548 | ||
73b65bb0 DJ |
3549 | There's no point in saying anything if the inferior has exited. |
3550 | Note that SIGNALLED here means "exited with a signal", not | |
3551 | "received a signal". */ | |
488f131b | 3552 | if (!ptid_equal (previous_inferior_ptid, inferior_ptid) |
73b65bb0 DJ |
3553 | && target_has_execution |
3554 | && last.kind != TARGET_WAITKIND_SIGNALLED | |
3555 | && last.kind != TARGET_WAITKIND_EXITED) | |
c906108c SS |
3556 | { |
3557 | target_terminal_ours_for_output (); | |
a3f17187 | 3558 | printf_filtered (_("[Switching to %s]\n"), |
c95310c6 | 3559 | target_pid_to_str (inferior_ptid)); |
39f77062 | 3560 | previous_inferior_ptid = inferior_ptid; |
c906108c | 3561 | } |
c906108c | 3562 | |
4fa8626c | 3563 | /* NOTE drow/2004-01-17: Is this still necessary? */ |
c906108c SS |
3564 | /* Make sure that the current_frame's pc is correct. This |
3565 | is a correction for setting up the frame info before doing | |
b798847d | 3566 | gdbarch_decr_pc_after_break */ |
b87efeee AC |
3567 | if (target_has_execution) |
3568 | /* FIXME: cagney/2002-12-06: Has the PC changed? Thanks to | |
b798847d | 3569 | gdbarch_decr_pc_after_break, the program counter can change. Ask the |
b87efeee | 3570 | frame code to check for this and sort out any resultant mess. |
b798847d | 3571 | gdbarch_decr_pc_after_break needs to just go away. */ |
2f107107 | 3572 | deprecated_update_frame_pc_hack (get_current_frame (), read_pc ()); |
c906108c | 3573 | |
74960c60 | 3574 | if (!breakpoints_always_inserted_mode () && target_has_execution) |
c906108c SS |
3575 | { |
3576 | if (remove_breakpoints ()) | |
3577 | { | |
3578 | target_terminal_ours_for_output (); | |
a3f17187 AC |
3579 | printf_filtered (_("\ |
3580 | Cannot remove breakpoints because program is no longer writable.\n\ | |
3581 | It might be running in another process.\n\ | |
3582 | Further execution is probably impossible.\n")); | |
c906108c SS |
3583 | } |
3584 | } | |
c906108c | 3585 | |
c906108c SS |
3586 | /* If an auto-display called a function and that got a signal, |
3587 | delete that auto-display to avoid an infinite recursion. */ | |
3588 | ||
3589 | if (stopped_by_random_signal) | |
3590 | disable_current_display (); | |
3591 | ||
3592 | /* Don't print a message if in the middle of doing a "step n" | |
3593 | operation for n > 1 */ | |
3594 | if (step_multi && stop_step) | |
3595 | goto done; | |
3596 | ||
3597 | target_terminal_ours (); | |
3598 | ||
7abfe014 DJ |
3599 | /* Set the current source location. This will also happen if we |
3600 | display the frame below, but the current SAL will be incorrect | |
3601 | during a user hook-stop function. */ | |
3602 | if (target_has_stack && !stop_stack_dummy) | |
3603 | set_current_sal_from_frame (get_current_frame (), 1); | |
3604 | ||
5913bcb0 AC |
3605 | /* Look up the hook_stop and run it (CLI internally handles problem |
3606 | of stop_command's pre-hook not existing). */ | |
3607 | if (stop_command) | |
3608 | catch_errors (hook_stop_stub, stop_command, | |
3609 | "Error while running hook_stop:\n", RETURN_MASK_ALL); | |
c906108c SS |
3610 | |
3611 | if (!target_has_stack) | |
3612 | { | |
3613 | ||
3614 | goto done; | |
3615 | } | |
3616 | ||
3617 | /* Select innermost stack frame - i.e., current frame is frame 0, | |
3618 | and current location is based on that. | |
3619 | Don't do this on return from a stack dummy routine, | |
3620 | or if the program has exited. */ | |
3621 | ||
3622 | if (!stop_stack_dummy) | |
3623 | { | |
0f7d239c | 3624 | select_frame (get_current_frame ()); |
c906108c SS |
3625 | |
3626 | /* Print current location without a level number, if | |
c5aa993b JM |
3627 | we have changed functions or hit a breakpoint. |
3628 | Print source line if we have one. | |
3629 | bpstat_print() contains the logic deciding in detail | |
3630 | what to print, based on the event(s) that just occurred. */ | |
c906108c | 3631 | |
d01a8610 AS |
3632 | /* If --batch-silent is enabled then there's no need to print the current |
3633 | source location, and to try risks causing an error message about | |
3634 | missing source files. */ | |
3635 | if (stop_print_frame && !batch_silent) | |
c906108c SS |
3636 | { |
3637 | int bpstat_ret; | |
3638 | int source_flag; | |
917317f4 | 3639 | int do_frame_printing = 1; |
c906108c SS |
3640 | |
3641 | bpstat_ret = bpstat_print (stop_bpstat); | |
917317f4 JM |
3642 | switch (bpstat_ret) |
3643 | { | |
3644 | case PRINT_UNKNOWN: | |
b0f4b84b DJ |
3645 | /* If we had hit a shared library event breakpoint, |
3646 | bpstat_print would print out this message. If we hit | |
3647 | an OS-level shared library event, do the same | |
3648 | thing. */ | |
3649 | if (last.kind == TARGET_WAITKIND_LOADED) | |
3650 | { | |
3651 | printf_filtered (_("Stopped due to shared library event\n")); | |
3652 | source_flag = SRC_LINE; /* something bogus */ | |
3653 | do_frame_printing = 0; | |
3654 | break; | |
3655 | } | |
3656 | ||
aa0cd9c1 | 3657 | /* FIXME: cagney/2002-12-01: Given that a frame ID does |
8fb3e588 AC |
3658 | (or should) carry around the function and does (or |
3659 | should) use that when doing a frame comparison. */ | |
917317f4 | 3660 | if (stop_step |
aa0cd9c1 AC |
3661 | && frame_id_eq (step_frame_id, |
3662 | get_frame_id (get_current_frame ())) | |
917317f4 | 3663 | && step_start_function == find_pc_function (stop_pc)) |
488f131b | 3664 | source_flag = SRC_LINE; /* finished step, just print source line */ |
917317f4 | 3665 | else |
488f131b | 3666 | source_flag = SRC_AND_LOC; /* print location and source line */ |
917317f4 JM |
3667 | break; |
3668 | case PRINT_SRC_AND_LOC: | |
488f131b | 3669 | source_flag = SRC_AND_LOC; /* print location and source line */ |
917317f4 JM |
3670 | break; |
3671 | case PRINT_SRC_ONLY: | |
c5394b80 | 3672 | source_flag = SRC_LINE; |
917317f4 JM |
3673 | break; |
3674 | case PRINT_NOTHING: | |
488f131b | 3675 | source_flag = SRC_LINE; /* something bogus */ |
917317f4 JM |
3676 | do_frame_printing = 0; |
3677 | break; | |
3678 | default: | |
e2e0b3e5 | 3679 | internal_error (__FILE__, __LINE__, _("Unknown value.")); |
917317f4 | 3680 | } |
c906108c | 3681 | |
9dc5e2a9 | 3682 | if (ui_out_is_mi_like_p (uiout)) |
39f77062 | 3683 | ui_out_field_int (uiout, "thread-id", |
488f131b | 3684 | pid_to_thread_id (inferior_ptid)); |
c906108c SS |
3685 | /* The behavior of this routine with respect to the source |
3686 | flag is: | |
c5394b80 JM |
3687 | SRC_LINE: Print only source line |
3688 | LOCATION: Print only location | |
3689 | SRC_AND_LOC: Print location and source line */ | |
917317f4 | 3690 | if (do_frame_printing) |
b04f3ab4 | 3691 | print_stack_frame (get_selected_frame (NULL), 0, source_flag); |
c906108c SS |
3692 | |
3693 | /* Display the auto-display expressions. */ | |
3694 | do_displays (); | |
3695 | } | |
3696 | } | |
3697 | ||
3698 | /* Save the function value return registers, if we care. | |
3699 | We might be about to restore their previous contents. */ | |
3700 | if (proceed_to_finish) | |
d5c31457 UW |
3701 | { |
3702 | /* This should not be necessary. */ | |
3703 | if (stop_registers) | |
3704 | regcache_xfree (stop_registers); | |
3705 | ||
3706 | /* NB: The copy goes through to the target picking up the value of | |
3707 | all the registers. */ | |
3708 | stop_registers = regcache_dup (get_current_regcache ()); | |
3709 | } | |
c906108c SS |
3710 | |
3711 | if (stop_stack_dummy) | |
3712 | { | |
dbe9fe58 AC |
3713 | /* Pop the empty frame that contains the stack dummy. POP_FRAME |
3714 | ends with a setting of the current frame, so we can use that | |
3715 | next. */ | |
3716 | frame_pop (get_current_frame ()); | |
c906108c | 3717 | /* Set stop_pc to what it was before we called the function. |
c5aa993b JM |
3718 | Can't rely on restore_inferior_status because that only gets |
3719 | called if we don't stop in the called function. */ | |
c906108c | 3720 | stop_pc = read_pc (); |
0f7d239c | 3721 | select_frame (get_current_frame ()); |
c906108c SS |
3722 | } |
3723 | ||
c906108c SS |
3724 | done: |
3725 | annotate_stopped (); | |
7a464420 | 3726 | observer_notify_normal_stop (stop_bpstat); |
2cec12e5 AR |
3727 | /* Delete the breakpoint we stopped at, if it wants to be deleted. |
3728 | Delete any breakpoint that is to be deleted at the next stop. */ | |
3729 | breakpoint_auto_delete (stop_bpstat); | |
c906108c SS |
3730 | } |
3731 | ||
3732 | static int | |
96baa820 | 3733 | hook_stop_stub (void *cmd) |
c906108c | 3734 | { |
5913bcb0 | 3735 | execute_cmd_pre_hook ((struct cmd_list_element *) cmd); |
c906108c SS |
3736 | return (0); |
3737 | } | |
3738 | \f | |
c5aa993b | 3739 | int |
96baa820 | 3740 | signal_stop_state (int signo) |
c906108c | 3741 | { |
a0ef4274 DJ |
3742 | /* Always stop on signals if we're just gaining control of the |
3743 | program. */ | |
3744 | return signal_stop[signo] || stop_soon != NO_STOP_QUIETLY; | |
c906108c SS |
3745 | } |
3746 | ||
c5aa993b | 3747 | int |
96baa820 | 3748 | signal_print_state (int signo) |
c906108c SS |
3749 | { |
3750 | return signal_print[signo]; | |
3751 | } | |
3752 | ||
c5aa993b | 3753 | int |
96baa820 | 3754 | signal_pass_state (int signo) |
c906108c SS |
3755 | { |
3756 | return signal_program[signo]; | |
3757 | } | |
3758 | ||
488f131b | 3759 | int |
7bda5e4a | 3760 | signal_stop_update (int signo, int state) |
d4f3574e SS |
3761 | { |
3762 | int ret = signal_stop[signo]; | |
3763 | signal_stop[signo] = state; | |
3764 | return ret; | |
3765 | } | |
3766 | ||
488f131b | 3767 | int |
7bda5e4a | 3768 | signal_print_update (int signo, int state) |
d4f3574e SS |
3769 | { |
3770 | int ret = signal_print[signo]; | |
3771 | signal_print[signo] = state; | |
3772 | return ret; | |
3773 | } | |
3774 | ||
488f131b | 3775 | int |
7bda5e4a | 3776 | signal_pass_update (int signo, int state) |
d4f3574e SS |
3777 | { |
3778 | int ret = signal_program[signo]; | |
3779 | signal_program[signo] = state; | |
3780 | return ret; | |
3781 | } | |
3782 | ||
c906108c | 3783 | static void |
96baa820 | 3784 | sig_print_header (void) |
c906108c | 3785 | { |
a3f17187 AC |
3786 | printf_filtered (_("\ |
3787 | Signal Stop\tPrint\tPass to program\tDescription\n")); | |
c906108c SS |
3788 | } |
3789 | ||
3790 | static void | |
96baa820 | 3791 | sig_print_info (enum target_signal oursig) |
c906108c SS |
3792 | { |
3793 | char *name = target_signal_to_name (oursig); | |
3794 | int name_padding = 13 - strlen (name); | |
96baa820 | 3795 | |
c906108c SS |
3796 | if (name_padding <= 0) |
3797 | name_padding = 0; | |
3798 | ||
3799 | printf_filtered ("%s", name); | |
488f131b | 3800 | printf_filtered ("%*.*s ", name_padding, name_padding, " "); |
c906108c SS |
3801 | printf_filtered ("%s\t", signal_stop[oursig] ? "Yes" : "No"); |
3802 | printf_filtered ("%s\t", signal_print[oursig] ? "Yes" : "No"); | |
3803 | printf_filtered ("%s\t\t", signal_program[oursig] ? "Yes" : "No"); | |
3804 | printf_filtered ("%s\n", target_signal_to_string (oursig)); | |
3805 | } | |
3806 | ||
3807 | /* Specify how various signals in the inferior should be handled. */ | |
3808 | ||
3809 | static void | |
96baa820 | 3810 | handle_command (char *args, int from_tty) |
c906108c SS |
3811 | { |
3812 | char **argv; | |
3813 | int digits, wordlen; | |
3814 | int sigfirst, signum, siglast; | |
3815 | enum target_signal oursig; | |
3816 | int allsigs; | |
3817 | int nsigs; | |
3818 | unsigned char *sigs; | |
3819 | struct cleanup *old_chain; | |
3820 | ||
3821 | if (args == NULL) | |
3822 | { | |
e2e0b3e5 | 3823 | error_no_arg (_("signal to handle")); |
c906108c SS |
3824 | } |
3825 | ||
3826 | /* Allocate and zero an array of flags for which signals to handle. */ | |
3827 | ||
3828 | nsigs = (int) TARGET_SIGNAL_LAST; | |
3829 | sigs = (unsigned char *) alloca (nsigs); | |
3830 | memset (sigs, 0, nsigs); | |
3831 | ||
3832 | /* Break the command line up into args. */ | |
3833 | ||
3834 | argv = buildargv (args); | |
3835 | if (argv == NULL) | |
3836 | { | |
3837 | nomem (0); | |
3838 | } | |
7a292a7a | 3839 | old_chain = make_cleanup_freeargv (argv); |
c906108c SS |
3840 | |
3841 | /* Walk through the args, looking for signal oursigs, signal names, and | |
3842 | actions. Signal numbers and signal names may be interspersed with | |
3843 | actions, with the actions being performed for all signals cumulatively | |
3844 | specified. Signal ranges can be specified as <LOW>-<HIGH>. */ | |
3845 | ||
3846 | while (*argv != NULL) | |
3847 | { | |
3848 | wordlen = strlen (*argv); | |
3849 | for (digits = 0; isdigit ((*argv)[digits]); digits++) | |
3850 | {; | |
3851 | } | |
3852 | allsigs = 0; | |
3853 | sigfirst = siglast = -1; | |
3854 | ||
3855 | if (wordlen >= 1 && !strncmp (*argv, "all", wordlen)) | |
3856 | { | |
3857 | /* Apply action to all signals except those used by the | |
3858 | debugger. Silently skip those. */ | |
3859 | allsigs = 1; | |
3860 | sigfirst = 0; | |
3861 | siglast = nsigs - 1; | |
3862 | } | |
3863 | else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen)) | |
3864 | { | |
3865 | SET_SIGS (nsigs, sigs, signal_stop); | |
3866 | SET_SIGS (nsigs, sigs, signal_print); | |
3867 | } | |
3868 | else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen)) | |
3869 | { | |
3870 | UNSET_SIGS (nsigs, sigs, signal_program); | |
3871 | } | |
3872 | else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen)) | |
3873 | { | |
3874 | SET_SIGS (nsigs, sigs, signal_print); | |
3875 | } | |
3876 | else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen)) | |
3877 | { | |
3878 | SET_SIGS (nsigs, sigs, signal_program); | |
3879 | } | |
3880 | else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen)) | |
3881 | { | |
3882 | UNSET_SIGS (nsigs, sigs, signal_stop); | |
3883 | } | |
3884 | else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen)) | |
3885 | { | |
3886 | SET_SIGS (nsigs, sigs, signal_program); | |
3887 | } | |
3888 | else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen)) | |
3889 | { | |
3890 | UNSET_SIGS (nsigs, sigs, signal_print); | |
3891 | UNSET_SIGS (nsigs, sigs, signal_stop); | |
3892 | } | |
3893 | else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen)) | |
3894 | { | |
3895 | UNSET_SIGS (nsigs, sigs, signal_program); | |
3896 | } | |
3897 | else if (digits > 0) | |
3898 | { | |
3899 | /* It is numeric. The numeric signal refers to our own | |
3900 | internal signal numbering from target.h, not to host/target | |
3901 | signal number. This is a feature; users really should be | |
3902 | using symbolic names anyway, and the common ones like | |
3903 | SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */ | |
3904 | ||
3905 | sigfirst = siglast = (int) | |
3906 | target_signal_from_command (atoi (*argv)); | |
3907 | if ((*argv)[digits] == '-') | |
3908 | { | |
3909 | siglast = (int) | |
3910 | target_signal_from_command (atoi ((*argv) + digits + 1)); | |
3911 | } | |
3912 | if (sigfirst > siglast) | |
3913 | { | |
3914 | /* Bet he didn't figure we'd think of this case... */ | |
3915 | signum = sigfirst; | |
3916 | sigfirst = siglast; | |
3917 | siglast = signum; | |
3918 | } | |
3919 | } | |
3920 | else | |
3921 | { | |
3922 | oursig = target_signal_from_name (*argv); | |
3923 | if (oursig != TARGET_SIGNAL_UNKNOWN) | |
3924 | { | |
3925 | sigfirst = siglast = (int) oursig; | |
3926 | } | |
3927 | else | |
3928 | { | |
3929 | /* Not a number and not a recognized flag word => complain. */ | |
8a3fe4f8 | 3930 | error (_("Unrecognized or ambiguous flag word: \"%s\"."), *argv); |
c906108c SS |
3931 | } |
3932 | } | |
3933 | ||
3934 | /* If any signal numbers or symbol names were found, set flags for | |
c5aa993b | 3935 | which signals to apply actions to. */ |
c906108c SS |
3936 | |
3937 | for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++) | |
3938 | { | |
3939 | switch ((enum target_signal) signum) | |
3940 | { | |
3941 | case TARGET_SIGNAL_TRAP: | |
3942 | case TARGET_SIGNAL_INT: | |
3943 | if (!allsigs && !sigs[signum]) | |
3944 | { | |
3945 | if (query ("%s is used by the debugger.\n\ | |
488f131b | 3946 | Are you sure you want to change it? ", target_signal_to_name ((enum target_signal) signum))) |
c906108c SS |
3947 | { |
3948 | sigs[signum] = 1; | |
3949 | } | |
3950 | else | |
3951 | { | |
a3f17187 | 3952 | printf_unfiltered (_("Not confirmed, unchanged.\n")); |
c906108c SS |
3953 | gdb_flush (gdb_stdout); |
3954 | } | |
3955 | } | |
3956 | break; | |
3957 | case TARGET_SIGNAL_0: | |
3958 | case TARGET_SIGNAL_DEFAULT: | |
3959 | case TARGET_SIGNAL_UNKNOWN: | |
3960 | /* Make sure that "all" doesn't print these. */ | |
3961 | break; | |
3962 | default: | |
3963 | sigs[signum] = 1; | |
3964 | break; | |
3965 | } | |
3966 | } | |
3967 | ||
3968 | argv++; | |
3969 | } | |
3970 | ||
39f77062 | 3971 | target_notice_signals (inferior_ptid); |
c906108c SS |
3972 | |
3973 | if (from_tty) | |
3974 | { | |
3975 | /* Show the results. */ | |
3976 | sig_print_header (); | |
3977 | for (signum = 0; signum < nsigs; signum++) | |
3978 | { | |
3979 | if (sigs[signum]) | |
3980 | { | |
3981 | sig_print_info (signum); | |
3982 | } | |
3983 | } | |
3984 | } | |
3985 | ||
3986 | do_cleanups (old_chain); | |
3987 | } | |
3988 | ||
3989 | static void | |
96baa820 | 3990 | xdb_handle_command (char *args, int from_tty) |
c906108c SS |
3991 | { |
3992 | char **argv; | |
3993 | struct cleanup *old_chain; | |
3994 | ||
3995 | /* Break the command line up into args. */ | |
3996 | ||
3997 | argv = buildargv (args); | |
3998 | if (argv == NULL) | |
3999 | { | |
4000 | nomem (0); | |
4001 | } | |
7a292a7a | 4002 | old_chain = make_cleanup_freeargv (argv); |
c906108c SS |
4003 | if (argv[1] != (char *) NULL) |
4004 | { | |
4005 | char *argBuf; | |
4006 | int bufLen; | |
4007 | ||
4008 | bufLen = strlen (argv[0]) + 20; | |
4009 | argBuf = (char *) xmalloc (bufLen); | |
4010 | if (argBuf) | |
4011 | { | |
4012 | int validFlag = 1; | |
4013 | enum target_signal oursig; | |
4014 | ||
4015 | oursig = target_signal_from_name (argv[0]); | |
4016 | memset (argBuf, 0, bufLen); | |
4017 | if (strcmp (argv[1], "Q") == 0) | |
4018 | sprintf (argBuf, "%s %s", argv[0], "noprint"); | |
4019 | else | |
4020 | { | |
4021 | if (strcmp (argv[1], "s") == 0) | |
4022 | { | |
4023 | if (!signal_stop[oursig]) | |
4024 | sprintf (argBuf, "%s %s", argv[0], "stop"); | |
4025 | else | |
4026 | sprintf (argBuf, "%s %s", argv[0], "nostop"); | |
4027 | } | |
4028 | else if (strcmp (argv[1], "i") == 0) | |
4029 | { | |
4030 | if (!signal_program[oursig]) | |
4031 | sprintf (argBuf, "%s %s", argv[0], "pass"); | |
4032 | else | |
4033 | sprintf (argBuf, "%s %s", argv[0], "nopass"); | |
4034 | } | |
4035 | else if (strcmp (argv[1], "r") == 0) | |
4036 | { | |
4037 | if (!signal_print[oursig]) | |
4038 | sprintf (argBuf, "%s %s", argv[0], "print"); | |
4039 | else | |
4040 | sprintf (argBuf, "%s %s", argv[0], "noprint"); | |
4041 | } | |
4042 | else | |
4043 | validFlag = 0; | |
4044 | } | |
4045 | if (validFlag) | |
4046 | handle_command (argBuf, from_tty); | |
4047 | else | |
a3f17187 | 4048 | printf_filtered (_("Invalid signal handling flag.\n")); |
c906108c | 4049 | if (argBuf) |
b8c9b27d | 4050 | xfree (argBuf); |
c906108c SS |
4051 | } |
4052 | } | |
4053 | do_cleanups (old_chain); | |
4054 | } | |
4055 | ||
4056 | /* Print current contents of the tables set by the handle command. | |
4057 | It is possible we should just be printing signals actually used | |
4058 | by the current target (but for things to work right when switching | |
4059 | targets, all signals should be in the signal tables). */ | |
4060 | ||
4061 | static void | |
96baa820 | 4062 | signals_info (char *signum_exp, int from_tty) |
c906108c SS |
4063 | { |
4064 | enum target_signal oursig; | |
4065 | sig_print_header (); | |
4066 | ||
4067 | if (signum_exp) | |
4068 | { | |
4069 | /* First see if this is a symbol name. */ | |
4070 | oursig = target_signal_from_name (signum_exp); | |
4071 | if (oursig == TARGET_SIGNAL_UNKNOWN) | |
4072 | { | |
4073 | /* No, try numeric. */ | |
4074 | oursig = | |
bb518678 | 4075 | target_signal_from_command (parse_and_eval_long (signum_exp)); |
c906108c SS |
4076 | } |
4077 | sig_print_info (oursig); | |
4078 | return; | |
4079 | } | |
4080 | ||
4081 | printf_filtered ("\n"); | |
4082 | /* These ugly casts brought to you by the native VAX compiler. */ | |
4083 | for (oursig = TARGET_SIGNAL_FIRST; | |
4084 | (int) oursig < (int) TARGET_SIGNAL_LAST; | |
4085 | oursig = (enum target_signal) ((int) oursig + 1)) | |
4086 | { | |
4087 | QUIT; | |
4088 | ||
4089 | if (oursig != TARGET_SIGNAL_UNKNOWN | |
488f131b | 4090 | && oursig != TARGET_SIGNAL_DEFAULT && oursig != TARGET_SIGNAL_0) |
c906108c SS |
4091 | sig_print_info (oursig); |
4092 | } | |
4093 | ||
a3f17187 | 4094 | printf_filtered (_("\nUse the \"handle\" command to change these tables.\n")); |
c906108c SS |
4095 | } |
4096 | \f | |
7a292a7a SS |
4097 | struct inferior_status |
4098 | { | |
4099 | enum target_signal stop_signal; | |
4100 | CORE_ADDR stop_pc; | |
4101 | bpstat stop_bpstat; | |
4102 | int stop_step; | |
4103 | int stop_stack_dummy; | |
4104 | int stopped_by_random_signal; | |
ca67fcb8 | 4105 | int stepping_over_breakpoint; |
7a292a7a SS |
4106 | CORE_ADDR step_range_start; |
4107 | CORE_ADDR step_range_end; | |
aa0cd9c1 | 4108 | struct frame_id step_frame_id; |
5fbbeb29 | 4109 | enum step_over_calls_kind step_over_calls; |
7a292a7a SS |
4110 | CORE_ADDR step_resume_break_address; |
4111 | int stop_after_trap; | |
c0236d92 | 4112 | int stop_soon; |
7a292a7a SS |
4113 | |
4114 | /* These are here because if call_function_by_hand has written some | |
4115 | registers and then decides to call error(), we better not have changed | |
4116 | any registers. */ | |
72cec141 | 4117 | struct regcache *registers; |
7a292a7a | 4118 | |
101dcfbe AC |
4119 | /* A frame unique identifier. */ |
4120 | struct frame_id selected_frame_id; | |
4121 | ||
7a292a7a SS |
4122 | int breakpoint_proceeded; |
4123 | int restore_stack_info; | |
4124 | int proceed_to_finish; | |
4125 | }; | |
4126 | ||
7a292a7a | 4127 | void |
96baa820 JM |
4128 | write_inferior_status_register (struct inferior_status *inf_status, int regno, |
4129 | LONGEST val) | |
7a292a7a | 4130 | { |
3acba339 | 4131 | int size = register_size (current_gdbarch, regno); |
7a292a7a SS |
4132 | void *buf = alloca (size); |
4133 | store_signed_integer (buf, size, val); | |
0818c12a | 4134 | regcache_raw_write (inf_status->registers, regno, buf); |
7a292a7a SS |
4135 | } |
4136 | ||
c906108c SS |
4137 | /* Save all of the information associated with the inferior<==>gdb |
4138 | connection. INF_STATUS is a pointer to a "struct inferior_status" | |
4139 | (defined in inferior.h). */ | |
4140 | ||
7a292a7a | 4141 | struct inferior_status * |
96baa820 | 4142 | save_inferior_status (int restore_stack_info) |
c906108c | 4143 | { |
72cec141 | 4144 | struct inferior_status *inf_status = XMALLOC (struct inferior_status); |
7a292a7a | 4145 | |
c906108c SS |
4146 | inf_status->stop_signal = stop_signal; |
4147 | inf_status->stop_pc = stop_pc; | |
4148 | inf_status->stop_step = stop_step; | |
4149 | inf_status->stop_stack_dummy = stop_stack_dummy; | |
4150 | inf_status->stopped_by_random_signal = stopped_by_random_signal; | |
ca67fcb8 | 4151 | inf_status->stepping_over_breakpoint = stepping_over_breakpoint; |
c906108c SS |
4152 | inf_status->step_range_start = step_range_start; |
4153 | inf_status->step_range_end = step_range_end; | |
aa0cd9c1 | 4154 | inf_status->step_frame_id = step_frame_id; |
c906108c SS |
4155 | inf_status->step_over_calls = step_over_calls; |
4156 | inf_status->stop_after_trap = stop_after_trap; | |
c0236d92 | 4157 | inf_status->stop_soon = stop_soon; |
c906108c SS |
4158 | /* Save original bpstat chain here; replace it with copy of chain. |
4159 | If caller's caller is walking the chain, they'll be happier if we | |
7a292a7a SS |
4160 | hand them back the original chain when restore_inferior_status is |
4161 | called. */ | |
c906108c SS |
4162 | inf_status->stop_bpstat = stop_bpstat; |
4163 | stop_bpstat = bpstat_copy (stop_bpstat); | |
4164 | inf_status->breakpoint_proceeded = breakpoint_proceeded; | |
4165 | inf_status->restore_stack_info = restore_stack_info; | |
4166 | inf_status->proceed_to_finish = proceed_to_finish; | |
c5aa993b | 4167 | |
594f7785 | 4168 | inf_status->registers = regcache_dup (get_current_regcache ()); |
c906108c | 4169 | |
206415a3 | 4170 | inf_status->selected_frame_id = get_frame_id (get_selected_frame (NULL)); |
7a292a7a | 4171 | return inf_status; |
c906108c SS |
4172 | } |
4173 | ||
c906108c | 4174 | static int |
96baa820 | 4175 | restore_selected_frame (void *args) |
c906108c | 4176 | { |
488f131b | 4177 | struct frame_id *fid = (struct frame_id *) args; |
c906108c | 4178 | struct frame_info *frame; |
c906108c | 4179 | |
101dcfbe | 4180 | frame = frame_find_by_id (*fid); |
c906108c | 4181 | |
aa0cd9c1 AC |
4182 | /* If inf_status->selected_frame_id is NULL, there was no previously |
4183 | selected frame. */ | |
101dcfbe | 4184 | if (frame == NULL) |
c906108c | 4185 | { |
8a3fe4f8 | 4186 | warning (_("Unable to restore previously selected frame.")); |
c906108c SS |
4187 | return 0; |
4188 | } | |
4189 | ||
0f7d239c | 4190 | select_frame (frame); |
c906108c SS |
4191 | |
4192 | return (1); | |
4193 | } | |
4194 | ||
4195 | void | |
96baa820 | 4196 | restore_inferior_status (struct inferior_status *inf_status) |
c906108c SS |
4197 | { |
4198 | stop_signal = inf_status->stop_signal; | |
4199 | stop_pc = inf_status->stop_pc; | |
4200 | stop_step = inf_status->stop_step; | |
4201 | stop_stack_dummy = inf_status->stop_stack_dummy; | |
4202 | stopped_by_random_signal = inf_status->stopped_by_random_signal; | |
ca67fcb8 | 4203 | stepping_over_breakpoint = inf_status->stepping_over_breakpoint; |
c906108c SS |
4204 | step_range_start = inf_status->step_range_start; |
4205 | step_range_end = inf_status->step_range_end; | |
aa0cd9c1 | 4206 | step_frame_id = inf_status->step_frame_id; |
c906108c SS |
4207 | step_over_calls = inf_status->step_over_calls; |
4208 | stop_after_trap = inf_status->stop_after_trap; | |
c0236d92 | 4209 | stop_soon = inf_status->stop_soon; |
c906108c SS |
4210 | bpstat_clear (&stop_bpstat); |
4211 | stop_bpstat = inf_status->stop_bpstat; | |
4212 | breakpoint_proceeded = inf_status->breakpoint_proceeded; | |
4213 | proceed_to_finish = inf_status->proceed_to_finish; | |
4214 | ||
c906108c SS |
4215 | /* The inferior can be gone if the user types "print exit(0)" |
4216 | (and perhaps other times). */ | |
4217 | if (target_has_execution) | |
72cec141 | 4218 | /* NB: The register write goes through to the target. */ |
594f7785 | 4219 | regcache_cpy (get_current_regcache (), inf_status->registers); |
72cec141 | 4220 | regcache_xfree (inf_status->registers); |
c906108c | 4221 | |
c906108c SS |
4222 | /* FIXME: If we are being called after stopping in a function which |
4223 | is called from gdb, we should not be trying to restore the | |
4224 | selected frame; it just prints a spurious error message (The | |
4225 | message is useful, however, in detecting bugs in gdb (like if gdb | |
4226 | clobbers the stack)). In fact, should we be restoring the | |
4227 | inferior status at all in that case? . */ | |
4228 | ||
4229 | if (target_has_stack && inf_status->restore_stack_info) | |
4230 | { | |
c906108c | 4231 | /* The point of catch_errors is that if the stack is clobbered, |
101dcfbe AC |
4232 | walking the stack might encounter a garbage pointer and |
4233 | error() trying to dereference it. */ | |
488f131b JB |
4234 | if (catch_errors |
4235 | (restore_selected_frame, &inf_status->selected_frame_id, | |
4236 | "Unable to restore previously selected frame:\n", | |
4237 | RETURN_MASK_ERROR) == 0) | |
c906108c SS |
4238 | /* Error in restoring the selected frame. Select the innermost |
4239 | frame. */ | |
0f7d239c | 4240 | select_frame (get_current_frame ()); |
c906108c SS |
4241 | |
4242 | } | |
c906108c | 4243 | |
72cec141 | 4244 | xfree (inf_status); |
7a292a7a | 4245 | } |
c906108c | 4246 | |
74b7792f AC |
4247 | static void |
4248 | do_restore_inferior_status_cleanup (void *sts) | |
4249 | { | |
4250 | restore_inferior_status (sts); | |
4251 | } | |
4252 | ||
4253 | struct cleanup * | |
4254 | make_cleanup_restore_inferior_status (struct inferior_status *inf_status) | |
4255 | { | |
4256 | return make_cleanup (do_restore_inferior_status_cleanup, inf_status); | |
4257 | } | |
4258 | ||
c906108c | 4259 | void |
96baa820 | 4260 | discard_inferior_status (struct inferior_status *inf_status) |
7a292a7a SS |
4261 | { |
4262 | /* See save_inferior_status for info on stop_bpstat. */ | |
4263 | bpstat_clear (&inf_status->stop_bpstat); | |
72cec141 | 4264 | regcache_xfree (inf_status->registers); |
72cec141 | 4265 | xfree (inf_status); |
7a292a7a SS |
4266 | } |
4267 | ||
47932f85 DJ |
4268 | int |
4269 | inferior_has_forked (int pid, int *child_pid) | |
4270 | { | |
4271 | struct target_waitstatus last; | |
4272 | ptid_t last_ptid; | |
4273 | ||
4274 | get_last_target_status (&last_ptid, &last); | |
4275 | ||
4276 | if (last.kind != TARGET_WAITKIND_FORKED) | |
4277 | return 0; | |
4278 | ||
4279 | if (ptid_get_pid (last_ptid) != pid) | |
4280 | return 0; | |
4281 | ||
4282 | *child_pid = last.value.related_pid; | |
4283 | return 1; | |
4284 | } | |
4285 | ||
4286 | int | |
4287 | inferior_has_vforked (int pid, int *child_pid) | |
4288 | { | |
4289 | struct target_waitstatus last; | |
4290 | ptid_t last_ptid; | |
4291 | ||
4292 | get_last_target_status (&last_ptid, &last); | |
4293 | ||
4294 | if (last.kind != TARGET_WAITKIND_VFORKED) | |
4295 | return 0; | |
4296 | ||
4297 | if (ptid_get_pid (last_ptid) != pid) | |
4298 | return 0; | |
4299 | ||
4300 | *child_pid = last.value.related_pid; | |
4301 | return 1; | |
4302 | } | |
4303 | ||
4304 | int | |
4305 | inferior_has_execd (int pid, char **execd_pathname) | |
4306 | { | |
4307 | struct target_waitstatus last; | |
4308 | ptid_t last_ptid; | |
4309 | ||
4310 | get_last_target_status (&last_ptid, &last); | |
4311 | ||
4312 | if (last.kind != TARGET_WAITKIND_EXECD) | |
4313 | return 0; | |
4314 | ||
4315 | if (ptid_get_pid (last_ptid) != pid) | |
4316 | return 0; | |
4317 | ||
4318 | *execd_pathname = xstrdup (last.value.execd_pathname); | |
4319 | return 1; | |
4320 | } | |
4321 | ||
ca6724c1 KB |
4322 | /* Oft used ptids */ |
4323 | ptid_t null_ptid; | |
4324 | ptid_t minus_one_ptid; | |
4325 | ||
4326 | /* Create a ptid given the necessary PID, LWP, and TID components. */ | |
488f131b | 4327 | |
ca6724c1 KB |
4328 | ptid_t |
4329 | ptid_build (int pid, long lwp, long tid) | |
4330 | { | |
4331 | ptid_t ptid; | |
4332 | ||
4333 | ptid.pid = pid; | |
4334 | ptid.lwp = lwp; | |
4335 | ptid.tid = tid; | |
4336 | return ptid; | |
4337 | } | |
4338 | ||
4339 | /* Create a ptid from just a pid. */ | |
4340 | ||
4341 | ptid_t | |
4342 | pid_to_ptid (int pid) | |
4343 | { | |
4344 | return ptid_build (pid, 0, 0); | |
4345 | } | |
4346 | ||
4347 | /* Fetch the pid (process id) component from a ptid. */ | |
4348 | ||
4349 | int | |
4350 | ptid_get_pid (ptid_t ptid) | |
4351 | { | |
4352 | return ptid.pid; | |
4353 | } | |
4354 | ||
4355 | /* Fetch the lwp (lightweight process) component from a ptid. */ | |
4356 | ||
4357 | long | |
4358 | ptid_get_lwp (ptid_t ptid) | |
4359 | { | |
4360 | return ptid.lwp; | |
4361 | } | |
4362 | ||
4363 | /* Fetch the tid (thread id) component from a ptid. */ | |
4364 | ||
4365 | long | |
4366 | ptid_get_tid (ptid_t ptid) | |
4367 | { | |
4368 | return ptid.tid; | |
4369 | } | |
4370 | ||
4371 | /* ptid_equal() is used to test equality of two ptids. */ | |
4372 | ||
4373 | int | |
4374 | ptid_equal (ptid_t ptid1, ptid_t ptid2) | |
4375 | { | |
4376 | return (ptid1.pid == ptid2.pid && ptid1.lwp == ptid2.lwp | |
488f131b | 4377 | && ptid1.tid == ptid2.tid); |
ca6724c1 KB |
4378 | } |
4379 | ||
4380 | /* restore_inferior_ptid() will be used by the cleanup machinery | |
4381 | to restore the inferior_ptid value saved in a call to | |
4382 | save_inferior_ptid(). */ | |
ce696e05 KB |
4383 | |
4384 | static void | |
4385 | restore_inferior_ptid (void *arg) | |
4386 | { | |
4387 | ptid_t *saved_ptid_ptr = arg; | |
4388 | inferior_ptid = *saved_ptid_ptr; | |
4389 | xfree (arg); | |
4390 | } | |
4391 | ||
4392 | /* Save the value of inferior_ptid so that it may be restored by a | |
4393 | later call to do_cleanups(). Returns the struct cleanup pointer | |
4394 | needed for later doing the cleanup. */ | |
4395 | ||
4396 | struct cleanup * | |
4397 | save_inferior_ptid (void) | |
4398 | { | |
4399 | ptid_t *saved_ptid_ptr; | |
4400 | ||
4401 | saved_ptid_ptr = xmalloc (sizeof (ptid_t)); | |
4402 | *saved_ptid_ptr = inferior_ptid; | |
4403 | return make_cleanup (restore_inferior_ptid, saved_ptid_ptr); | |
4404 | } | |
c5aa993b | 4405 | \f |
488f131b | 4406 | |
c906108c | 4407 | void |
96baa820 | 4408 | _initialize_infrun (void) |
c906108c | 4409 | { |
52f0bd74 AC |
4410 | int i; |
4411 | int numsigs; | |
c906108c SS |
4412 | struct cmd_list_element *c; |
4413 | ||
1bedd215 AC |
4414 | add_info ("signals", signals_info, _("\ |
4415 | What debugger does when program gets various signals.\n\ | |
4416 | Specify a signal as argument to print info on that signal only.")); | |
c906108c SS |
4417 | add_info_alias ("handle", "signals", 0); |
4418 | ||
1bedd215 AC |
4419 | add_com ("handle", class_run, handle_command, _("\ |
4420 | Specify how to handle a signal.\n\ | |
c906108c SS |
4421 | Args are signals and actions to apply to those signals.\n\ |
4422 | Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\ | |
4423 | from 1-15 are allowed for compatibility with old versions of GDB.\n\ | |
4424 | Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\ | |
4425 | The special arg \"all\" is recognized to mean all signals except those\n\ | |
1bedd215 AC |
4426 | used by the debugger, typically SIGTRAP and SIGINT.\n\ |
4427 | Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\ | |
c906108c SS |
4428 | \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\ |
4429 | Stop means reenter debugger if this signal happens (implies print).\n\ | |
4430 | Print means print a message if this signal happens.\n\ | |
4431 | Pass means let program see this signal; otherwise program doesn't know.\n\ | |
4432 | Ignore is a synonym for nopass and noignore is a synonym for pass.\n\ | |
1bedd215 | 4433 | Pass and Stop may be combined.")); |
c906108c SS |
4434 | if (xdb_commands) |
4435 | { | |
1bedd215 AC |
4436 | add_com ("lz", class_info, signals_info, _("\ |
4437 | What debugger does when program gets various signals.\n\ | |
4438 | Specify a signal as argument to print info on that signal only.")); | |
4439 | add_com ("z", class_run, xdb_handle_command, _("\ | |
4440 | Specify how to handle a signal.\n\ | |
c906108c SS |
4441 | Args are signals and actions to apply to those signals.\n\ |
4442 | Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\ | |
4443 | from 1-15 are allowed for compatibility with old versions of GDB.\n\ | |
4444 | Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\ | |
4445 | The special arg \"all\" is recognized to mean all signals except those\n\ | |
1bedd215 AC |
4446 | used by the debugger, typically SIGTRAP and SIGINT.\n\ |
4447 | Recognized actions include \"s\" (toggles between stop and nostop), \n\ | |
c906108c SS |
4448 | \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \ |
4449 | nopass), \"Q\" (noprint)\n\ | |
4450 | Stop means reenter debugger if this signal happens (implies print).\n\ | |
4451 | Print means print a message if this signal happens.\n\ | |
4452 | Pass means let program see this signal; otherwise program doesn't know.\n\ | |
4453 | Ignore is a synonym for nopass and noignore is a synonym for pass.\n\ | |
1bedd215 | 4454 | Pass and Stop may be combined.")); |
c906108c SS |
4455 | } |
4456 | ||
4457 | if (!dbx_commands) | |
1a966eab AC |
4458 | stop_command = add_cmd ("stop", class_obscure, |
4459 | not_just_help_class_command, _("\ | |
4460 | There is no `stop' command, but you can set a hook on `stop'.\n\ | |
c906108c | 4461 | This allows you to set a list of commands to be run each time execution\n\ |
1a966eab | 4462 | of the program stops."), &cmdlist); |
c906108c | 4463 | |
85c07804 AC |
4464 | add_setshow_zinteger_cmd ("infrun", class_maintenance, &debug_infrun, _("\ |
4465 | Set inferior debugging."), _("\ | |
4466 | Show inferior debugging."), _("\ | |
4467 | When non-zero, inferior specific debugging is enabled."), | |
4468 | NULL, | |
920d2a44 | 4469 | show_debug_infrun, |
85c07804 | 4470 | &setdebuglist, &showdebuglist); |
527159b7 | 4471 | |
237fc4c9 PA |
4472 | add_setshow_boolean_cmd ("displaced", class_maintenance, &debug_displaced, _("\ |
4473 | Set displaced stepping debugging."), _("\ | |
4474 | Show displaced stepping debugging."), _("\ | |
4475 | When non-zero, displaced stepping specific debugging is enabled."), | |
4476 | NULL, | |
4477 | show_debug_displaced, | |
4478 | &setdebuglist, &showdebuglist); | |
4479 | ||
c906108c | 4480 | numsigs = (int) TARGET_SIGNAL_LAST; |
488f131b | 4481 | signal_stop = (unsigned char *) xmalloc (sizeof (signal_stop[0]) * numsigs); |
c906108c SS |
4482 | signal_print = (unsigned char *) |
4483 | xmalloc (sizeof (signal_print[0]) * numsigs); | |
4484 | signal_program = (unsigned char *) | |
4485 | xmalloc (sizeof (signal_program[0]) * numsigs); | |
4486 | for (i = 0; i < numsigs; i++) | |
4487 | { | |
4488 | signal_stop[i] = 1; | |
4489 | signal_print[i] = 1; | |
4490 | signal_program[i] = 1; | |
4491 | } | |
4492 | ||
4493 | /* Signals caused by debugger's own actions | |
4494 | should not be given to the program afterwards. */ | |
4495 | signal_program[TARGET_SIGNAL_TRAP] = 0; | |
4496 | signal_program[TARGET_SIGNAL_INT] = 0; | |
4497 | ||
4498 | /* Signals that are not errors should not normally enter the debugger. */ | |
4499 | signal_stop[TARGET_SIGNAL_ALRM] = 0; | |
4500 | signal_print[TARGET_SIGNAL_ALRM] = 0; | |
4501 | signal_stop[TARGET_SIGNAL_VTALRM] = 0; | |
4502 | signal_print[TARGET_SIGNAL_VTALRM] = 0; | |
4503 | signal_stop[TARGET_SIGNAL_PROF] = 0; | |
4504 | signal_print[TARGET_SIGNAL_PROF] = 0; | |
4505 | signal_stop[TARGET_SIGNAL_CHLD] = 0; | |
4506 | signal_print[TARGET_SIGNAL_CHLD] = 0; | |
4507 | signal_stop[TARGET_SIGNAL_IO] = 0; | |
4508 | signal_print[TARGET_SIGNAL_IO] = 0; | |
4509 | signal_stop[TARGET_SIGNAL_POLL] = 0; | |
4510 | signal_print[TARGET_SIGNAL_POLL] = 0; | |
4511 | signal_stop[TARGET_SIGNAL_URG] = 0; | |
4512 | signal_print[TARGET_SIGNAL_URG] = 0; | |
4513 | signal_stop[TARGET_SIGNAL_WINCH] = 0; | |
4514 | signal_print[TARGET_SIGNAL_WINCH] = 0; | |
4515 | ||
cd0fc7c3 SS |
4516 | /* These signals are used internally by user-level thread |
4517 | implementations. (See signal(5) on Solaris.) Like the above | |
4518 | signals, a healthy program receives and handles them as part of | |
4519 | its normal operation. */ | |
4520 | signal_stop[TARGET_SIGNAL_LWP] = 0; | |
4521 | signal_print[TARGET_SIGNAL_LWP] = 0; | |
4522 | signal_stop[TARGET_SIGNAL_WAITING] = 0; | |
4523 | signal_print[TARGET_SIGNAL_WAITING] = 0; | |
4524 | signal_stop[TARGET_SIGNAL_CANCEL] = 0; | |
4525 | signal_print[TARGET_SIGNAL_CANCEL] = 0; | |
4526 | ||
85c07804 AC |
4527 | add_setshow_zinteger_cmd ("stop-on-solib-events", class_support, |
4528 | &stop_on_solib_events, _("\ | |
4529 | Set stopping for shared library events."), _("\ | |
4530 | Show stopping for shared library events."), _("\ | |
c906108c SS |
4531 | If nonzero, gdb will give control to the user when the dynamic linker\n\ |
4532 | notifies gdb of shared library events. The most common event of interest\n\ | |
85c07804 AC |
4533 | to the user would be loading/unloading of a new library."), |
4534 | NULL, | |
920d2a44 | 4535 | show_stop_on_solib_events, |
85c07804 | 4536 | &setlist, &showlist); |
c906108c | 4537 | |
7ab04401 AC |
4538 | add_setshow_enum_cmd ("follow-fork-mode", class_run, |
4539 | follow_fork_mode_kind_names, | |
4540 | &follow_fork_mode_string, _("\ | |
4541 | Set debugger response to a program call of fork or vfork."), _("\ | |
4542 | Show debugger response to a program call of fork or vfork."), _("\ | |
c906108c SS |
4543 | A fork or vfork creates a new process. follow-fork-mode can be:\n\ |
4544 | parent - the original process is debugged after a fork\n\ | |
4545 | child - the new process is debugged after a fork\n\ | |
ea1dd7bc | 4546 | The unfollowed process will continue to run.\n\ |
7ab04401 AC |
4547 | By default, the debugger will follow the parent process."), |
4548 | NULL, | |
920d2a44 | 4549 | show_follow_fork_mode_string, |
7ab04401 AC |
4550 | &setlist, &showlist); |
4551 | ||
4552 | add_setshow_enum_cmd ("scheduler-locking", class_run, | |
4553 | scheduler_enums, &scheduler_mode, _("\ | |
4554 | Set mode for locking scheduler during execution."), _("\ | |
4555 | Show mode for locking scheduler during execution."), _("\ | |
c906108c SS |
4556 | off == no locking (threads may preempt at any time)\n\ |
4557 | on == full locking (no thread except the current thread may run)\n\ | |
4558 | step == scheduler locked during every single-step operation.\n\ | |
4559 | In this mode, no other thread may run during a step command.\n\ | |
7ab04401 AC |
4560 | Other threads may run while stepping over a function call ('next')."), |
4561 | set_schedlock_func, /* traps on target vector */ | |
920d2a44 | 4562 | show_scheduler_mode, |
7ab04401 | 4563 | &setlist, &showlist); |
5fbbeb29 | 4564 | |
5bf193a2 AC |
4565 | add_setshow_boolean_cmd ("step-mode", class_run, &step_stop_if_no_debug, _("\ |
4566 | Set mode of the step operation."), _("\ | |
4567 | Show mode of the step operation."), _("\ | |
4568 | When set, doing a step over a function without debug line information\n\ | |
4569 | will stop at the first instruction of that function. Otherwise, the\n\ | |
4570 | function is skipped and the step command stops at a different source line."), | |
4571 | NULL, | |
920d2a44 | 4572 | show_step_stop_if_no_debug, |
5bf193a2 | 4573 | &setlist, &showlist); |
ca6724c1 | 4574 | |
237fc4c9 PA |
4575 | add_setshow_boolean_cmd ("can-use-displaced-stepping", class_maintenance, |
4576 | &can_use_displaced_stepping, _("\ | |
4577 | Set debugger's willingness to use displaced stepping."), _("\ | |
4578 | Show debugger's willingness to use displaced stepping."), _("\ | |
4579 | If zero, gdb will not use to use displaced stepping to step over\n\ | |
4580 | breakpoints, even if such is supported by the target."), | |
4581 | NULL, | |
4582 | show_can_use_displaced_stepping, | |
4583 | &maintenance_set_cmdlist, | |
4584 | &maintenance_show_cmdlist); | |
4585 | ||
4586 | ||
ca6724c1 KB |
4587 | /* ptid initializations */ |
4588 | null_ptid = ptid_build (0, 0, 0); | |
4589 | minus_one_ptid = ptid_build (-1, 0, 0); | |
4590 | inferior_ptid = null_ptid; | |
4591 | target_last_wait_ptid = minus_one_ptid; | |
237fc4c9 | 4592 | displaced_step_ptid = null_ptid; |
c906108c | 4593 | } |