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