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 SS |
1283 | { |
1284 | init_thread_list (); | |
1285 | init_wait_for_inferior (); | |
b0f4b84b | 1286 | stop_soon = STOP_QUIETLY_REMOTE; |
ca67fcb8 | 1287 | stepping_over_breakpoint = 0; |
43ff13b4 | 1288 | |
6426a772 JM |
1289 | /* Always go on waiting for the target, regardless of the mode. */ |
1290 | /* FIXME: cagney/1999-09-23: At present it isn't possible to | |
7e73cedf | 1291 | indicate to wait_for_inferior that a target should timeout if |
6426a772 JM |
1292 | nothing is returned (instead of just blocking). Because of this, |
1293 | targets expecting an immediate response need to, internally, set | |
1294 | things up so that the target_wait() is forced to eventually | |
1295 | timeout. */ | |
1296 | /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to | |
1297 | differentiate to its caller what the state of the target is after | |
1298 | the initial open has been performed. Here we're assuming that | |
1299 | the target has stopped. It should be possible to eventually have | |
1300 | target_open() return to the caller an indication that the target | |
1301 | is currently running and GDB state should be set to the same as | |
1302 | for an async run. */ | |
ae123ec6 | 1303 | wait_for_inferior (0); |
8621d6a9 DJ |
1304 | |
1305 | /* Now that the inferior has stopped, do any bookkeeping like | |
1306 | loading shared libraries. We want to do this before normal_stop, | |
1307 | so that the displayed frame is up to date. */ | |
1308 | post_create_inferior (¤t_target, from_tty); | |
1309 | ||
6426a772 | 1310 | normal_stop (); |
c906108c SS |
1311 | } |
1312 | ||
1313 | /* Initialize static vars when a new inferior begins. */ | |
1314 | ||
1315 | void | |
96baa820 | 1316 | init_wait_for_inferior (void) |
c906108c SS |
1317 | { |
1318 | /* These are meaningless until the first time through wait_for_inferior. */ | |
1319 | prev_pc = 0; | |
c906108c | 1320 | |
c906108c SS |
1321 | breakpoint_init_inferior (inf_starting); |
1322 | ||
1323 | /* Don't confuse first call to proceed(). */ | |
1324 | stop_signal = TARGET_SIGNAL_0; | |
1325 | ||
1326 | /* The first resume is not following a fork/vfork/exec. */ | |
1327 | pending_follow.kind = TARGET_WAITKIND_SPURIOUS; /* I.e., none. */ | |
c906108c | 1328 | |
c906108c | 1329 | clear_proceed_status (); |
9f976b41 DJ |
1330 | |
1331 | stepping_past_singlestep_breakpoint = 0; | |
ca67fcb8 | 1332 | deferred_step_ptid = null_ptid; |
ca005067 DJ |
1333 | |
1334 | target_last_wait_ptid = minus_one_ptid; | |
237fc4c9 PA |
1335 | |
1336 | displaced_step_clear (); | |
c906108c | 1337 | } |
237fc4c9 | 1338 | |
c906108c | 1339 | \f |
b83266a0 SS |
1340 | /* This enum encodes possible reasons for doing a target_wait, so that |
1341 | wfi can call target_wait in one place. (Ultimately the call will be | |
1342 | moved out of the infinite loop entirely.) */ | |
1343 | ||
c5aa993b JM |
1344 | enum infwait_states |
1345 | { | |
cd0fc7c3 SS |
1346 | infwait_normal_state, |
1347 | infwait_thread_hop_state, | |
d983da9c | 1348 | infwait_step_watch_state, |
cd0fc7c3 | 1349 | infwait_nonstep_watch_state |
b83266a0 SS |
1350 | }; |
1351 | ||
11cf8741 JM |
1352 | /* Why did the inferior stop? Used to print the appropriate messages |
1353 | to the interface from within handle_inferior_event(). */ | |
1354 | enum inferior_stop_reason | |
1355 | { | |
11cf8741 JM |
1356 | /* Step, next, nexti, stepi finished. */ |
1357 | END_STEPPING_RANGE, | |
11cf8741 JM |
1358 | /* Inferior terminated by signal. */ |
1359 | SIGNAL_EXITED, | |
1360 | /* Inferior exited. */ | |
1361 | EXITED, | |
1362 | /* Inferior received signal, and user asked to be notified. */ | |
1363 | SIGNAL_RECEIVED | |
1364 | }; | |
1365 | ||
cd0fc7c3 SS |
1366 | /* This structure contains what used to be local variables in |
1367 | wait_for_inferior. Probably many of them can return to being | |
1368 | locals in handle_inferior_event. */ | |
1369 | ||
c5aa993b | 1370 | struct execution_control_state |
488f131b JB |
1371 | { |
1372 | struct target_waitstatus ws; | |
1373 | struct target_waitstatus *wp; | |
ca67fcb8 VP |
1374 | /* Should we step over breakpoint next time keep_going |
1375 | is called? */ | |
1376 | int stepping_over_breakpoint; | |
488f131b JB |
1377 | int random_signal; |
1378 | CORE_ADDR stop_func_start; | |
1379 | CORE_ADDR stop_func_end; | |
1380 | char *stop_func_name; | |
1381 | struct symtab_and_line sal; | |
488f131b JB |
1382 | int current_line; |
1383 | struct symtab *current_symtab; | |
488f131b JB |
1384 | ptid_t ptid; |
1385 | ptid_t saved_inferior_ptid; | |
68f53502 | 1386 | int step_after_step_resume_breakpoint; |
488f131b JB |
1387 | int stepping_through_solib_after_catch; |
1388 | bpstat stepping_through_solib_catchpoints; | |
488f131b JB |
1389 | int new_thread_event; |
1390 | struct target_waitstatus tmpstatus; | |
1391 | enum infwait_states infwait_state; | |
1392 | ptid_t waiton_ptid; | |
1393 | int wait_some_more; | |
1394 | }; | |
1395 | ||
1396 | void init_execution_control_state (struct execution_control_state *ecs); | |
1397 | ||
1398 | void handle_inferior_event (struct execution_control_state *ecs); | |
cd0fc7c3 | 1399 | |
c2c6d25f | 1400 | static void step_into_function (struct execution_control_state *ecs); |
44cbf7b5 | 1401 | static void insert_step_resume_breakpoint_at_frame (struct frame_info *step_frame); |
14e60db5 | 1402 | static void insert_step_resume_breakpoint_at_caller (struct frame_info *); |
44cbf7b5 AC |
1403 | static void insert_step_resume_breakpoint_at_sal (struct symtab_and_line sr_sal, |
1404 | struct frame_id sr_id); | |
611c83ae PA |
1405 | static void insert_longjmp_resume_breakpoint (CORE_ADDR); |
1406 | ||
104c1213 JM |
1407 | static void stop_stepping (struct execution_control_state *ecs); |
1408 | static void prepare_to_wait (struct execution_control_state *ecs); | |
d4f3574e | 1409 | static void keep_going (struct execution_control_state *ecs); |
488f131b JB |
1410 | static void print_stop_reason (enum inferior_stop_reason stop_reason, |
1411 | int stop_info); | |
104c1213 | 1412 | |
cd0fc7c3 | 1413 | /* Wait for control to return from inferior to debugger. |
ae123ec6 JB |
1414 | |
1415 | If TREAT_EXEC_AS_SIGTRAP is non-zero, then handle EXEC signals | |
1416 | as if they were SIGTRAP signals. This can be useful during | |
1417 | the startup sequence on some targets such as HP/UX, where | |
1418 | we receive an EXEC event instead of the expected SIGTRAP. | |
1419 | ||
cd0fc7c3 SS |
1420 | If inferior gets a signal, we may decide to start it up again |
1421 | instead of returning. That is why there is a loop in this function. | |
1422 | When this function actually returns it means the inferior | |
1423 | should be left stopped and GDB should read more commands. */ | |
1424 | ||
1425 | void | |
ae123ec6 | 1426 | wait_for_inferior (int treat_exec_as_sigtrap) |
cd0fc7c3 SS |
1427 | { |
1428 | struct cleanup *old_cleanups; | |
1429 | struct execution_control_state ecss; | |
1430 | struct execution_control_state *ecs; | |
c906108c | 1431 | |
527159b7 | 1432 | if (debug_infrun) |
ae123ec6 JB |
1433 | fprintf_unfiltered |
1434 | (gdb_stdlog, "infrun: wait_for_inferior (treat_exec_as_sigtrap=%d)\n", | |
1435 | treat_exec_as_sigtrap); | |
527159b7 | 1436 | |
8601f500 | 1437 | old_cleanups = make_cleanup (delete_step_resume_breakpoint, |
c906108c | 1438 | &step_resume_breakpoint); |
cd0fc7c3 SS |
1439 | |
1440 | /* wfi still stays in a loop, so it's OK just to take the address of | |
1441 | a local to get the ecs pointer. */ | |
1442 | ecs = &ecss; | |
1443 | ||
1444 | /* Fill in with reasonable starting values. */ | |
1445 | init_execution_control_state (ecs); | |
1446 | ||
c906108c | 1447 | /* We'll update this if & when we switch to a new thread. */ |
39f77062 | 1448 | previous_inferior_ptid = inferior_ptid; |
c906108c | 1449 | |
cd0fc7c3 SS |
1450 | overlay_cache_invalid = 1; |
1451 | ||
1452 | /* We have to invalidate the registers BEFORE calling target_wait | |
1453 | because they can be loaded from the target while in target_wait. | |
1454 | This makes remote debugging a bit more efficient for those | |
1455 | targets that provide critical registers as part of their normal | |
1456 | status mechanism. */ | |
1457 | ||
1458 | registers_changed (); | |
b83266a0 | 1459 | |
c906108c SS |
1460 | while (1) |
1461 | { | |
9a4105ab AC |
1462 | if (deprecated_target_wait_hook) |
1463 | ecs->ptid = deprecated_target_wait_hook (ecs->waiton_ptid, ecs->wp); | |
cd0fc7c3 | 1464 | else |
39f77062 | 1465 | ecs->ptid = target_wait (ecs->waiton_ptid, ecs->wp); |
c906108c | 1466 | |
ae123ec6 JB |
1467 | if (treat_exec_as_sigtrap && ecs->ws.kind == TARGET_WAITKIND_EXECD) |
1468 | { | |
1469 | xfree (ecs->ws.value.execd_pathname); | |
1470 | ecs->ws.kind = TARGET_WAITKIND_STOPPED; | |
1471 | ecs->ws.value.sig = TARGET_SIGNAL_TRAP; | |
1472 | } | |
1473 | ||
cd0fc7c3 SS |
1474 | /* Now figure out what to do with the result of the result. */ |
1475 | handle_inferior_event (ecs); | |
c906108c | 1476 | |
cd0fc7c3 SS |
1477 | if (!ecs->wait_some_more) |
1478 | break; | |
1479 | } | |
1480 | do_cleanups (old_cleanups); | |
1481 | } | |
c906108c | 1482 | |
43ff13b4 JM |
1483 | /* Asynchronous version of wait_for_inferior. It is called by the |
1484 | event loop whenever a change of state is detected on the file | |
1485 | descriptor corresponding to the target. It can be called more than | |
1486 | once to complete a single execution command. In such cases we need | |
1487 | to keep the state in a global variable ASYNC_ECSS. If it is the | |
1488 | last time that this function is called for a single execution | |
1489 | command, then report to the user that the inferior has stopped, and | |
1490 | do the necessary cleanups. */ | |
1491 | ||
1492 | struct execution_control_state async_ecss; | |
1493 | struct execution_control_state *async_ecs; | |
1494 | ||
1495 | void | |
fba45db2 | 1496 | fetch_inferior_event (void *client_data) |
43ff13b4 JM |
1497 | { |
1498 | static struct cleanup *old_cleanups; | |
1499 | ||
c5aa993b | 1500 | async_ecs = &async_ecss; |
43ff13b4 JM |
1501 | |
1502 | if (!async_ecs->wait_some_more) | |
1503 | { | |
43ff13b4 JM |
1504 | /* Fill in with reasonable starting values. */ |
1505 | init_execution_control_state (async_ecs); | |
1506 | ||
43ff13b4 | 1507 | /* We'll update this if & when we switch to a new thread. */ |
39f77062 | 1508 | previous_inferior_ptid = inferior_ptid; |
43ff13b4 JM |
1509 | |
1510 | overlay_cache_invalid = 1; | |
1511 | ||
1512 | /* We have to invalidate the registers BEFORE calling target_wait | |
c5aa993b JM |
1513 | because they can be loaded from the target while in target_wait. |
1514 | This makes remote debugging a bit more efficient for those | |
1515 | targets that provide critical registers as part of their normal | |
1516 | status mechanism. */ | |
43ff13b4 JM |
1517 | |
1518 | registers_changed (); | |
1519 | } | |
1520 | ||
9a4105ab | 1521 | if (deprecated_target_wait_hook) |
488f131b | 1522 | async_ecs->ptid = |
9a4105ab | 1523 | deprecated_target_wait_hook (async_ecs->waiton_ptid, async_ecs->wp); |
43ff13b4 | 1524 | else |
39f77062 | 1525 | async_ecs->ptid = target_wait (async_ecs->waiton_ptid, async_ecs->wp); |
43ff13b4 JM |
1526 | |
1527 | /* Now figure out what to do with the result of the result. */ | |
1528 | handle_inferior_event (async_ecs); | |
1529 | ||
1530 | if (!async_ecs->wait_some_more) | |
1531 | { | |
f107f563 VP |
1532 | delete_step_resume_breakpoint (&step_resume_breakpoint); |
1533 | ||
43ff13b4 | 1534 | normal_stop (); |
c2d11a7d JM |
1535 | if (step_multi && stop_step) |
1536 | inferior_event_handler (INF_EXEC_CONTINUE, NULL); | |
1537 | else | |
1538 | inferior_event_handler (INF_EXEC_COMPLETE, NULL); | |
43ff13b4 JM |
1539 | } |
1540 | } | |
1541 | ||
cd0fc7c3 SS |
1542 | /* Prepare an execution control state for looping through a |
1543 | wait_for_inferior-type loop. */ | |
1544 | ||
1545 | void | |
96baa820 | 1546 | init_execution_control_state (struct execution_control_state *ecs) |
cd0fc7c3 | 1547 | { |
ca67fcb8 | 1548 | ecs->stepping_over_breakpoint = 0; |
cd0fc7c3 | 1549 | ecs->random_signal = 0; |
68f53502 | 1550 | ecs->step_after_step_resume_breakpoint = 0; |
cd0fc7c3 SS |
1551 | ecs->stepping_through_solib_after_catch = 0; |
1552 | ecs->stepping_through_solib_catchpoints = NULL; | |
cd0fc7c3 SS |
1553 | ecs->sal = find_pc_line (prev_pc, 0); |
1554 | ecs->current_line = ecs->sal.line; | |
1555 | ecs->current_symtab = ecs->sal.symtab; | |
1556 | ecs->infwait_state = infwait_normal_state; | |
39f77062 | 1557 | ecs->waiton_ptid = pid_to_ptid (-1); |
cd0fc7c3 SS |
1558 | ecs->wp = &(ecs->ws); |
1559 | } | |
1560 | ||
e02bc4cc | 1561 | /* Return the cached copy of the last pid/waitstatus returned by |
9a4105ab AC |
1562 | target_wait()/deprecated_target_wait_hook(). The data is actually |
1563 | cached by handle_inferior_event(), which gets called immediately | |
1564 | after target_wait()/deprecated_target_wait_hook(). */ | |
e02bc4cc DS |
1565 | |
1566 | void | |
488f131b | 1567 | get_last_target_status (ptid_t *ptidp, struct target_waitstatus *status) |
e02bc4cc | 1568 | { |
39f77062 | 1569 | *ptidp = target_last_wait_ptid; |
e02bc4cc DS |
1570 | *status = target_last_waitstatus; |
1571 | } | |
1572 | ||
ac264b3b MS |
1573 | void |
1574 | nullify_last_target_wait_ptid (void) | |
1575 | { | |
1576 | target_last_wait_ptid = minus_one_ptid; | |
1577 | } | |
1578 | ||
dd80620e MS |
1579 | /* Switch thread contexts, maintaining "infrun state". */ |
1580 | ||
1581 | static void | |
1582 | context_switch (struct execution_control_state *ecs) | |
1583 | { | |
1584 | /* Caution: it may happen that the new thread (or the old one!) | |
1585 | is not in the thread list. In this case we must not attempt | |
1586 | to "switch context", or we run the risk that our context may | |
1587 | be lost. This may happen as a result of the target module | |
1588 | mishandling thread creation. */ | |
1589 | ||
fd48f117 DJ |
1590 | if (debug_infrun) |
1591 | { | |
1592 | fprintf_unfiltered (gdb_stdlog, "infrun: Switching context from %s ", | |
1593 | target_pid_to_str (inferior_ptid)); | |
1594 | fprintf_unfiltered (gdb_stdlog, "to %s\n", | |
1595 | target_pid_to_str (ecs->ptid)); | |
1596 | } | |
1597 | ||
dd80620e | 1598 | if (in_thread_list (inferior_ptid) && in_thread_list (ecs->ptid)) |
488f131b | 1599 | { /* Perform infrun state context switch: */ |
dd80620e | 1600 | /* Save infrun state for the old thread. */ |
0ce3d317 | 1601 | save_infrun_state (inferior_ptid, prev_pc, |
ca67fcb8 | 1602 | stepping_over_breakpoint, step_resume_breakpoint, |
15960608 | 1603 | step_range_start, |
aa0cd9c1 | 1604 | step_range_end, &step_frame_id, |
611c83ae | 1605 | ecs->stepping_over_breakpoint, |
dd80620e MS |
1606 | ecs->stepping_through_solib_after_catch, |
1607 | ecs->stepping_through_solib_catchpoints, | |
f2c9ca08 | 1608 | ecs->current_line, ecs->current_symtab); |
dd80620e MS |
1609 | |
1610 | /* Load infrun state for the new thread. */ | |
0ce3d317 | 1611 | load_infrun_state (ecs->ptid, &prev_pc, |
ca67fcb8 | 1612 | &stepping_over_breakpoint, &step_resume_breakpoint, |
15960608 | 1613 | &step_range_start, |
aa0cd9c1 | 1614 | &step_range_end, &step_frame_id, |
611c83ae | 1615 | &ecs->stepping_over_breakpoint, |
dd80620e MS |
1616 | &ecs->stepping_through_solib_after_catch, |
1617 | &ecs->stepping_through_solib_catchpoints, | |
f2c9ca08 | 1618 | &ecs->current_line, &ecs->current_symtab); |
dd80620e | 1619 | } |
6a6b96b9 UW |
1620 | |
1621 | switch_to_thread (ecs->ptid); | |
dd80620e MS |
1622 | } |
1623 | ||
4fa8626c DJ |
1624 | static void |
1625 | adjust_pc_after_break (struct execution_control_state *ecs) | |
1626 | { | |
515630c5 UW |
1627 | struct regcache *regcache = get_thread_regcache (ecs->ptid); |
1628 | struct gdbarch *gdbarch = get_regcache_arch (regcache); | |
8aad930b | 1629 | CORE_ADDR breakpoint_pc; |
4fa8626c DJ |
1630 | |
1631 | /* If this target does not decrement the PC after breakpoints, then | |
1632 | we have nothing to do. */ | |
515630c5 | 1633 | if (gdbarch_decr_pc_after_break (gdbarch) == 0) |
4fa8626c DJ |
1634 | return; |
1635 | ||
1636 | /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If | |
1637 | we aren't, just return. | |
9709f61c DJ |
1638 | |
1639 | We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not | |
b798847d UW |
1640 | affected by gdbarch_decr_pc_after_break. Other waitkinds which are |
1641 | implemented by software breakpoints should be handled through the normal | |
1642 | breakpoint layer. | |
8fb3e588 | 1643 | |
4fa8626c DJ |
1644 | NOTE drow/2004-01-31: On some targets, breakpoints may generate |
1645 | different signals (SIGILL or SIGEMT for instance), but it is less | |
1646 | clear where the PC is pointing afterwards. It may not match | |
b798847d UW |
1647 | gdbarch_decr_pc_after_break. I don't know any specific target that |
1648 | generates these signals at breakpoints (the code has been in GDB since at | |
1649 | least 1992) so I can not guess how to handle them here. | |
8fb3e588 | 1650 | |
e6cf7916 UW |
1651 | In earlier versions of GDB, a target with |
1652 | gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a | |
b798847d UW |
1653 | watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any |
1654 | target with both of these set in GDB history, and it seems unlikely to be | |
1655 | correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */ | |
4fa8626c DJ |
1656 | |
1657 | if (ecs->ws.kind != TARGET_WAITKIND_STOPPED) | |
1658 | return; | |
1659 | ||
1660 | if (ecs->ws.value.sig != TARGET_SIGNAL_TRAP) | |
1661 | return; | |
1662 | ||
8aad930b AC |
1663 | /* Find the location where (if we've hit a breakpoint) the |
1664 | breakpoint would be. */ | |
515630c5 UW |
1665 | breakpoint_pc = regcache_read_pc (regcache) |
1666 | - gdbarch_decr_pc_after_break (gdbarch); | |
8aad930b | 1667 | |
1c0fdd0e UW |
1668 | /* Check whether there actually is a software breakpoint inserted |
1669 | at that location. */ | |
1670 | if (software_breakpoint_inserted_here_p (breakpoint_pc)) | |
8aad930b | 1671 | { |
1c0fdd0e UW |
1672 | /* When using hardware single-step, a SIGTRAP is reported for both |
1673 | a completed single-step and a software breakpoint. Need to | |
1674 | differentiate between the two, as the latter needs adjusting | |
1675 | but the former does not. | |
1676 | ||
1677 | The SIGTRAP can be due to a completed hardware single-step only if | |
1678 | - we didn't insert software single-step breakpoints | |
1679 | - the thread to be examined is still the current thread | |
1680 | - this thread is currently being stepped | |
1681 | ||
1682 | If any of these events did not occur, we must have stopped due | |
1683 | to hitting a software breakpoint, and have to back up to the | |
1684 | breakpoint address. | |
1685 | ||
1686 | As a special case, we could have hardware single-stepped a | |
1687 | software breakpoint. In this case (prev_pc == breakpoint_pc), | |
1688 | we also need to back up to the breakpoint address. */ | |
1689 | ||
1690 | if (singlestep_breakpoints_inserted_p | |
1691 | || !ptid_equal (ecs->ptid, inferior_ptid) | |
1692 | || !currently_stepping (ecs) | |
1693 | || prev_pc == breakpoint_pc) | |
515630c5 | 1694 | regcache_write_pc (regcache, breakpoint_pc); |
8aad930b | 1695 | } |
4fa8626c DJ |
1696 | } |
1697 | ||
cd0fc7c3 SS |
1698 | /* Given an execution control state that has been freshly filled in |
1699 | by an event from the inferior, figure out what it means and take | |
1700 | appropriate action. */ | |
c906108c | 1701 | |
cd0fc7c3 | 1702 | void |
96baa820 | 1703 | handle_inferior_event (struct execution_control_state *ecs) |
cd0fc7c3 | 1704 | { |
c8edd8b4 | 1705 | int sw_single_step_trap_p = 0; |
d983da9c DJ |
1706 | int stopped_by_watchpoint; |
1707 | int stepped_after_stopped_by_watchpoint = 0; | |
cd0fc7c3 | 1708 | |
e02bc4cc | 1709 | /* Cache the last pid/waitstatus. */ |
39f77062 | 1710 | target_last_wait_ptid = ecs->ptid; |
e02bc4cc DS |
1711 | target_last_waitstatus = *ecs->wp; |
1712 | ||
ca005067 DJ |
1713 | /* Always clear state belonging to the previous time we stopped. */ |
1714 | stop_stack_dummy = 0; | |
1715 | ||
4fa8626c DJ |
1716 | adjust_pc_after_break (ecs); |
1717 | ||
488f131b JB |
1718 | switch (ecs->infwait_state) |
1719 | { | |
1720 | case infwait_thread_hop_state: | |
527159b7 | 1721 | if (debug_infrun) |
8a9de0e4 | 1722 | fprintf_unfiltered (gdb_stdlog, "infrun: infwait_thread_hop_state\n"); |
488f131b JB |
1723 | /* Cancel the waiton_ptid. */ |
1724 | ecs->waiton_ptid = pid_to_ptid (-1); | |
65e82032 | 1725 | break; |
b83266a0 | 1726 | |
488f131b | 1727 | case infwait_normal_state: |
527159b7 | 1728 | if (debug_infrun) |
8a9de0e4 | 1729 | fprintf_unfiltered (gdb_stdlog, "infrun: infwait_normal_state\n"); |
d983da9c DJ |
1730 | break; |
1731 | ||
1732 | case infwait_step_watch_state: | |
1733 | if (debug_infrun) | |
1734 | fprintf_unfiltered (gdb_stdlog, | |
1735 | "infrun: infwait_step_watch_state\n"); | |
1736 | ||
1737 | stepped_after_stopped_by_watchpoint = 1; | |
488f131b | 1738 | break; |
b83266a0 | 1739 | |
488f131b | 1740 | case infwait_nonstep_watch_state: |
527159b7 | 1741 | if (debug_infrun) |
8a9de0e4 AC |
1742 | fprintf_unfiltered (gdb_stdlog, |
1743 | "infrun: infwait_nonstep_watch_state\n"); | |
488f131b | 1744 | insert_breakpoints (); |
c906108c | 1745 | |
488f131b JB |
1746 | /* FIXME-maybe: is this cleaner than setting a flag? Does it |
1747 | handle things like signals arriving and other things happening | |
1748 | in combination correctly? */ | |
1749 | stepped_after_stopped_by_watchpoint = 1; | |
1750 | break; | |
65e82032 AC |
1751 | |
1752 | default: | |
e2e0b3e5 | 1753 | internal_error (__FILE__, __LINE__, _("bad switch")); |
488f131b JB |
1754 | } |
1755 | ecs->infwait_state = infwait_normal_state; | |
c906108c | 1756 | |
35f196d9 | 1757 | reinit_frame_cache (); |
c906108c | 1758 | |
488f131b | 1759 | /* If it's a new process, add it to the thread database */ |
c906108c | 1760 | |
488f131b | 1761 | ecs->new_thread_event = (!ptid_equal (ecs->ptid, inferior_ptid) |
b9b5d7ea | 1762 | && !ptid_equal (ecs->ptid, minus_one_ptid) |
488f131b JB |
1763 | && !in_thread_list (ecs->ptid)); |
1764 | ||
1765 | if (ecs->ws.kind != TARGET_WAITKIND_EXITED | |
1766 | && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED && ecs->new_thread_event) | |
93815fbf | 1767 | add_thread (ecs->ptid); |
c906108c | 1768 | |
488f131b JB |
1769 | switch (ecs->ws.kind) |
1770 | { | |
1771 | case TARGET_WAITKIND_LOADED: | |
527159b7 | 1772 | if (debug_infrun) |
8a9de0e4 | 1773 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_LOADED\n"); |
b0f4b84b DJ |
1774 | /* Ignore gracefully during startup of the inferior, as it might |
1775 | be the shell which has just loaded some objects, otherwise | |
1776 | add the symbols for the newly loaded objects. Also ignore at | |
1777 | the beginning of an attach or remote session; we will query | |
1778 | the full list of libraries once the connection is | |
1779 | established. */ | |
c0236d92 | 1780 | if (stop_soon == NO_STOP_QUIETLY) |
488f131b | 1781 | { |
488f131b JB |
1782 | /* Check for any newly added shared libraries if we're |
1783 | supposed to be adding them automatically. Switch | |
1784 | terminal for any messages produced by | |
1785 | breakpoint_re_set. */ | |
1786 | target_terminal_ours_for_output (); | |
aff6338a | 1787 | /* NOTE: cagney/2003-11-25: Make certain that the target |
8fb3e588 AC |
1788 | stack's section table is kept up-to-date. Architectures, |
1789 | (e.g., PPC64), use the section table to perform | |
1790 | operations such as address => section name and hence | |
1791 | require the table to contain all sections (including | |
1792 | those found in shared libraries). */ | |
aff6338a | 1793 | /* NOTE: cagney/2003-11-25: Pass current_target and not |
8fb3e588 AC |
1794 | exec_ops to SOLIB_ADD. This is because current GDB is |
1795 | only tooled to propagate section_table changes out from | |
1796 | the "current_target" (see target_resize_to_sections), and | |
1797 | not up from the exec stratum. This, of course, isn't | |
1798 | right. "infrun.c" should only interact with the | |
1799 | exec/process stratum, instead relying on the target stack | |
1800 | to propagate relevant changes (stop, section table | |
1801 | changed, ...) up to other layers. */ | |
b0f4b84b | 1802 | #ifdef SOLIB_ADD |
aff6338a | 1803 | SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add); |
b0f4b84b DJ |
1804 | #else |
1805 | solib_add (NULL, 0, ¤t_target, auto_solib_add); | |
1806 | #endif | |
488f131b JB |
1807 | target_terminal_inferior (); |
1808 | ||
b0f4b84b DJ |
1809 | /* If requested, stop when the dynamic linker notifies |
1810 | gdb of events. This allows the user to get control | |
1811 | and place breakpoints in initializer routines for | |
1812 | dynamically loaded objects (among other things). */ | |
1813 | if (stop_on_solib_events) | |
1814 | { | |
1815 | stop_stepping (ecs); | |
1816 | return; | |
1817 | } | |
1818 | ||
1819 | /* NOTE drow/2007-05-11: This might be a good place to check | |
1820 | for "catch load". */ | |
488f131b | 1821 | } |
b0f4b84b DJ |
1822 | |
1823 | /* If we are skipping through a shell, or through shared library | |
1824 | loading that we aren't interested in, resume the program. If | |
1825 | we're running the program normally, also resume. But stop if | |
1826 | we're attaching or setting up a remote connection. */ | |
1827 | if (stop_soon == STOP_QUIETLY || stop_soon == NO_STOP_QUIETLY) | |
1828 | { | |
74960c60 VP |
1829 | /* Loading of shared libraries might have changed breakpoint |
1830 | addresses. Make sure new breakpoints are inserted. */ | |
0b02b92d UW |
1831 | if (stop_soon == NO_STOP_QUIETLY |
1832 | && !breakpoints_always_inserted_mode ()) | |
74960c60 | 1833 | insert_breakpoints (); |
b0f4b84b DJ |
1834 | resume (0, TARGET_SIGNAL_0); |
1835 | prepare_to_wait (ecs); | |
1836 | return; | |
1837 | } | |
1838 | ||
1839 | break; | |
c5aa993b | 1840 | |
488f131b | 1841 | case TARGET_WAITKIND_SPURIOUS: |
527159b7 | 1842 | if (debug_infrun) |
8a9de0e4 | 1843 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SPURIOUS\n"); |
488f131b JB |
1844 | resume (0, TARGET_SIGNAL_0); |
1845 | prepare_to_wait (ecs); | |
1846 | return; | |
c5aa993b | 1847 | |
488f131b | 1848 | case TARGET_WAITKIND_EXITED: |
527159b7 | 1849 | if (debug_infrun) |
8a9de0e4 | 1850 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_EXITED\n"); |
488f131b JB |
1851 | target_terminal_ours (); /* Must do this before mourn anyway */ |
1852 | print_stop_reason (EXITED, ecs->ws.value.integer); | |
1853 | ||
1854 | /* Record the exit code in the convenience variable $_exitcode, so | |
1855 | that the user can inspect this again later. */ | |
1856 | set_internalvar (lookup_internalvar ("_exitcode"), | |
1857 | value_from_longest (builtin_type_int, | |
1858 | (LONGEST) ecs->ws.value.integer)); | |
1859 | gdb_flush (gdb_stdout); | |
1860 | target_mourn_inferior (); | |
1c0fdd0e | 1861 | singlestep_breakpoints_inserted_p = 0; |
488f131b JB |
1862 | stop_print_frame = 0; |
1863 | stop_stepping (ecs); | |
1864 | return; | |
c5aa993b | 1865 | |
488f131b | 1866 | case TARGET_WAITKIND_SIGNALLED: |
527159b7 | 1867 | if (debug_infrun) |
8a9de0e4 | 1868 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SIGNALLED\n"); |
488f131b JB |
1869 | stop_print_frame = 0; |
1870 | stop_signal = ecs->ws.value.sig; | |
1871 | target_terminal_ours (); /* Must do this before mourn anyway */ | |
c5aa993b | 1872 | |
488f131b JB |
1873 | /* Note: By definition of TARGET_WAITKIND_SIGNALLED, we shouldn't |
1874 | reach here unless the inferior is dead. However, for years | |
1875 | target_kill() was called here, which hints that fatal signals aren't | |
1876 | really fatal on some systems. If that's true, then some changes | |
1877 | may be needed. */ | |
1878 | target_mourn_inferior (); | |
c906108c | 1879 | |
488f131b | 1880 | print_stop_reason (SIGNAL_EXITED, stop_signal); |
1c0fdd0e | 1881 | singlestep_breakpoints_inserted_p = 0; |
488f131b JB |
1882 | stop_stepping (ecs); |
1883 | return; | |
c906108c | 1884 | |
488f131b JB |
1885 | /* The following are the only cases in which we keep going; |
1886 | the above cases end in a continue or goto. */ | |
1887 | case TARGET_WAITKIND_FORKED: | |
deb3b17b | 1888 | case TARGET_WAITKIND_VFORKED: |
527159b7 | 1889 | if (debug_infrun) |
8a9de0e4 | 1890 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_FORKED\n"); |
488f131b JB |
1891 | stop_signal = TARGET_SIGNAL_TRAP; |
1892 | pending_follow.kind = ecs->ws.kind; | |
1893 | ||
8e7d2c16 DJ |
1894 | pending_follow.fork_event.parent_pid = PIDGET (ecs->ptid); |
1895 | pending_follow.fork_event.child_pid = ecs->ws.value.related_pid; | |
c906108c | 1896 | |
5a2901d9 DJ |
1897 | if (!ptid_equal (ecs->ptid, inferior_ptid)) |
1898 | { | |
1899 | context_switch (ecs); | |
35f196d9 | 1900 | reinit_frame_cache (); |
5a2901d9 DJ |
1901 | } |
1902 | ||
488f131b | 1903 | stop_pc = read_pc (); |
675bf4cb | 1904 | |
d983da9c | 1905 | stop_bpstat = bpstat_stop_status (stop_pc, ecs->ptid); |
675bf4cb | 1906 | |
488f131b | 1907 | ecs->random_signal = !bpstat_explains_signal (stop_bpstat); |
04e68871 DJ |
1908 | |
1909 | /* If no catchpoint triggered for this, then keep going. */ | |
1910 | if (ecs->random_signal) | |
1911 | { | |
1912 | stop_signal = TARGET_SIGNAL_0; | |
1913 | keep_going (ecs); | |
1914 | return; | |
1915 | } | |
488f131b JB |
1916 | goto process_event_stop_test; |
1917 | ||
1918 | case TARGET_WAITKIND_EXECD: | |
527159b7 | 1919 | if (debug_infrun) |
fc5261f2 | 1920 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_EXECD\n"); |
488f131b JB |
1921 | stop_signal = TARGET_SIGNAL_TRAP; |
1922 | ||
488f131b JB |
1923 | pending_follow.execd_pathname = |
1924 | savestring (ecs->ws.value.execd_pathname, | |
1925 | strlen (ecs->ws.value.execd_pathname)); | |
1926 | ||
488f131b JB |
1927 | /* This causes the eventpoints and symbol table to be reset. Must |
1928 | do this now, before trying to determine whether to stop. */ | |
1929 | follow_exec (PIDGET (inferior_ptid), pending_follow.execd_pathname); | |
1930 | xfree (pending_follow.execd_pathname); | |
c906108c | 1931 | |
515630c5 | 1932 | stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid)); |
488f131b JB |
1933 | ecs->saved_inferior_ptid = inferior_ptid; |
1934 | inferior_ptid = ecs->ptid; | |
675bf4cb | 1935 | |
d983da9c | 1936 | stop_bpstat = bpstat_stop_status (stop_pc, ecs->ptid); |
675bf4cb | 1937 | |
488f131b JB |
1938 | ecs->random_signal = !bpstat_explains_signal (stop_bpstat); |
1939 | inferior_ptid = ecs->saved_inferior_ptid; | |
04e68871 | 1940 | |
5a2901d9 DJ |
1941 | if (!ptid_equal (ecs->ptid, inferior_ptid)) |
1942 | { | |
1943 | context_switch (ecs); | |
35f196d9 | 1944 | reinit_frame_cache (); |
5a2901d9 DJ |
1945 | } |
1946 | ||
04e68871 DJ |
1947 | /* If no catchpoint triggered for this, then keep going. */ |
1948 | if (ecs->random_signal) | |
1949 | { | |
1950 | stop_signal = TARGET_SIGNAL_0; | |
1951 | keep_going (ecs); | |
1952 | return; | |
1953 | } | |
488f131b JB |
1954 | goto process_event_stop_test; |
1955 | ||
b4dc5ffa MK |
1956 | /* Be careful not to try to gather much state about a thread |
1957 | that's in a syscall. It's frequently a losing proposition. */ | |
488f131b | 1958 | case TARGET_WAITKIND_SYSCALL_ENTRY: |
527159b7 | 1959 | if (debug_infrun) |
8a9de0e4 | 1960 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SYSCALL_ENTRY\n"); |
488f131b JB |
1961 | resume (0, TARGET_SIGNAL_0); |
1962 | prepare_to_wait (ecs); | |
1963 | return; | |
c906108c | 1964 | |
488f131b JB |
1965 | /* Before examining the threads further, step this thread to |
1966 | get it entirely out of the syscall. (We get notice of the | |
1967 | event when the thread is just on the verge of exiting a | |
1968 | syscall. Stepping one instruction seems to get it back | |
b4dc5ffa | 1969 | into user code.) */ |
488f131b | 1970 | case TARGET_WAITKIND_SYSCALL_RETURN: |
527159b7 | 1971 | if (debug_infrun) |
8a9de0e4 | 1972 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SYSCALL_RETURN\n"); |
488f131b | 1973 | target_resume (ecs->ptid, 1, TARGET_SIGNAL_0); |
488f131b JB |
1974 | prepare_to_wait (ecs); |
1975 | return; | |
c906108c | 1976 | |
488f131b | 1977 | case TARGET_WAITKIND_STOPPED: |
527159b7 | 1978 | if (debug_infrun) |
8a9de0e4 | 1979 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_STOPPED\n"); |
488f131b JB |
1980 | stop_signal = ecs->ws.value.sig; |
1981 | break; | |
c906108c | 1982 | |
488f131b JB |
1983 | /* We had an event in the inferior, but we are not interested |
1984 | in handling it at this level. The lower layers have already | |
8e7d2c16 | 1985 | done what needs to be done, if anything. |
8fb3e588 AC |
1986 | |
1987 | One of the possible circumstances for this is when the | |
1988 | inferior produces output for the console. The inferior has | |
1989 | not stopped, and we are ignoring the event. Another possible | |
1990 | circumstance is any event which the lower level knows will be | |
1991 | reported multiple times without an intervening resume. */ | |
488f131b | 1992 | case TARGET_WAITKIND_IGNORE: |
527159b7 | 1993 | if (debug_infrun) |
8a9de0e4 | 1994 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_IGNORE\n"); |
8e7d2c16 | 1995 | prepare_to_wait (ecs); |
488f131b JB |
1996 | return; |
1997 | } | |
c906108c | 1998 | |
488f131b JB |
1999 | /* We may want to consider not doing a resume here in order to give |
2000 | the user a chance to play with the new thread. It might be good | |
2001 | to make that a user-settable option. */ | |
c906108c | 2002 | |
488f131b JB |
2003 | /* At this point, all threads are stopped (happens automatically in |
2004 | either the OS or the native code). Therefore we need to continue | |
2005 | all threads in order to make progress. */ | |
2006 | if (ecs->new_thread_event) | |
2007 | { | |
2008 | target_resume (RESUME_ALL, 0, TARGET_SIGNAL_0); | |
2009 | prepare_to_wait (ecs); | |
2010 | return; | |
2011 | } | |
c906108c | 2012 | |
237fc4c9 PA |
2013 | /* Do we need to clean up the state of a thread that has completed a |
2014 | displaced single-step? (Doing so usually affects the PC, so do | |
2015 | it here, before we set stop_pc.) */ | |
2016 | displaced_step_fixup (ecs->ptid, stop_signal); | |
2017 | ||
515630c5 | 2018 | stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid)); |
488f131b | 2019 | |
527159b7 | 2020 | if (debug_infrun) |
237fc4c9 PA |
2021 | { |
2022 | fprintf_unfiltered (gdb_stdlog, "infrun: stop_pc = 0x%s\n", | |
2023 | paddr_nz (stop_pc)); | |
2024 | if (STOPPED_BY_WATCHPOINT (&ecs->ws)) | |
2025 | { | |
2026 | CORE_ADDR addr; | |
2027 | fprintf_unfiltered (gdb_stdlog, "infrun: stopped by watchpoint\n"); | |
2028 | ||
2029 | if (target_stopped_data_address (¤t_target, &addr)) | |
2030 | fprintf_unfiltered (gdb_stdlog, | |
2031 | "infrun: stopped data address = 0x%s\n", | |
2032 | paddr_nz (addr)); | |
2033 | else | |
2034 | fprintf_unfiltered (gdb_stdlog, | |
2035 | "infrun: (no data address available)\n"); | |
2036 | } | |
2037 | } | |
527159b7 | 2038 | |
9f976b41 DJ |
2039 | if (stepping_past_singlestep_breakpoint) |
2040 | { | |
1c0fdd0e | 2041 | gdb_assert (singlestep_breakpoints_inserted_p); |
9f976b41 DJ |
2042 | gdb_assert (ptid_equal (singlestep_ptid, ecs->ptid)); |
2043 | gdb_assert (!ptid_equal (singlestep_ptid, saved_singlestep_ptid)); | |
2044 | ||
2045 | stepping_past_singlestep_breakpoint = 0; | |
2046 | ||
2047 | /* We've either finished single-stepping past the single-step | |
8fb3e588 AC |
2048 | breakpoint, or stopped for some other reason. It would be nice if |
2049 | we could tell, but we can't reliably. */ | |
9f976b41 | 2050 | if (stop_signal == TARGET_SIGNAL_TRAP) |
8fb3e588 | 2051 | { |
527159b7 | 2052 | if (debug_infrun) |
8a9de0e4 | 2053 | fprintf_unfiltered (gdb_stdlog, "infrun: stepping_past_singlestep_breakpoint\n"); |
9f976b41 | 2054 | /* Pull the single step breakpoints out of the target. */ |
e0cd558a | 2055 | remove_single_step_breakpoints (); |
9f976b41 DJ |
2056 | singlestep_breakpoints_inserted_p = 0; |
2057 | ||
2058 | ecs->random_signal = 0; | |
2059 | ||
2060 | ecs->ptid = saved_singlestep_ptid; | |
2061 | context_switch (ecs); | |
9a4105ab AC |
2062 | if (deprecated_context_hook) |
2063 | deprecated_context_hook (pid_to_thread_id (ecs->ptid)); | |
9f976b41 DJ |
2064 | |
2065 | resume (1, TARGET_SIGNAL_0); | |
2066 | prepare_to_wait (ecs); | |
2067 | return; | |
2068 | } | |
2069 | } | |
2070 | ||
2071 | stepping_past_singlestep_breakpoint = 0; | |
2072 | ||
ca67fcb8 | 2073 | if (!ptid_equal (deferred_step_ptid, null_ptid)) |
6a6b96b9 | 2074 | { |
6a6b96b9 UW |
2075 | /* If we stopped for some other reason than single-stepping, ignore |
2076 | the fact that we were supposed to switch back. */ | |
2077 | if (stop_signal == TARGET_SIGNAL_TRAP) | |
2078 | { | |
2079 | if (debug_infrun) | |
2080 | fprintf_unfiltered (gdb_stdlog, | |
ca67fcb8 | 2081 | "infrun: handling deferred step\n"); |
6a6b96b9 UW |
2082 | |
2083 | /* Pull the single step breakpoints out of the target. */ | |
2084 | if (singlestep_breakpoints_inserted_p) | |
2085 | { | |
2086 | remove_single_step_breakpoints (); | |
2087 | singlestep_breakpoints_inserted_p = 0; | |
2088 | } | |
2089 | ||
2090 | /* Note: We do not call context_switch at this point, as the | |
2091 | context is already set up for stepping the original thread. */ | |
ca67fcb8 VP |
2092 | switch_to_thread (deferred_step_ptid); |
2093 | deferred_step_ptid = null_ptid; | |
6a6b96b9 UW |
2094 | /* Suppress spurious "Switching to ..." message. */ |
2095 | previous_inferior_ptid = inferior_ptid; | |
2096 | ||
2097 | resume (1, TARGET_SIGNAL_0); | |
2098 | prepare_to_wait (ecs); | |
2099 | return; | |
2100 | } | |
ca67fcb8 VP |
2101 | |
2102 | deferred_step_ptid = null_ptid; | |
6a6b96b9 UW |
2103 | } |
2104 | ||
488f131b JB |
2105 | /* See if a thread hit a thread-specific breakpoint that was meant for |
2106 | another thread. If so, then step that thread past the breakpoint, | |
2107 | and continue it. */ | |
2108 | ||
2109 | if (stop_signal == TARGET_SIGNAL_TRAP) | |
2110 | { | |
9f976b41 DJ |
2111 | int thread_hop_needed = 0; |
2112 | ||
f8d40ec8 JB |
2113 | /* Check if a regular breakpoint has been hit before checking |
2114 | for a potential single step breakpoint. Otherwise, GDB will | |
2115 | not see this breakpoint hit when stepping onto breakpoints. */ | |
c36b740a | 2116 | if (regular_breakpoint_inserted_here_p (stop_pc)) |
488f131b | 2117 | { |
c5aa993b | 2118 | ecs->random_signal = 0; |
4fa8626c | 2119 | if (!breakpoint_thread_match (stop_pc, ecs->ptid)) |
9f976b41 DJ |
2120 | thread_hop_needed = 1; |
2121 | } | |
1c0fdd0e | 2122 | else if (singlestep_breakpoints_inserted_p) |
9f976b41 | 2123 | { |
fd48f117 DJ |
2124 | /* We have not context switched yet, so this should be true |
2125 | no matter which thread hit the singlestep breakpoint. */ | |
2126 | gdb_assert (ptid_equal (inferior_ptid, singlestep_ptid)); | |
2127 | if (debug_infrun) | |
2128 | fprintf_unfiltered (gdb_stdlog, "infrun: software single step " | |
2129 | "trap for %s\n", | |
2130 | target_pid_to_str (ecs->ptid)); | |
2131 | ||
9f976b41 DJ |
2132 | ecs->random_signal = 0; |
2133 | /* The call to in_thread_list is necessary because PTIDs sometimes | |
2134 | change when we go from single-threaded to multi-threaded. If | |
2135 | the singlestep_ptid is still in the list, assume that it is | |
2136 | really different from ecs->ptid. */ | |
2137 | if (!ptid_equal (singlestep_ptid, ecs->ptid) | |
2138 | && in_thread_list (singlestep_ptid)) | |
2139 | { | |
fd48f117 DJ |
2140 | /* If the PC of the thread we were trying to single-step |
2141 | has changed, discard this event (which we were going | |
2142 | to ignore anyway), and pretend we saw that thread | |
2143 | trap. This prevents us continuously moving the | |
2144 | single-step breakpoint forward, one instruction at a | |
2145 | time. If the PC has changed, then the thread we were | |
2146 | trying to single-step has trapped or been signalled, | |
2147 | but the event has not been reported to GDB yet. | |
2148 | ||
2149 | There might be some cases where this loses signal | |
2150 | information, if a signal has arrived at exactly the | |
2151 | same time that the PC changed, but this is the best | |
2152 | we can do with the information available. Perhaps we | |
2153 | should arrange to report all events for all threads | |
2154 | when they stop, or to re-poll the remote looking for | |
2155 | this particular thread (i.e. temporarily enable | |
2156 | schedlock). */ | |
515630c5 UW |
2157 | |
2158 | CORE_ADDR new_singlestep_pc | |
2159 | = regcache_read_pc (get_thread_regcache (singlestep_ptid)); | |
2160 | ||
2161 | if (new_singlestep_pc != singlestep_pc) | |
fd48f117 DJ |
2162 | { |
2163 | if (debug_infrun) | |
2164 | fprintf_unfiltered (gdb_stdlog, "infrun: unexpected thread," | |
2165 | " but expected thread advanced also\n"); | |
2166 | ||
2167 | /* The current context still belongs to | |
2168 | singlestep_ptid. Don't swap here, since that's | |
2169 | the context we want to use. Just fudge our | |
2170 | state and continue. */ | |
2171 | ecs->ptid = singlestep_ptid; | |
515630c5 | 2172 | stop_pc = new_singlestep_pc; |
fd48f117 DJ |
2173 | } |
2174 | else | |
2175 | { | |
2176 | if (debug_infrun) | |
2177 | fprintf_unfiltered (gdb_stdlog, | |
2178 | "infrun: unexpected thread\n"); | |
2179 | ||
2180 | thread_hop_needed = 1; | |
2181 | stepping_past_singlestep_breakpoint = 1; | |
2182 | saved_singlestep_ptid = singlestep_ptid; | |
2183 | } | |
9f976b41 DJ |
2184 | } |
2185 | } | |
2186 | ||
2187 | if (thread_hop_needed) | |
8fb3e588 | 2188 | { |
237fc4c9 | 2189 | int remove_status = 0; |
8fb3e588 | 2190 | |
527159b7 | 2191 | if (debug_infrun) |
8a9de0e4 | 2192 | fprintf_unfiltered (gdb_stdlog, "infrun: thread_hop_needed\n"); |
527159b7 | 2193 | |
8fb3e588 AC |
2194 | /* Saw a breakpoint, but it was hit by the wrong thread. |
2195 | Just continue. */ | |
2196 | ||
1c0fdd0e | 2197 | if (singlestep_breakpoints_inserted_p) |
488f131b | 2198 | { |
8fb3e588 | 2199 | /* Pull the single step breakpoints out of the target. */ |
e0cd558a | 2200 | remove_single_step_breakpoints (); |
8fb3e588 AC |
2201 | singlestep_breakpoints_inserted_p = 0; |
2202 | } | |
2203 | ||
237fc4c9 PA |
2204 | /* If the arch can displace step, don't remove the |
2205 | breakpoints. */ | |
2206 | if (!use_displaced_stepping (current_gdbarch)) | |
2207 | remove_status = remove_breakpoints (); | |
2208 | ||
8fb3e588 AC |
2209 | /* Did we fail to remove breakpoints? If so, try |
2210 | to set the PC past the bp. (There's at least | |
2211 | one situation in which we can fail to remove | |
2212 | the bp's: On HP-UX's that use ttrace, we can't | |
2213 | change the address space of a vforking child | |
2214 | process until the child exits (well, okay, not | |
2215 | then either :-) or execs. */ | |
2216 | if (remove_status != 0) | |
9d9cd7ac | 2217 | error (_("Cannot step over breakpoint hit in wrong thread")); |
8fb3e588 AC |
2218 | else |
2219 | { /* Single step */ | |
8fb3e588 AC |
2220 | if (!ptid_equal (inferior_ptid, ecs->ptid)) |
2221 | context_switch (ecs); | |
2222 | ecs->waiton_ptid = ecs->ptid; | |
2223 | ecs->wp = &(ecs->ws); | |
ca67fcb8 | 2224 | ecs->stepping_over_breakpoint = 1; |
8fb3e588 AC |
2225 | |
2226 | ecs->infwait_state = infwait_thread_hop_state; | |
2227 | keep_going (ecs); | |
2228 | registers_changed (); | |
2229 | return; | |
2230 | } | |
488f131b | 2231 | } |
1c0fdd0e | 2232 | else if (singlestep_breakpoints_inserted_p) |
8fb3e588 AC |
2233 | { |
2234 | sw_single_step_trap_p = 1; | |
2235 | ecs->random_signal = 0; | |
2236 | } | |
488f131b JB |
2237 | } |
2238 | else | |
2239 | ecs->random_signal = 1; | |
c906108c | 2240 | |
488f131b | 2241 | /* See if something interesting happened to the non-current thread. If |
b40c7d58 DJ |
2242 | so, then switch to that thread. */ |
2243 | if (!ptid_equal (ecs->ptid, inferior_ptid)) | |
488f131b | 2244 | { |
527159b7 | 2245 | if (debug_infrun) |
8a9de0e4 | 2246 | fprintf_unfiltered (gdb_stdlog, "infrun: context switch\n"); |
527159b7 | 2247 | |
488f131b | 2248 | context_switch (ecs); |
c5aa993b | 2249 | |
9a4105ab AC |
2250 | if (deprecated_context_hook) |
2251 | deprecated_context_hook (pid_to_thread_id (ecs->ptid)); | |
488f131b | 2252 | } |
c906108c | 2253 | |
1c0fdd0e | 2254 | if (singlestep_breakpoints_inserted_p) |
488f131b JB |
2255 | { |
2256 | /* Pull the single step breakpoints out of the target. */ | |
e0cd558a | 2257 | remove_single_step_breakpoints (); |
488f131b JB |
2258 | singlestep_breakpoints_inserted_p = 0; |
2259 | } | |
c906108c | 2260 | |
d983da9c DJ |
2261 | if (stepped_after_stopped_by_watchpoint) |
2262 | stopped_by_watchpoint = 0; | |
2263 | else | |
2264 | stopped_by_watchpoint = watchpoints_triggered (&ecs->ws); | |
2265 | ||
2266 | /* If necessary, step over this watchpoint. We'll be back to display | |
2267 | it in a moment. */ | |
2268 | if (stopped_by_watchpoint | |
2269 | && (HAVE_STEPPABLE_WATCHPOINT | |
2270 | || gdbarch_have_nonsteppable_watchpoint (current_gdbarch))) | |
488f131b | 2271 | { |
488f131b JB |
2272 | /* At this point, we are stopped at an instruction which has |
2273 | attempted to write to a piece of memory under control of | |
2274 | a watchpoint. The instruction hasn't actually executed | |
2275 | yet. If we were to evaluate the watchpoint expression | |
2276 | now, we would get the old value, and therefore no change | |
2277 | would seem to have occurred. | |
2278 | ||
2279 | In order to make watchpoints work `right', we really need | |
2280 | to complete the memory write, and then evaluate the | |
d983da9c DJ |
2281 | watchpoint expression. We do this by single-stepping the |
2282 | target. | |
2283 | ||
2284 | It may not be necessary to disable the watchpoint to stop over | |
2285 | it. For example, the PA can (with some kernel cooperation) | |
2286 | single step over a watchpoint without disabling the watchpoint. | |
2287 | ||
2288 | It is far more common to need to disable a watchpoint to step | |
2289 | the inferior over it. If we have non-steppable watchpoints, | |
2290 | we must disable the current watchpoint; it's simplest to | |
2291 | disable all watchpoints and breakpoints. */ | |
2292 | ||
2293 | if (!HAVE_STEPPABLE_WATCHPOINT) | |
2294 | remove_breakpoints (); | |
488f131b JB |
2295 | registers_changed (); |
2296 | target_resume (ecs->ptid, 1, TARGET_SIGNAL_0); /* Single step */ | |
488f131b | 2297 | ecs->waiton_ptid = ecs->ptid; |
d983da9c DJ |
2298 | if (HAVE_STEPPABLE_WATCHPOINT) |
2299 | ecs->infwait_state = infwait_step_watch_state; | |
2300 | else | |
2301 | ecs->infwait_state = infwait_nonstep_watch_state; | |
488f131b JB |
2302 | prepare_to_wait (ecs); |
2303 | return; | |
2304 | } | |
2305 | ||
488f131b JB |
2306 | ecs->stop_func_start = 0; |
2307 | ecs->stop_func_end = 0; | |
2308 | ecs->stop_func_name = 0; | |
2309 | /* Don't care about return value; stop_func_start and stop_func_name | |
2310 | will both be 0 if it doesn't work. */ | |
2311 | find_pc_partial_function (stop_pc, &ecs->stop_func_name, | |
2312 | &ecs->stop_func_start, &ecs->stop_func_end); | |
cbf3b44a UW |
2313 | ecs->stop_func_start |
2314 | += gdbarch_deprecated_function_start_offset (current_gdbarch); | |
ca67fcb8 | 2315 | ecs->stepping_over_breakpoint = 0; |
488f131b JB |
2316 | bpstat_clear (&stop_bpstat); |
2317 | stop_step = 0; | |
488f131b JB |
2318 | stop_print_frame = 1; |
2319 | ecs->random_signal = 0; | |
2320 | stopped_by_random_signal = 0; | |
488f131b | 2321 | |
3352ef37 | 2322 | if (stop_signal == TARGET_SIGNAL_TRAP |
ca67fcb8 | 2323 | && stepping_over_breakpoint |
3352ef37 AC |
2324 | && gdbarch_single_step_through_delay_p (current_gdbarch) |
2325 | && currently_stepping (ecs)) | |
2326 | { | |
b50d7442 | 2327 | /* We're trying to step off a breakpoint. Turns out that we're |
3352ef37 AC |
2328 | also on an instruction that needs to be stepped multiple |
2329 | times before it's been fully executing. E.g., architectures | |
2330 | with a delay slot. It needs to be stepped twice, once for | |
2331 | the instruction and once for the delay slot. */ | |
2332 | int step_through_delay | |
2333 | = gdbarch_single_step_through_delay (current_gdbarch, | |
2334 | get_current_frame ()); | |
527159b7 | 2335 | if (debug_infrun && step_through_delay) |
8a9de0e4 | 2336 | fprintf_unfiltered (gdb_stdlog, "infrun: step through delay\n"); |
3352ef37 AC |
2337 | if (step_range_end == 0 && step_through_delay) |
2338 | { | |
2339 | /* The user issued a continue when stopped at a breakpoint. | |
2340 | Set up for another trap and get out of here. */ | |
ca67fcb8 | 2341 | ecs->stepping_over_breakpoint = 1; |
3352ef37 AC |
2342 | keep_going (ecs); |
2343 | return; | |
2344 | } | |
2345 | else if (step_through_delay) | |
2346 | { | |
2347 | /* The user issued a step when stopped at a breakpoint. | |
2348 | Maybe we should stop, maybe we should not - the delay | |
2349 | slot *might* correspond to a line of source. In any | |
ca67fcb8 VP |
2350 | case, don't decide that here, just set |
2351 | ecs->stepping_over_breakpoint, making sure we | |
2352 | single-step again before breakpoints are re-inserted. */ | |
2353 | ecs->stepping_over_breakpoint = 1; | |
3352ef37 AC |
2354 | } |
2355 | } | |
2356 | ||
488f131b JB |
2357 | /* Look at the cause of the stop, and decide what to do. |
2358 | The alternatives are: | |
2359 | 1) break; to really stop and return to the debugger, | |
2360 | 2) drop through to start up again | |
ca67fcb8 | 2361 | (set ecs->stepping_over_breakpoint to 1 to single step once) |
488f131b JB |
2362 | 3) set ecs->random_signal to 1, and the decision between 1 and 2 |
2363 | will be made according to the signal handling tables. */ | |
2364 | ||
2365 | /* First, distinguish signals caused by the debugger from signals | |
03cebad2 MK |
2366 | that have to do with the program's own actions. Note that |
2367 | breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending | |
2368 | on the operating system version. Here we detect when a SIGILL or | |
2369 | SIGEMT is really a breakpoint and change it to SIGTRAP. We do | |
2370 | something similar for SIGSEGV, since a SIGSEGV will be generated | |
2371 | when we're trying to execute a breakpoint instruction on a | |
2372 | non-executable stack. This happens for call dummy breakpoints | |
2373 | for architectures like SPARC that place call dummies on the | |
237fc4c9 | 2374 | stack. |
488f131b | 2375 | |
237fc4c9 PA |
2376 | If we're doing a displaced step past a breakpoint, then the |
2377 | breakpoint is always inserted at the original instruction; | |
2378 | non-standard signals can't be explained by the breakpoint. */ | |
488f131b | 2379 | if (stop_signal == TARGET_SIGNAL_TRAP |
237fc4c9 PA |
2380 | || (! stepping_over_breakpoint |
2381 | && breakpoint_inserted_here_p (stop_pc) | |
8fb3e588 AC |
2382 | && (stop_signal == TARGET_SIGNAL_ILL |
2383 | || stop_signal == TARGET_SIGNAL_SEGV | |
2384 | || stop_signal == TARGET_SIGNAL_EMT)) | |
b0f4b84b DJ |
2385 | || stop_soon == STOP_QUIETLY || stop_soon == STOP_QUIETLY_NO_SIGSTOP |
2386 | || stop_soon == STOP_QUIETLY_REMOTE) | |
488f131b JB |
2387 | { |
2388 | if (stop_signal == TARGET_SIGNAL_TRAP && stop_after_trap) | |
2389 | { | |
527159b7 | 2390 | if (debug_infrun) |
8a9de0e4 | 2391 | fprintf_unfiltered (gdb_stdlog, "infrun: stopped\n"); |
488f131b JB |
2392 | stop_print_frame = 0; |
2393 | stop_stepping (ecs); | |
2394 | return; | |
2395 | } | |
c54cfec8 EZ |
2396 | |
2397 | /* This is originated from start_remote(), start_inferior() and | |
2398 | shared libraries hook functions. */ | |
b0f4b84b | 2399 | if (stop_soon == STOP_QUIETLY || stop_soon == STOP_QUIETLY_REMOTE) |
488f131b | 2400 | { |
527159b7 | 2401 | if (debug_infrun) |
8a9de0e4 | 2402 | fprintf_unfiltered (gdb_stdlog, "infrun: quietly stopped\n"); |
488f131b JB |
2403 | stop_stepping (ecs); |
2404 | return; | |
2405 | } | |
2406 | ||
c54cfec8 EZ |
2407 | /* This originates from attach_command(). We need to overwrite |
2408 | the stop_signal here, because some kernels don't ignore a | |
a0ef4274 DJ |
2409 | SIGSTOP in a subsequent ptrace(PTRACE_CONT,SIGSTOP) call. |
2410 | See more comments in inferior.h. On the other hand, if we | |
2411 | get a non-SIGSTOP, report it to the user - assume the backend | |
2412 | will handle the SIGSTOP if it should show up later. */ | |
2413 | if (stop_soon == STOP_QUIETLY_NO_SIGSTOP | |
2414 | && stop_signal == TARGET_SIGNAL_STOP) | |
c54cfec8 EZ |
2415 | { |
2416 | stop_stepping (ecs); | |
a0ef4274 | 2417 | stop_signal = TARGET_SIGNAL_0; |
c54cfec8 EZ |
2418 | return; |
2419 | } | |
2420 | ||
fba57f8f VP |
2421 | /* See if there is a breakpoint at the current PC. */ |
2422 | stop_bpstat = bpstat_stop_status (stop_pc, ecs->ptid); | |
2423 | ||
2424 | /* Following in case break condition called a | |
2425 | function. */ | |
2426 | stop_print_frame = 1; | |
488f131b | 2427 | |
73dd234f | 2428 | /* NOTE: cagney/2003-03-29: These two checks for a random signal |
8fb3e588 AC |
2429 | at one stage in the past included checks for an inferior |
2430 | function call's call dummy's return breakpoint. The original | |
2431 | comment, that went with the test, read: | |
73dd234f | 2432 | |
8fb3e588 AC |
2433 | ``End of a stack dummy. Some systems (e.g. Sony news) give |
2434 | another signal besides SIGTRAP, so check here as well as | |
2435 | above.'' | |
73dd234f AC |
2436 | |
2437 | If someone ever tries to get get call dummys on a | |
2438 | non-executable stack to work (where the target would stop | |
03cebad2 MK |
2439 | with something like a SIGSEGV), then those tests might need |
2440 | to be re-instated. Given, however, that the tests were only | |
73dd234f | 2441 | enabled when momentary breakpoints were not being used, I |
03cebad2 MK |
2442 | suspect that it won't be the case. |
2443 | ||
8fb3e588 AC |
2444 | NOTE: kettenis/2004-02-05: Indeed such checks don't seem to |
2445 | be necessary for call dummies on a non-executable stack on | |
2446 | SPARC. */ | |
73dd234f | 2447 | |
488f131b JB |
2448 | if (stop_signal == TARGET_SIGNAL_TRAP) |
2449 | ecs->random_signal | |
2450 | = !(bpstat_explains_signal (stop_bpstat) | |
ca67fcb8 | 2451 | || stepping_over_breakpoint |
488f131b | 2452 | || (step_range_end && step_resume_breakpoint == NULL)); |
488f131b JB |
2453 | else |
2454 | { | |
73dd234f | 2455 | ecs->random_signal = !bpstat_explains_signal (stop_bpstat); |
488f131b JB |
2456 | if (!ecs->random_signal) |
2457 | stop_signal = TARGET_SIGNAL_TRAP; | |
2458 | } | |
2459 | } | |
2460 | ||
2461 | /* When we reach this point, we've pretty much decided | |
2462 | that the reason for stopping must've been a random | |
2463 | (unexpected) signal. */ | |
2464 | ||
2465 | else | |
2466 | ecs->random_signal = 1; | |
488f131b | 2467 | |
04e68871 | 2468 | process_event_stop_test: |
488f131b JB |
2469 | /* For the program's own signals, act according to |
2470 | the signal handling tables. */ | |
2471 | ||
2472 | if (ecs->random_signal) | |
2473 | { | |
2474 | /* Signal not for debugging purposes. */ | |
2475 | int printed = 0; | |
2476 | ||
527159b7 | 2477 | if (debug_infrun) |
8a9de0e4 | 2478 | fprintf_unfiltered (gdb_stdlog, "infrun: random signal %d\n", stop_signal); |
527159b7 | 2479 | |
488f131b JB |
2480 | stopped_by_random_signal = 1; |
2481 | ||
2482 | if (signal_print[stop_signal]) | |
2483 | { | |
2484 | printed = 1; | |
2485 | target_terminal_ours_for_output (); | |
2486 | print_stop_reason (SIGNAL_RECEIVED, stop_signal); | |
2487 | } | |
a0ef4274 | 2488 | if (signal_stop_state (stop_signal)) |
488f131b JB |
2489 | { |
2490 | stop_stepping (ecs); | |
2491 | return; | |
2492 | } | |
2493 | /* If not going to stop, give terminal back | |
2494 | if we took it away. */ | |
2495 | else if (printed) | |
2496 | target_terminal_inferior (); | |
2497 | ||
2498 | /* Clear the signal if it should not be passed. */ | |
2499 | if (signal_program[stop_signal] == 0) | |
2500 | stop_signal = TARGET_SIGNAL_0; | |
2501 | ||
68f53502 | 2502 | if (prev_pc == read_pc () |
74960c60 | 2503 | && stepping_over_breakpoint |
68f53502 AC |
2504 | && step_resume_breakpoint == NULL) |
2505 | { | |
2506 | /* We were just starting a new sequence, attempting to | |
2507 | single-step off of a breakpoint and expecting a SIGTRAP. | |
237fc4c9 | 2508 | Instead this signal arrives. This signal will take us out |
68f53502 AC |
2509 | of the stepping range so GDB needs to remember to, when |
2510 | the signal handler returns, resume stepping off that | |
2511 | breakpoint. */ | |
2512 | /* To simplify things, "continue" is forced to use the same | |
2513 | code paths as single-step - set a breakpoint at the | |
2514 | signal return address and then, once hit, step off that | |
2515 | breakpoint. */ | |
237fc4c9 PA |
2516 | if (debug_infrun) |
2517 | fprintf_unfiltered (gdb_stdlog, | |
2518 | "infrun: signal arrived while stepping over " | |
2519 | "breakpoint\n"); | |
d3169d93 | 2520 | |
44cbf7b5 | 2521 | insert_step_resume_breakpoint_at_frame (get_current_frame ()); |
68f53502 | 2522 | ecs->step_after_step_resume_breakpoint = 1; |
9d799f85 AC |
2523 | keep_going (ecs); |
2524 | return; | |
68f53502 | 2525 | } |
9d799f85 AC |
2526 | |
2527 | if (step_range_end != 0 | |
2528 | && stop_signal != TARGET_SIGNAL_0 | |
2529 | && stop_pc >= step_range_start && stop_pc < step_range_end | |
2530 | && frame_id_eq (get_frame_id (get_current_frame ()), | |
2531 | step_frame_id) | |
2532 | && step_resume_breakpoint == NULL) | |
d303a6c7 AC |
2533 | { |
2534 | /* The inferior is about to take a signal that will take it | |
2535 | out of the single step range. Set a breakpoint at the | |
2536 | current PC (which is presumably where the signal handler | |
2537 | will eventually return) and then allow the inferior to | |
2538 | run free. | |
2539 | ||
2540 | Note that this is only needed for a signal delivered | |
2541 | while in the single-step range. Nested signals aren't a | |
2542 | problem as they eventually all return. */ | |
237fc4c9 PA |
2543 | if (debug_infrun) |
2544 | fprintf_unfiltered (gdb_stdlog, | |
2545 | "infrun: signal may take us out of " | |
2546 | "single-step range\n"); | |
2547 | ||
44cbf7b5 | 2548 | insert_step_resume_breakpoint_at_frame (get_current_frame ()); |
9d799f85 AC |
2549 | keep_going (ecs); |
2550 | return; | |
d303a6c7 | 2551 | } |
9d799f85 AC |
2552 | |
2553 | /* Note: step_resume_breakpoint may be non-NULL. This occures | |
2554 | when either there's a nested signal, or when there's a | |
2555 | pending signal enabled just as the signal handler returns | |
2556 | (leaving the inferior at the step-resume-breakpoint without | |
2557 | actually executing it). Either way continue until the | |
2558 | breakpoint is really hit. */ | |
488f131b JB |
2559 | keep_going (ecs); |
2560 | return; | |
2561 | } | |
2562 | ||
2563 | /* Handle cases caused by hitting a breakpoint. */ | |
2564 | { | |
2565 | CORE_ADDR jmp_buf_pc; | |
2566 | struct bpstat_what what; | |
2567 | ||
2568 | what = bpstat_what (stop_bpstat); | |
2569 | ||
2570 | if (what.call_dummy) | |
2571 | { | |
2572 | stop_stack_dummy = 1; | |
c5aa993b | 2573 | } |
c906108c | 2574 | |
488f131b | 2575 | switch (what.main_action) |
c5aa993b | 2576 | { |
488f131b | 2577 | case BPSTAT_WHAT_SET_LONGJMP_RESUME: |
611c83ae PA |
2578 | /* If we hit the breakpoint at longjmp while stepping, we |
2579 | install a momentary breakpoint at the target of the | |
2580 | jmp_buf. */ | |
2581 | ||
2582 | if (debug_infrun) | |
2583 | fprintf_unfiltered (gdb_stdlog, | |
2584 | "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME\n"); | |
2585 | ||
2586 | ecs->stepping_over_breakpoint = 1; | |
2587 | ||
91104499 | 2588 | if (!gdbarch_get_longjmp_target_p (current_gdbarch) |
60ade65d UW |
2589 | || !gdbarch_get_longjmp_target (current_gdbarch, |
2590 | get_current_frame (), &jmp_buf_pc)) | |
c5aa993b | 2591 | { |
611c83ae PA |
2592 | if (debug_infrun) |
2593 | fprintf_unfiltered (gdb_stdlog, "\ | |
2594 | infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME (!gdbarch_get_longjmp_target)\n"); | |
488f131b | 2595 | keep_going (ecs); |
104c1213 | 2596 | return; |
c5aa993b | 2597 | } |
488f131b | 2598 | |
611c83ae PA |
2599 | /* We're going to replace the current step-resume breakpoint |
2600 | with a longjmp-resume breakpoint. */ | |
488f131b | 2601 | if (step_resume_breakpoint != NULL) |
611c83ae PA |
2602 | delete_step_resume_breakpoint (&step_resume_breakpoint); |
2603 | ||
2604 | /* Insert a breakpoint at resume address. */ | |
2605 | insert_longjmp_resume_breakpoint (jmp_buf_pc); | |
c906108c | 2606 | |
488f131b JB |
2607 | keep_going (ecs); |
2608 | return; | |
c906108c | 2609 | |
488f131b | 2610 | case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME: |
527159b7 | 2611 | if (debug_infrun) |
611c83ae PA |
2612 | fprintf_unfiltered (gdb_stdlog, |
2613 | "infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME\n"); | |
2614 | ||
2615 | gdb_assert (step_resume_breakpoint != NULL); | |
2616 | delete_step_resume_breakpoint (&step_resume_breakpoint); | |
2617 | ||
2618 | stop_step = 1; | |
2619 | print_stop_reason (END_STEPPING_RANGE, 0); | |
2620 | stop_stepping (ecs); | |
2621 | return; | |
488f131b JB |
2622 | |
2623 | case BPSTAT_WHAT_SINGLE: | |
527159b7 | 2624 | if (debug_infrun) |
8802d8ed | 2625 | fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_SINGLE\n"); |
ca67fcb8 | 2626 | ecs->stepping_over_breakpoint = 1; |
488f131b JB |
2627 | /* Still need to check other stuff, at least the case |
2628 | where we are stepping and step out of the right range. */ | |
2629 | break; | |
c906108c | 2630 | |
488f131b | 2631 | case BPSTAT_WHAT_STOP_NOISY: |
527159b7 | 2632 | if (debug_infrun) |
8802d8ed | 2633 | fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STOP_NOISY\n"); |
488f131b | 2634 | stop_print_frame = 1; |
c906108c | 2635 | |
d303a6c7 AC |
2636 | /* We are about to nuke the step_resume_breakpointt via the |
2637 | cleanup chain, so no need to worry about it here. */ | |
c5aa993b | 2638 | |
488f131b JB |
2639 | stop_stepping (ecs); |
2640 | return; | |
c5aa993b | 2641 | |
488f131b | 2642 | case BPSTAT_WHAT_STOP_SILENT: |
527159b7 | 2643 | if (debug_infrun) |
8802d8ed | 2644 | fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STOP_SILENT\n"); |
488f131b | 2645 | stop_print_frame = 0; |
c5aa993b | 2646 | |
d303a6c7 AC |
2647 | /* We are about to nuke the step_resume_breakpoin via the |
2648 | cleanup chain, so no need to worry about it here. */ | |
c5aa993b | 2649 | |
488f131b | 2650 | stop_stepping (ecs); |
e441088d | 2651 | return; |
c5aa993b | 2652 | |
488f131b JB |
2653 | case BPSTAT_WHAT_STEP_RESUME: |
2654 | /* This proably demands a more elegant solution, but, yeah | |
2655 | right... | |
c5aa993b | 2656 | |
488f131b JB |
2657 | This function's use of the simple variable |
2658 | step_resume_breakpoint doesn't seem to accomodate | |
2659 | simultaneously active step-resume bp's, although the | |
2660 | breakpoint list certainly can. | |
c5aa993b | 2661 | |
488f131b JB |
2662 | If we reach here and step_resume_breakpoint is already |
2663 | NULL, then apparently we have multiple active | |
2664 | step-resume bp's. We'll just delete the breakpoint we | |
2665 | stopped at, and carry on. | |
2666 | ||
2667 | Correction: what the code currently does is delete a | |
2668 | step-resume bp, but it makes no effort to ensure that | |
2669 | the one deleted is the one currently stopped at. MVS */ | |
c5aa993b | 2670 | |
527159b7 | 2671 | if (debug_infrun) |
8802d8ed | 2672 | fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STEP_RESUME\n"); |
527159b7 | 2673 | |
488f131b JB |
2674 | if (step_resume_breakpoint == NULL) |
2675 | { | |
2676 | step_resume_breakpoint = | |
2677 | bpstat_find_step_resume_breakpoint (stop_bpstat); | |
2678 | } | |
2679 | delete_step_resume_breakpoint (&step_resume_breakpoint); | |
68f53502 AC |
2680 | if (ecs->step_after_step_resume_breakpoint) |
2681 | { | |
2682 | /* Back when the step-resume breakpoint was inserted, we | |
2683 | were trying to single-step off a breakpoint. Go back | |
2684 | to doing that. */ | |
2685 | ecs->step_after_step_resume_breakpoint = 0; | |
ca67fcb8 | 2686 | ecs->stepping_over_breakpoint = 1; |
68f53502 AC |
2687 | keep_going (ecs); |
2688 | return; | |
2689 | } | |
488f131b JB |
2690 | break; |
2691 | ||
488f131b JB |
2692 | case BPSTAT_WHAT_CHECK_SHLIBS: |
2693 | case BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK: | |
c906108c | 2694 | { |
527159b7 | 2695 | if (debug_infrun) |
8802d8ed | 2696 | fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_CHECK_SHLIBS\n"); |
488f131b JB |
2697 | |
2698 | /* Check for any newly added shared libraries if we're | |
2699 | supposed to be adding them automatically. Switch | |
2700 | terminal for any messages produced by | |
2701 | breakpoint_re_set. */ | |
2702 | target_terminal_ours_for_output (); | |
aff6338a | 2703 | /* NOTE: cagney/2003-11-25: Make certain that the target |
8fb3e588 AC |
2704 | stack's section table is kept up-to-date. Architectures, |
2705 | (e.g., PPC64), use the section table to perform | |
2706 | operations such as address => section name and hence | |
2707 | require the table to contain all sections (including | |
2708 | those found in shared libraries). */ | |
aff6338a | 2709 | /* NOTE: cagney/2003-11-25: Pass current_target and not |
8fb3e588 AC |
2710 | exec_ops to SOLIB_ADD. This is because current GDB is |
2711 | only tooled to propagate section_table changes out from | |
2712 | the "current_target" (see target_resize_to_sections), and | |
2713 | not up from the exec stratum. This, of course, isn't | |
2714 | right. "infrun.c" should only interact with the | |
2715 | exec/process stratum, instead relying on the target stack | |
2716 | to propagate relevant changes (stop, section table | |
2717 | changed, ...) up to other layers. */ | |
a77053c2 | 2718 | #ifdef SOLIB_ADD |
aff6338a | 2719 | SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add); |
a77053c2 MK |
2720 | #else |
2721 | solib_add (NULL, 0, ¤t_target, auto_solib_add); | |
2722 | #endif | |
488f131b JB |
2723 | target_terminal_inferior (); |
2724 | ||
488f131b JB |
2725 | /* If requested, stop when the dynamic linker notifies |
2726 | gdb of events. This allows the user to get control | |
2727 | and place breakpoints in initializer routines for | |
2728 | dynamically loaded objects (among other things). */ | |
877522db | 2729 | if (stop_on_solib_events || stop_stack_dummy) |
d4f3574e | 2730 | { |
488f131b | 2731 | stop_stepping (ecs); |
d4f3574e SS |
2732 | return; |
2733 | } | |
c5aa993b | 2734 | |
488f131b JB |
2735 | /* If we stopped due to an explicit catchpoint, then the |
2736 | (see above) call to SOLIB_ADD pulled in any symbols | |
2737 | from a newly-loaded library, if appropriate. | |
2738 | ||
2739 | We do want the inferior to stop, but not where it is | |
2740 | now, which is in the dynamic linker callback. Rather, | |
2741 | we would like it stop in the user's program, just after | |
2742 | the call that caused this catchpoint to trigger. That | |
2743 | gives the user a more useful vantage from which to | |
2744 | examine their program's state. */ | |
8fb3e588 AC |
2745 | else if (what.main_action |
2746 | == BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK) | |
c906108c | 2747 | { |
488f131b JB |
2748 | /* ??rehrauer: If I could figure out how to get the |
2749 | right return PC from here, we could just set a temp | |
2750 | breakpoint and resume. I'm not sure we can without | |
2751 | cracking open the dld's shared libraries and sniffing | |
2752 | their unwind tables and text/data ranges, and that's | |
2753 | not a terribly portable notion. | |
2754 | ||
2755 | Until that time, we must step the inferior out of the | |
2756 | dld callback, and also out of the dld itself (and any | |
2757 | code or stubs in libdld.sl, such as "shl_load" and | |
2758 | friends) until we reach non-dld code. At that point, | |
2759 | we can stop stepping. */ | |
2760 | bpstat_get_triggered_catchpoints (stop_bpstat, | |
2761 | &ecs-> | |
2762 | stepping_through_solib_catchpoints); | |
2763 | ecs->stepping_through_solib_after_catch = 1; | |
2764 | ||
2765 | /* Be sure to lift all breakpoints, so the inferior does | |
2766 | actually step past this point... */ | |
ca67fcb8 | 2767 | ecs->stepping_over_breakpoint = 1; |
488f131b | 2768 | break; |
c906108c | 2769 | } |
c5aa993b | 2770 | else |
c5aa993b | 2771 | { |
488f131b | 2772 | /* We want to step over this breakpoint, then keep going. */ |
ca67fcb8 | 2773 | ecs->stepping_over_breakpoint = 1; |
488f131b | 2774 | break; |
c5aa993b | 2775 | } |
488f131b | 2776 | } |
488f131b | 2777 | break; |
c906108c | 2778 | |
488f131b JB |
2779 | case BPSTAT_WHAT_LAST: |
2780 | /* Not a real code, but listed here to shut up gcc -Wall. */ | |
c906108c | 2781 | |
488f131b JB |
2782 | case BPSTAT_WHAT_KEEP_CHECKING: |
2783 | break; | |
2784 | } | |
2785 | } | |
c906108c | 2786 | |
488f131b JB |
2787 | /* We come here if we hit a breakpoint but should not |
2788 | stop for it. Possibly we also were stepping | |
2789 | and should stop for that. So fall through and | |
2790 | test for stepping. But, if not stepping, | |
2791 | do not stop. */ | |
c906108c | 2792 | |
9d1ff73f MS |
2793 | /* Are we stepping to get the inferior out of the dynamic linker's |
2794 | hook (and possibly the dld itself) after catching a shlib | |
2795 | event? */ | |
488f131b JB |
2796 | if (ecs->stepping_through_solib_after_catch) |
2797 | { | |
2798 | #if defined(SOLIB_ADD) | |
2799 | /* Have we reached our destination? If not, keep going. */ | |
2800 | if (SOLIB_IN_DYNAMIC_LINKER (PIDGET (ecs->ptid), stop_pc)) | |
2801 | { | |
527159b7 | 2802 | if (debug_infrun) |
8a9de0e4 | 2803 | fprintf_unfiltered (gdb_stdlog, "infrun: stepping in dynamic linker\n"); |
ca67fcb8 | 2804 | ecs->stepping_over_breakpoint = 1; |
488f131b | 2805 | keep_going (ecs); |
104c1213 | 2806 | return; |
488f131b JB |
2807 | } |
2808 | #endif | |
527159b7 | 2809 | if (debug_infrun) |
8a9de0e4 | 2810 | fprintf_unfiltered (gdb_stdlog, "infrun: step past dynamic linker\n"); |
488f131b JB |
2811 | /* Else, stop and report the catchpoint(s) whose triggering |
2812 | caused us to begin stepping. */ | |
2813 | ecs->stepping_through_solib_after_catch = 0; | |
2814 | bpstat_clear (&stop_bpstat); | |
2815 | stop_bpstat = bpstat_copy (ecs->stepping_through_solib_catchpoints); | |
2816 | bpstat_clear (&ecs->stepping_through_solib_catchpoints); | |
2817 | stop_print_frame = 1; | |
2818 | stop_stepping (ecs); | |
2819 | return; | |
2820 | } | |
c906108c | 2821 | |
488f131b JB |
2822 | if (step_resume_breakpoint) |
2823 | { | |
527159b7 | 2824 | if (debug_infrun) |
d3169d93 DJ |
2825 | fprintf_unfiltered (gdb_stdlog, |
2826 | "infrun: step-resume breakpoint is inserted\n"); | |
527159b7 | 2827 | |
488f131b JB |
2828 | /* Having a step-resume breakpoint overrides anything |
2829 | else having to do with stepping commands until | |
2830 | that breakpoint is reached. */ | |
488f131b JB |
2831 | keep_going (ecs); |
2832 | return; | |
2833 | } | |
c5aa993b | 2834 | |
488f131b JB |
2835 | if (step_range_end == 0) |
2836 | { | |
527159b7 | 2837 | if (debug_infrun) |
8a9de0e4 | 2838 | fprintf_unfiltered (gdb_stdlog, "infrun: no stepping, continue\n"); |
488f131b | 2839 | /* Likewise if we aren't even stepping. */ |
488f131b JB |
2840 | keep_going (ecs); |
2841 | return; | |
2842 | } | |
c5aa993b | 2843 | |
488f131b | 2844 | /* If stepping through a line, keep going if still within it. |
c906108c | 2845 | |
488f131b JB |
2846 | Note that step_range_end is the address of the first instruction |
2847 | beyond the step range, and NOT the address of the last instruction | |
2848 | within it! */ | |
2849 | if (stop_pc >= step_range_start && stop_pc < step_range_end) | |
2850 | { | |
527159b7 | 2851 | if (debug_infrun) |
8a9de0e4 | 2852 | fprintf_unfiltered (gdb_stdlog, "infrun: stepping inside range [0x%s-0x%s]\n", |
527159b7 RC |
2853 | paddr_nz (step_range_start), |
2854 | paddr_nz (step_range_end)); | |
488f131b JB |
2855 | keep_going (ecs); |
2856 | return; | |
2857 | } | |
c5aa993b | 2858 | |
488f131b | 2859 | /* We stepped out of the stepping range. */ |
c906108c | 2860 | |
488f131b JB |
2861 | /* If we are stepping at the source level and entered the runtime |
2862 | loader dynamic symbol resolution code, we keep on single stepping | |
2863 | until we exit the run time loader code and reach the callee's | |
2864 | address. */ | |
2865 | if (step_over_calls == STEP_OVER_UNDEBUGGABLE | |
a77053c2 MK |
2866 | #ifdef IN_SOLIB_DYNSYM_RESOLVE_CODE |
2867 | && IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc) | |
2868 | #else | |
2869 | && in_solib_dynsym_resolve_code (stop_pc) | |
2870 | #endif | |
2871 | ) | |
488f131b | 2872 | { |
4c8c40e6 MK |
2873 | CORE_ADDR pc_after_resolver = |
2874 | gdbarch_skip_solib_resolver (current_gdbarch, stop_pc); | |
c906108c | 2875 | |
527159b7 | 2876 | if (debug_infrun) |
8a9de0e4 | 2877 | fprintf_unfiltered (gdb_stdlog, "infrun: stepped into dynsym resolve code\n"); |
527159b7 | 2878 | |
488f131b JB |
2879 | if (pc_after_resolver) |
2880 | { | |
2881 | /* Set up a step-resume breakpoint at the address | |
2882 | indicated by SKIP_SOLIB_RESOLVER. */ | |
2883 | struct symtab_and_line sr_sal; | |
fe39c653 | 2884 | init_sal (&sr_sal); |
488f131b JB |
2885 | sr_sal.pc = pc_after_resolver; |
2886 | ||
44cbf7b5 | 2887 | insert_step_resume_breakpoint_at_sal (sr_sal, null_frame_id); |
c5aa993b | 2888 | } |
c906108c | 2889 | |
488f131b JB |
2890 | keep_going (ecs); |
2891 | return; | |
2892 | } | |
c906108c | 2893 | |
42edda50 AC |
2894 | if (step_range_end != 1 |
2895 | && (step_over_calls == STEP_OVER_UNDEBUGGABLE | |
2896 | || step_over_calls == STEP_OVER_ALL) | |
2897 | && get_frame_type (get_current_frame ()) == SIGTRAMP_FRAME) | |
488f131b | 2898 | { |
527159b7 | 2899 | if (debug_infrun) |
8a9de0e4 | 2900 | fprintf_unfiltered (gdb_stdlog, "infrun: stepped into signal trampoline\n"); |
42edda50 | 2901 | /* The inferior, while doing a "step" or "next", has ended up in |
8fb3e588 AC |
2902 | a signal trampoline (either by a signal being delivered or by |
2903 | the signal handler returning). Just single-step until the | |
2904 | inferior leaves the trampoline (either by calling the handler | |
2905 | or returning). */ | |
488f131b JB |
2906 | keep_going (ecs); |
2907 | return; | |
2908 | } | |
c906108c | 2909 | |
c17eaafe DJ |
2910 | /* Check for subroutine calls. The check for the current frame |
2911 | equalling the step ID is not necessary - the check of the | |
2912 | previous frame's ID is sufficient - but it is a common case and | |
2913 | cheaper than checking the previous frame's ID. | |
14e60db5 DJ |
2914 | |
2915 | NOTE: frame_id_eq will never report two invalid frame IDs as | |
2916 | being equal, so to get into this block, both the current and | |
2917 | previous frame must have valid frame IDs. */ | |
c17eaafe DJ |
2918 | if (!frame_id_eq (get_frame_id (get_current_frame ()), step_frame_id) |
2919 | && frame_id_eq (frame_unwind_id (get_current_frame ()), step_frame_id)) | |
488f131b | 2920 | { |
95918acb | 2921 | CORE_ADDR real_stop_pc; |
8fb3e588 | 2922 | |
527159b7 | 2923 | if (debug_infrun) |
8a9de0e4 | 2924 | fprintf_unfiltered (gdb_stdlog, "infrun: stepped into subroutine\n"); |
527159b7 | 2925 | |
95918acb AC |
2926 | if ((step_over_calls == STEP_OVER_NONE) |
2927 | || ((step_range_end == 1) | |
2928 | && in_prologue (prev_pc, ecs->stop_func_start))) | |
2929 | { | |
2930 | /* I presume that step_over_calls is only 0 when we're | |
2931 | supposed to be stepping at the assembly language level | |
2932 | ("stepi"). Just stop. */ | |
2933 | /* Also, maybe we just did a "nexti" inside a prolog, so we | |
2934 | thought it was a subroutine call but it was not. Stop as | |
2935 | well. FENN */ | |
2936 | stop_step = 1; | |
2937 | print_stop_reason (END_STEPPING_RANGE, 0); | |
2938 | stop_stepping (ecs); | |
2939 | return; | |
2940 | } | |
8fb3e588 | 2941 | |
8567c30f AC |
2942 | if (step_over_calls == STEP_OVER_ALL) |
2943 | { | |
2944 | /* We're doing a "next", set a breakpoint at callee's return | |
2945 | address (the address at which the caller will | |
2946 | resume). */ | |
14e60db5 | 2947 | insert_step_resume_breakpoint_at_caller (get_current_frame ()); |
8567c30f AC |
2948 | keep_going (ecs); |
2949 | return; | |
2950 | } | |
a53c66de | 2951 | |
95918acb | 2952 | /* If we are in a function call trampoline (a stub between the |
8fb3e588 AC |
2953 | calling routine and the real function), locate the real |
2954 | function. That's what tells us (a) whether we want to step | |
2955 | into it at all, and (b) what prologue we want to run to the | |
2956 | end of, if we do step into it. */ | |
52f729a7 | 2957 | real_stop_pc = skip_language_trampoline (get_current_frame (), stop_pc); |
95918acb | 2958 | if (real_stop_pc == 0) |
52f729a7 UW |
2959 | real_stop_pc = gdbarch_skip_trampoline_code |
2960 | (current_gdbarch, get_current_frame (), stop_pc); | |
95918acb AC |
2961 | if (real_stop_pc != 0) |
2962 | ecs->stop_func_start = real_stop_pc; | |
8fb3e588 | 2963 | |
a77053c2 MK |
2964 | if ( |
2965 | #ifdef IN_SOLIB_DYNSYM_RESOLVE_CODE | |
2966 | IN_SOLIB_DYNSYM_RESOLVE_CODE (ecs->stop_func_start) | |
2967 | #else | |
2968 | in_solib_dynsym_resolve_code (ecs->stop_func_start) | |
2969 | #endif | |
2970 | ) | |
1b2bfbb9 RC |
2971 | { |
2972 | struct symtab_and_line sr_sal; | |
2973 | init_sal (&sr_sal); | |
2974 | sr_sal.pc = ecs->stop_func_start; | |
2975 | ||
44cbf7b5 | 2976 | insert_step_resume_breakpoint_at_sal (sr_sal, null_frame_id); |
8fb3e588 AC |
2977 | keep_going (ecs); |
2978 | return; | |
1b2bfbb9 RC |
2979 | } |
2980 | ||
95918acb | 2981 | /* If we have line number information for the function we are |
8fb3e588 | 2982 | thinking of stepping into, step into it. |
95918acb | 2983 | |
8fb3e588 AC |
2984 | If there are several symtabs at that PC (e.g. with include |
2985 | files), just want to know whether *any* of them have line | |
2986 | numbers. find_pc_line handles this. */ | |
95918acb AC |
2987 | { |
2988 | struct symtab_and_line tmp_sal; | |
8fb3e588 | 2989 | |
95918acb AC |
2990 | tmp_sal = find_pc_line (ecs->stop_func_start, 0); |
2991 | if (tmp_sal.line != 0) | |
2992 | { | |
2993 | step_into_function (ecs); | |
2994 | return; | |
2995 | } | |
2996 | } | |
2997 | ||
2998 | /* If we have no line number and the step-stop-if-no-debug is | |
8fb3e588 AC |
2999 | set, we stop the step so that the user has a chance to switch |
3000 | in assembly mode. */ | |
95918acb AC |
3001 | if (step_over_calls == STEP_OVER_UNDEBUGGABLE && step_stop_if_no_debug) |
3002 | { | |
3003 | stop_step = 1; | |
3004 | print_stop_reason (END_STEPPING_RANGE, 0); | |
3005 | stop_stepping (ecs); | |
3006 | return; | |
3007 | } | |
3008 | ||
3009 | /* Set a breakpoint at callee's return address (the address at | |
8fb3e588 | 3010 | which the caller will resume). */ |
14e60db5 | 3011 | insert_step_resume_breakpoint_at_caller (get_current_frame ()); |
95918acb | 3012 | keep_going (ecs); |
488f131b | 3013 | return; |
488f131b | 3014 | } |
c906108c | 3015 | |
488f131b JB |
3016 | /* If we're in the return path from a shared library trampoline, |
3017 | we want to proceed through the trampoline when stepping. */ | |
e76f05fa UW |
3018 | if (gdbarch_in_solib_return_trampoline (current_gdbarch, |
3019 | stop_pc, ecs->stop_func_name)) | |
488f131b | 3020 | { |
488f131b | 3021 | /* Determine where this trampoline returns. */ |
52f729a7 UW |
3022 | CORE_ADDR real_stop_pc; |
3023 | real_stop_pc = gdbarch_skip_trampoline_code | |
3024 | (current_gdbarch, get_current_frame (), stop_pc); | |
c906108c | 3025 | |
527159b7 | 3026 | if (debug_infrun) |
8a9de0e4 | 3027 | fprintf_unfiltered (gdb_stdlog, "infrun: stepped into solib return tramp\n"); |
527159b7 | 3028 | |
488f131b | 3029 | /* Only proceed through if we know where it's going. */ |
d764a824 | 3030 | if (real_stop_pc) |
488f131b JB |
3031 | { |
3032 | /* And put the step-breakpoint there and go until there. */ | |
3033 | struct symtab_and_line sr_sal; | |
3034 | ||
fe39c653 | 3035 | init_sal (&sr_sal); /* initialize to zeroes */ |
d764a824 | 3036 | sr_sal.pc = real_stop_pc; |
488f131b | 3037 | sr_sal.section = find_pc_overlay (sr_sal.pc); |
44cbf7b5 AC |
3038 | |
3039 | /* Do not specify what the fp should be when we stop since | |
3040 | on some machines the prologue is where the new fp value | |
3041 | is established. */ | |
3042 | insert_step_resume_breakpoint_at_sal (sr_sal, null_frame_id); | |
c906108c | 3043 | |
488f131b JB |
3044 | /* Restart without fiddling with the step ranges or |
3045 | other state. */ | |
3046 | keep_going (ecs); | |
3047 | return; | |
3048 | } | |
3049 | } | |
c906108c | 3050 | |
7ed0fe66 DJ |
3051 | ecs->sal = find_pc_line (stop_pc, 0); |
3052 | ||
1b2bfbb9 RC |
3053 | /* NOTE: tausq/2004-05-24: This if block used to be done before all |
3054 | the trampoline processing logic, however, there are some trampolines | |
3055 | that have no names, so we should do trampoline handling first. */ | |
3056 | if (step_over_calls == STEP_OVER_UNDEBUGGABLE | |
7ed0fe66 DJ |
3057 | && ecs->stop_func_name == NULL |
3058 | && ecs->sal.line == 0) | |
1b2bfbb9 | 3059 | { |
527159b7 | 3060 | if (debug_infrun) |
8a9de0e4 | 3061 | fprintf_unfiltered (gdb_stdlog, "infrun: stepped into undebuggable function\n"); |
527159b7 | 3062 | |
1b2bfbb9 | 3063 | /* The inferior just stepped into, or returned to, an |
7ed0fe66 DJ |
3064 | undebuggable function (where there is no debugging information |
3065 | and no line number corresponding to the address where the | |
1b2bfbb9 RC |
3066 | inferior stopped). Since we want to skip this kind of code, |
3067 | we keep going until the inferior returns from this | |
14e60db5 DJ |
3068 | function - unless the user has asked us not to (via |
3069 | set step-mode) or we no longer know how to get back | |
3070 | to the call site. */ | |
3071 | if (step_stop_if_no_debug | |
3072 | || !frame_id_p (frame_unwind_id (get_current_frame ()))) | |
1b2bfbb9 RC |
3073 | { |
3074 | /* If we have no line number and the step-stop-if-no-debug | |
3075 | is set, we stop the step so that the user has a chance to | |
3076 | switch in assembly mode. */ | |
3077 | stop_step = 1; | |
3078 | print_stop_reason (END_STEPPING_RANGE, 0); | |
3079 | stop_stepping (ecs); | |
3080 | return; | |
3081 | } | |
3082 | else | |
3083 | { | |
3084 | /* Set a breakpoint at callee's return address (the address | |
3085 | at which the caller will resume). */ | |
14e60db5 | 3086 | insert_step_resume_breakpoint_at_caller (get_current_frame ()); |
1b2bfbb9 RC |
3087 | keep_going (ecs); |
3088 | return; | |
3089 | } | |
3090 | } | |
3091 | ||
3092 | if (step_range_end == 1) | |
3093 | { | |
3094 | /* It is stepi or nexti. We always want to stop stepping after | |
3095 | one instruction. */ | |
527159b7 | 3096 | if (debug_infrun) |
8a9de0e4 | 3097 | fprintf_unfiltered (gdb_stdlog, "infrun: stepi/nexti\n"); |
1b2bfbb9 RC |
3098 | stop_step = 1; |
3099 | print_stop_reason (END_STEPPING_RANGE, 0); | |
3100 | stop_stepping (ecs); | |
3101 | return; | |
3102 | } | |
3103 | ||
488f131b JB |
3104 | if (ecs->sal.line == 0) |
3105 | { | |
3106 | /* We have no line number information. That means to stop | |
3107 | stepping (does this always happen right after one instruction, | |
3108 | when we do "s" in a function with no line numbers, | |
3109 | or can this happen as a result of a return or longjmp?). */ | |
527159b7 | 3110 | if (debug_infrun) |
8a9de0e4 | 3111 | fprintf_unfiltered (gdb_stdlog, "infrun: no line number info\n"); |
488f131b JB |
3112 | stop_step = 1; |
3113 | print_stop_reason (END_STEPPING_RANGE, 0); | |
3114 | stop_stepping (ecs); | |
3115 | return; | |
3116 | } | |
c906108c | 3117 | |
488f131b JB |
3118 | if ((stop_pc == ecs->sal.pc) |
3119 | && (ecs->current_line != ecs->sal.line | |
3120 | || ecs->current_symtab != ecs->sal.symtab)) | |
3121 | { | |
3122 | /* We are at the start of a different line. So stop. Note that | |
3123 | we don't stop if we step into the middle of a different line. | |
3124 | That is said to make things like for (;;) statements work | |
3125 | better. */ | |
527159b7 | 3126 | if (debug_infrun) |
8a9de0e4 | 3127 | fprintf_unfiltered (gdb_stdlog, "infrun: stepped to a different line\n"); |
488f131b JB |
3128 | stop_step = 1; |
3129 | print_stop_reason (END_STEPPING_RANGE, 0); | |
3130 | stop_stepping (ecs); | |
3131 | return; | |
3132 | } | |
c906108c | 3133 | |
488f131b | 3134 | /* We aren't done stepping. |
c906108c | 3135 | |
488f131b JB |
3136 | Optimize by setting the stepping range to the line. |
3137 | (We might not be in the original line, but if we entered a | |
3138 | new line in mid-statement, we continue stepping. This makes | |
3139 | things like for(;;) statements work better.) */ | |
c906108c | 3140 | |
488f131b JB |
3141 | step_range_start = ecs->sal.pc; |
3142 | step_range_end = ecs->sal.end; | |
aa0cd9c1 | 3143 | step_frame_id = get_frame_id (get_current_frame ()); |
488f131b JB |
3144 | ecs->current_line = ecs->sal.line; |
3145 | ecs->current_symtab = ecs->sal.symtab; | |
3146 | ||
aa0cd9c1 AC |
3147 | /* In the case where we just stepped out of a function into the |
3148 | middle of a line of the caller, continue stepping, but | |
3149 | step_frame_id must be modified to current frame */ | |
65815ea1 AC |
3150 | #if 0 |
3151 | /* NOTE: cagney/2003-10-16: I think this frame ID inner test is too | |
3152 | generous. It will trigger on things like a step into a frameless | |
3153 | stackless leaf function. I think the logic should instead look | |
3154 | at the unwound frame ID has that should give a more robust | |
3155 | indication of what happened. */ | |
8fb3e588 AC |
3156 | if (step - ID == current - ID) |
3157 | still stepping in same function; | |
3158 | else if (step - ID == unwind (current - ID)) | |
3159 | stepped into a function; | |
3160 | else | |
3161 | stepped out of a function; | |
3162 | /* Of course this assumes that the frame ID unwind code is robust | |
3163 | and we're willing to introduce frame unwind logic into this | |
3164 | function. Fortunately, those days are nearly upon us. */ | |
65815ea1 | 3165 | #endif |
488f131b | 3166 | { |
09a7aba8 UW |
3167 | struct frame_info *frame = get_current_frame (); |
3168 | struct frame_id current_frame = get_frame_id (frame); | |
3169 | if (!(frame_id_inner (get_frame_arch (frame), current_frame, | |
3170 | step_frame_id))) | |
aa0cd9c1 | 3171 | step_frame_id = current_frame; |
488f131b | 3172 | } |
c906108c | 3173 | |
527159b7 | 3174 | if (debug_infrun) |
8a9de0e4 | 3175 | fprintf_unfiltered (gdb_stdlog, "infrun: keep going\n"); |
488f131b | 3176 | keep_going (ecs); |
104c1213 JM |
3177 | } |
3178 | ||
3179 | /* Are we in the middle of stepping? */ | |
3180 | ||
3181 | static int | |
3182 | currently_stepping (struct execution_control_state *ecs) | |
3183 | { | |
611c83ae PA |
3184 | return (((step_range_end && step_resume_breakpoint == NULL) |
3185 | || stepping_over_breakpoint) | |
104c1213 JM |
3186 | || ecs->stepping_through_solib_after_catch |
3187 | || bpstat_should_step ()); | |
3188 | } | |
c906108c | 3189 | |
c2c6d25f JM |
3190 | /* Subroutine call with source code we should not step over. Do step |
3191 | to the first line of code in it. */ | |
3192 | ||
3193 | static void | |
3194 | step_into_function (struct execution_control_state *ecs) | |
3195 | { | |
3196 | struct symtab *s; | |
3197 | struct symtab_and_line sr_sal; | |
3198 | ||
3199 | s = find_pc_symtab (stop_pc); | |
3200 | if (s && s->language != language_asm) | |
a433963d UW |
3201 | ecs->stop_func_start = gdbarch_skip_prologue |
3202 | (current_gdbarch, ecs->stop_func_start); | |
c2c6d25f JM |
3203 | |
3204 | ecs->sal = find_pc_line (ecs->stop_func_start, 0); | |
3205 | /* Use the step_resume_break to step until the end of the prologue, | |
3206 | even if that involves jumps (as it seems to on the vax under | |
3207 | 4.2). */ | |
3208 | /* If the prologue ends in the middle of a source line, continue to | |
3209 | the end of that source line (if it is still within the function). | |
3210 | Otherwise, just go to end of prologue. */ | |
c2c6d25f JM |
3211 | if (ecs->sal.end |
3212 | && ecs->sal.pc != ecs->stop_func_start | |
3213 | && ecs->sal.end < ecs->stop_func_end) | |
3214 | ecs->stop_func_start = ecs->sal.end; | |
c2c6d25f | 3215 | |
2dbd5e30 KB |
3216 | /* Architectures which require breakpoint adjustment might not be able |
3217 | to place a breakpoint at the computed address. If so, the test | |
3218 | ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust | |
3219 | ecs->stop_func_start to an address at which a breakpoint may be | |
3220 | legitimately placed. | |
8fb3e588 | 3221 | |
2dbd5e30 KB |
3222 | Note: kevinb/2004-01-19: On FR-V, if this adjustment is not |
3223 | made, GDB will enter an infinite loop when stepping through | |
3224 | optimized code consisting of VLIW instructions which contain | |
3225 | subinstructions corresponding to different source lines. On | |
3226 | FR-V, it's not permitted to place a breakpoint on any but the | |
3227 | first subinstruction of a VLIW instruction. When a breakpoint is | |
3228 | set, GDB will adjust the breakpoint address to the beginning of | |
3229 | the VLIW instruction. Thus, we need to make the corresponding | |
3230 | adjustment here when computing the stop address. */ | |
8fb3e588 | 3231 | |
2dbd5e30 KB |
3232 | if (gdbarch_adjust_breakpoint_address_p (current_gdbarch)) |
3233 | { | |
3234 | ecs->stop_func_start | |
3235 | = gdbarch_adjust_breakpoint_address (current_gdbarch, | |
8fb3e588 | 3236 | ecs->stop_func_start); |
2dbd5e30 KB |
3237 | } |
3238 | ||
c2c6d25f JM |
3239 | if (ecs->stop_func_start == stop_pc) |
3240 | { | |
3241 | /* We are already there: stop now. */ | |
3242 | stop_step = 1; | |
488f131b | 3243 | print_stop_reason (END_STEPPING_RANGE, 0); |
c2c6d25f JM |
3244 | stop_stepping (ecs); |
3245 | return; | |
3246 | } | |
3247 | else | |
3248 | { | |
3249 | /* Put the step-breakpoint there and go until there. */ | |
fe39c653 | 3250 | init_sal (&sr_sal); /* initialize to zeroes */ |
c2c6d25f JM |
3251 | sr_sal.pc = ecs->stop_func_start; |
3252 | sr_sal.section = find_pc_overlay (ecs->stop_func_start); | |
44cbf7b5 | 3253 | |
c2c6d25f | 3254 | /* Do not specify what the fp should be when we stop since on |
488f131b JB |
3255 | some machines the prologue is where the new fp value is |
3256 | established. */ | |
44cbf7b5 | 3257 | insert_step_resume_breakpoint_at_sal (sr_sal, null_frame_id); |
c2c6d25f JM |
3258 | |
3259 | /* And make sure stepping stops right away then. */ | |
3260 | step_range_end = step_range_start; | |
3261 | } | |
3262 | keep_going (ecs); | |
3263 | } | |
d4f3574e | 3264 | |
d3169d93 | 3265 | /* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID. |
44cbf7b5 AC |
3266 | This is used to both functions and to skip over code. */ |
3267 | ||
3268 | static void | |
3269 | insert_step_resume_breakpoint_at_sal (struct symtab_and_line sr_sal, | |
3270 | struct frame_id sr_id) | |
3271 | { | |
611c83ae PA |
3272 | /* There should never be more than one step-resume or longjmp-resume |
3273 | breakpoint per thread, so we should never be setting a new | |
44cbf7b5 AC |
3274 | step_resume_breakpoint when one is already active. */ |
3275 | gdb_assert (step_resume_breakpoint == NULL); | |
d3169d93 DJ |
3276 | |
3277 | if (debug_infrun) | |
3278 | fprintf_unfiltered (gdb_stdlog, | |
3279 | "infrun: inserting step-resume breakpoint at 0x%s\n", | |
3280 | paddr_nz (sr_sal.pc)); | |
3281 | ||
44cbf7b5 AC |
3282 | step_resume_breakpoint = set_momentary_breakpoint (sr_sal, sr_id, |
3283 | bp_step_resume); | |
44cbf7b5 | 3284 | } |
7ce450bd | 3285 | |
d3169d93 | 3286 | /* Insert a "step-resume breakpoint" at RETURN_FRAME.pc. This is used |
14e60db5 | 3287 | to skip a potential signal handler. |
7ce450bd | 3288 | |
14e60db5 DJ |
3289 | This is called with the interrupted function's frame. The signal |
3290 | handler, when it returns, will resume the interrupted function at | |
3291 | RETURN_FRAME.pc. */ | |
d303a6c7 AC |
3292 | |
3293 | static void | |
44cbf7b5 | 3294 | insert_step_resume_breakpoint_at_frame (struct frame_info *return_frame) |
d303a6c7 AC |
3295 | { |
3296 | struct symtab_and_line sr_sal; | |
3297 | ||
f4c1edd8 | 3298 | gdb_assert (return_frame != NULL); |
d303a6c7 AC |
3299 | init_sal (&sr_sal); /* initialize to zeros */ |
3300 | ||
bf6ae464 UW |
3301 | sr_sal.pc = gdbarch_addr_bits_remove |
3302 | (current_gdbarch, get_frame_pc (return_frame)); | |
d303a6c7 AC |
3303 | sr_sal.section = find_pc_overlay (sr_sal.pc); |
3304 | ||
44cbf7b5 | 3305 | insert_step_resume_breakpoint_at_sal (sr_sal, get_frame_id (return_frame)); |
d303a6c7 AC |
3306 | } |
3307 | ||
14e60db5 DJ |
3308 | /* Similar to insert_step_resume_breakpoint_at_frame, except |
3309 | but a breakpoint at the previous frame's PC. This is used to | |
3310 | skip a function after stepping into it (for "next" or if the called | |
3311 | function has no debugging information). | |
3312 | ||
3313 | The current function has almost always been reached by single | |
3314 | stepping a call or return instruction. NEXT_FRAME belongs to the | |
3315 | current function, and the breakpoint will be set at the caller's | |
3316 | resume address. | |
3317 | ||
3318 | This is a separate function rather than reusing | |
3319 | insert_step_resume_breakpoint_at_frame in order to avoid | |
3320 | get_prev_frame, which may stop prematurely (see the implementation | |
3321 | of frame_unwind_id for an example). */ | |
3322 | ||
3323 | static void | |
3324 | insert_step_resume_breakpoint_at_caller (struct frame_info *next_frame) | |
3325 | { | |
3326 | struct symtab_and_line sr_sal; | |
3327 | ||
3328 | /* We shouldn't have gotten here if we don't know where the call site | |
3329 | is. */ | |
3330 | gdb_assert (frame_id_p (frame_unwind_id (next_frame))); | |
3331 | ||
3332 | init_sal (&sr_sal); /* initialize to zeros */ | |
3333 | ||
bf6ae464 UW |
3334 | sr_sal.pc = gdbarch_addr_bits_remove |
3335 | (current_gdbarch, frame_pc_unwind (next_frame)); | |
14e60db5 DJ |
3336 | sr_sal.section = find_pc_overlay (sr_sal.pc); |
3337 | ||
3338 | insert_step_resume_breakpoint_at_sal (sr_sal, frame_unwind_id (next_frame)); | |
3339 | } | |
3340 | ||
611c83ae PA |
3341 | /* Insert a "longjmp-resume" breakpoint at PC. This is used to set a |
3342 | new breakpoint at the target of a jmp_buf. The handling of | |
3343 | longjmp-resume uses the same mechanisms used for handling | |
3344 | "step-resume" breakpoints. */ | |
3345 | ||
3346 | static void | |
3347 | insert_longjmp_resume_breakpoint (CORE_ADDR pc) | |
3348 | { | |
3349 | /* There should never be more than one step-resume or longjmp-resume | |
3350 | breakpoint per thread, so we should never be setting a new | |
3351 | longjmp_resume_breakpoint when one is already active. */ | |
3352 | gdb_assert (step_resume_breakpoint == NULL); | |
3353 | ||
3354 | if (debug_infrun) | |
3355 | fprintf_unfiltered (gdb_stdlog, | |
3356 | "infrun: inserting longjmp-resume breakpoint at 0x%s\n", | |
3357 | paddr_nz (pc)); | |
3358 | ||
3359 | step_resume_breakpoint = | |
3360 | set_momentary_breakpoint_at_pc (pc, bp_longjmp_resume); | |
3361 | } | |
3362 | ||
104c1213 JM |
3363 | static void |
3364 | stop_stepping (struct execution_control_state *ecs) | |
3365 | { | |
527159b7 | 3366 | if (debug_infrun) |
8a9de0e4 | 3367 | fprintf_unfiltered (gdb_stdlog, "infrun: stop_stepping\n"); |
527159b7 | 3368 | |
cd0fc7c3 SS |
3369 | /* Let callers know we don't want to wait for the inferior anymore. */ |
3370 | ecs->wait_some_more = 0; | |
3371 | } | |
3372 | ||
d4f3574e SS |
3373 | /* This function handles various cases where we need to continue |
3374 | waiting for the inferior. */ | |
3375 | /* (Used to be the keep_going: label in the old wait_for_inferior) */ | |
3376 | ||
3377 | static void | |
3378 | keep_going (struct execution_control_state *ecs) | |
3379 | { | |
d4f3574e | 3380 | /* Save the pc before execution, to compare with pc after stop. */ |
488f131b | 3381 | prev_pc = read_pc (); /* Might have been DECR_AFTER_BREAK */ |
d4f3574e | 3382 | |
d4f3574e SS |
3383 | /* If we did not do break;, it means we should keep running the |
3384 | inferior and not return to debugger. */ | |
3385 | ||
ca67fcb8 | 3386 | if (stepping_over_breakpoint && stop_signal != TARGET_SIGNAL_TRAP) |
d4f3574e SS |
3387 | { |
3388 | /* We took a signal (which we are supposed to pass through to | |
488f131b JB |
3389 | the inferior, else we'd have done a break above) and we |
3390 | haven't yet gotten our trap. Simply continue. */ | |
d4f3574e SS |
3391 | resume (currently_stepping (ecs), stop_signal); |
3392 | } | |
3393 | else | |
3394 | { | |
3395 | /* Either the trap was not expected, but we are continuing | |
488f131b JB |
3396 | anyway (the user asked that this signal be passed to the |
3397 | child) | |
3398 | -- or -- | |
3399 | The signal was SIGTRAP, e.g. it was our signal, but we | |
3400 | decided we should resume from it. | |
d4f3574e | 3401 | |
c36b740a | 3402 | We're going to run this baby now! |
d4f3574e | 3403 | |
c36b740a VP |
3404 | Note that insert_breakpoints won't try to re-insert |
3405 | already inserted breakpoints. Therefore, we don't | |
3406 | care if breakpoints were already inserted, or not. */ | |
3407 | ||
45e8c884 VP |
3408 | if (ecs->stepping_over_breakpoint) |
3409 | { | |
237fc4c9 PA |
3410 | if (! use_displaced_stepping (current_gdbarch)) |
3411 | /* Since we can't do a displaced step, we have to remove | |
3412 | the breakpoint while we step it. To keep things | |
3413 | simple, we remove them all. */ | |
3414 | remove_breakpoints (); | |
45e8c884 VP |
3415 | } |
3416 | else | |
d4f3574e | 3417 | { |
e236ba44 | 3418 | struct gdb_exception e; |
569631c6 UW |
3419 | /* Stop stepping when inserting breakpoints |
3420 | has failed. */ | |
e236ba44 VP |
3421 | TRY_CATCH (e, RETURN_MASK_ERROR) |
3422 | { | |
3423 | insert_breakpoints (); | |
3424 | } | |
3425 | if (e.reason < 0) | |
d4f3574e SS |
3426 | { |
3427 | stop_stepping (ecs); | |
3428 | return; | |
3429 | } | |
d4f3574e SS |
3430 | } |
3431 | ||
ca67fcb8 | 3432 | stepping_over_breakpoint = ecs->stepping_over_breakpoint; |
d4f3574e SS |
3433 | |
3434 | /* Do not deliver SIGNAL_TRAP (except when the user explicitly | |
488f131b JB |
3435 | specifies that such a signal should be delivered to the |
3436 | target program). | |
3437 | ||
3438 | Typically, this would occure when a user is debugging a | |
3439 | target monitor on a simulator: the target monitor sets a | |
3440 | breakpoint; the simulator encounters this break-point and | |
3441 | halts the simulation handing control to GDB; GDB, noteing | |
3442 | that the break-point isn't valid, returns control back to the | |
3443 | simulator; the simulator then delivers the hardware | |
3444 | equivalent of a SIGNAL_TRAP to the program being debugged. */ | |
3445 | ||
3446 | if (stop_signal == TARGET_SIGNAL_TRAP && !signal_program[stop_signal]) | |
d4f3574e SS |
3447 | stop_signal = TARGET_SIGNAL_0; |
3448 | ||
d4f3574e SS |
3449 | |
3450 | resume (currently_stepping (ecs), stop_signal); | |
3451 | } | |
3452 | ||
488f131b | 3453 | prepare_to_wait (ecs); |
d4f3574e SS |
3454 | } |
3455 | ||
104c1213 JM |
3456 | /* This function normally comes after a resume, before |
3457 | handle_inferior_event exits. It takes care of any last bits of | |
3458 | housekeeping, and sets the all-important wait_some_more flag. */ | |
cd0fc7c3 | 3459 | |
104c1213 JM |
3460 | static void |
3461 | prepare_to_wait (struct execution_control_state *ecs) | |
cd0fc7c3 | 3462 | { |
527159b7 | 3463 | if (debug_infrun) |
8a9de0e4 | 3464 | fprintf_unfiltered (gdb_stdlog, "infrun: prepare_to_wait\n"); |
104c1213 JM |
3465 | if (ecs->infwait_state == infwait_normal_state) |
3466 | { | |
3467 | overlay_cache_invalid = 1; | |
3468 | ||
3469 | /* We have to invalidate the registers BEFORE calling | |
488f131b JB |
3470 | target_wait because they can be loaded from the target while |
3471 | in target_wait. This makes remote debugging a bit more | |
3472 | efficient for those targets that provide critical registers | |
3473 | as part of their normal status mechanism. */ | |
104c1213 JM |
3474 | |
3475 | registers_changed (); | |
39f77062 | 3476 | ecs->waiton_ptid = pid_to_ptid (-1); |
104c1213 JM |
3477 | ecs->wp = &(ecs->ws); |
3478 | } | |
3479 | /* This is the old end of the while loop. Let everybody know we | |
3480 | want to wait for the inferior some more and get called again | |
3481 | soon. */ | |
3482 | ecs->wait_some_more = 1; | |
c906108c | 3483 | } |
11cf8741 JM |
3484 | |
3485 | /* Print why the inferior has stopped. We always print something when | |
3486 | the inferior exits, or receives a signal. The rest of the cases are | |
3487 | dealt with later on in normal_stop() and print_it_typical(). Ideally | |
3488 | there should be a call to this function from handle_inferior_event() | |
3489 | each time stop_stepping() is called.*/ | |
3490 | static void | |
3491 | print_stop_reason (enum inferior_stop_reason stop_reason, int stop_info) | |
3492 | { | |
3493 | switch (stop_reason) | |
3494 | { | |
11cf8741 JM |
3495 | case END_STEPPING_RANGE: |
3496 | /* We are done with a step/next/si/ni command. */ | |
3497 | /* For now print nothing. */ | |
fb40c209 | 3498 | /* Print a message only if not in the middle of doing a "step n" |
488f131b | 3499 | operation for n > 1 */ |
fb40c209 | 3500 | if (!step_multi || !stop_step) |
9dc5e2a9 | 3501 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3502 | ui_out_field_string |
3503 | (uiout, "reason", | |
3504 | async_reason_lookup (EXEC_ASYNC_END_STEPPING_RANGE)); | |
11cf8741 | 3505 | break; |
11cf8741 JM |
3506 | case SIGNAL_EXITED: |
3507 | /* The inferior was terminated by a signal. */ | |
8b93c638 | 3508 | annotate_signalled (); |
9dc5e2a9 | 3509 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3510 | ui_out_field_string |
3511 | (uiout, "reason", | |
3512 | async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED)); | |
8b93c638 JM |
3513 | ui_out_text (uiout, "\nProgram terminated with signal "); |
3514 | annotate_signal_name (); | |
488f131b JB |
3515 | ui_out_field_string (uiout, "signal-name", |
3516 | target_signal_to_name (stop_info)); | |
8b93c638 JM |
3517 | annotate_signal_name_end (); |
3518 | ui_out_text (uiout, ", "); | |
3519 | annotate_signal_string (); | |
488f131b JB |
3520 | ui_out_field_string (uiout, "signal-meaning", |
3521 | target_signal_to_string (stop_info)); | |
8b93c638 JM |
3522 | annotate_signal_string_end (); |
3523 | ui_out_text (uiout, ".\n"); | |
3524 | ui_out_text (uiout, "The program no longer exists.\n"); | |
11cf8741 JM |
3525 | break; |
3526 | case EXITED: | |
3527 | /* The inferior program is finished. */ | |
8b93c638 JM |
3528 | annotate_exited (stop_info); |
3529 | if (stop_info) | |
3530 | { | |
9dc5e2a9 | 3531 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3532 | ui_out_field_string (uiout, "reason", |
3533 | async_reason_lookup (EXEC_ASYNC_EXITED)); | |
8b93c638 | 3534 | ui_out_text (uiout, "\nProgram exited with code "); |
488f131b JB |
3535 | ui_out_field_fmt (uiout, "exit-code", "0%o", |
3536 | (unsigned int) stop_info); | |
8b93c638 JM |
3537 | ui_out_text (uiout, ".\n"); |
3538 | } | |
3539 | else | |
3540 | { | |
9dc5e2a9 | 3541 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3542 | ui_out_field_string |
3543 | (uiout, "reason", | |
3544 | async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY)); | |
8b93c638 JM |
3545 | ui_out_text (uiout, "\nProgram exited normally.\n"); |
3546 | } | |
f17517ea AS |
3547 | /* Support the --return-child-result option. */ |
3548 | return_child_result_value = stop_info; | |
11cf8741 JM |
3549 | break; |
3550 | case SIGNAL_RECEIVED: | |
3551 | /* Signal received. The signal table tells us to print about | |
3552 | it. */ | |
8b93c638 JM |
3553 | annotate_signal (); |
3554 | ui_out_text (uiout, "\nProgram received signal "); | |
3555 | annotate_signal_name (); | |
84c6c83c | 3556 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3557 | ui_out_field_string |
3558 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED)); | |
488f131b JB |
3559 | ui_out_field_string (uiout, "signal-name", |
3560 | target_signal_to_name (stop_info)); | |
8b93c638 JM |
3561 | annotate_signal_name_end (); |
3562 | ui_out_text (uiout, ", "); | |
3563 | annotate_signal_string (); | |
488f131b JB |
3564 | ui_out_field_string (uiout, "signal-meaning", |
3565 | target_signal_to_string (stop_info)); | |
8b93c638 JM |
3566 | annotate_signal_string_end (); |
3567 | ui_out_text (uiout, ".\n"); | |
11cf8741 JM |
3568 | break; |
3569 | default: | |
8e65ff28 | 3570 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 3571 | _("print_stop_reason: unrecognized enum value")); |
11cf8741 JM |
3572 | break; |
3573 | } | |
3574 | } | |
c906108c | 3575 | \f |
43ff13b4 | 3576 | |
c906108c SS |
3577 | /* Here to return control to GDB when the inferior stops for real. |
3578 | Print appropriate messages, remove breakpoints, give terminal our modes. | |
3579 | ||
3580 | STOP_PRINT_FRAME nonzero means print the executing frame | |
3581 | (pc, function, args, file, line number and line text). | |
3582 | BREAKPOINTS_FAILED nonzero means stop was due to error | |
3583 | attempting to insert breakpoints. */ | |
3584 | ||
3585 | void | |
96baa820 | 3586 | normal_stop (void) |
c906108c | 3587 | { |
73b65bb0 DJ |
3588 | struct target_waitstatus last; |
3589 | ptid_t last_ptid; | |
3590 | ||
3591 | get_last_target_status (&last_ptid, &last); | |
3592 | ||
c906108c SS |
3593 | /* As with the notification of thread events, we want to delay |
3594 | notifying the user that we've switched thread context until | |
3595 | the inferior actually stops. | |
3596 | ||
73b65bb0 DJ |
3597 | There's no point in saying anything if the inferior has exited. |
3598 | Note that SIGNALLED here means "exited with a signal", not | |
3599 | "received a signal". */ | |
488f131b | 3600 | if (!ptid_equal (previous_inferior_ptid, inferior_ptid) |
73b65bb0 DJ |
3601 | && target_has_execution |
3602 | && last.kind != TARGET_WAITKIND_SIGNALLED | |
3603 | && last.kind != TARGET_WAITKIND_EXITED) | |
c906108c SS |
3604 | { |
3605 | target_terminal_ours_for_output (); | |
a3f17187 | 3606 | printf_filtered (_("[Switching to %s]\n"), |
c95310c6 | 3607 | target_pid_to_str (inferior_ptid)); |
b8fa951a | 3608 | annotate_thread_changed (); |
39f77062 | 3609 | previous_inferior_ptid = inferior_ptid; |
c906108c | 3610 | } |
c906108c | 3611 | |
4fa8626c | 3612 | /* NOTE drow/2004-01-17: Is this still necessary? */ |
c906108c SS |
3613 | /* Make sure that the current_frame's pc is correct. This |
3614 | is a correction for setting up the frame info before doing | |
b798847d | 3615 | gdbarch_decr_pc_after_break */ |
b87efeee AC |
3616 | if (target_has_execution) |
3617 | /* FIXME: cagney/2002-12-06: Has the PC changed? Thanks to | |
b798847d | 3618 | gdbarch_decr_pc_after_break, the program counter can change. Ask the |
b87efeee | 3619 | frame code to check for this and sort out any resultant mess. |
b798847d | 3620 | gdbarch_decr_pc_after_break needs to just go away. */ |
2f107107 | 3621 | deprecated_update_frame_pc_hack (get_current_frame (), read_pc ()); |
c906108c | 3622 | |
74960c60 | 3623 | if (!breakpoints_always_inserted_mode () && target_has_execution) |
c906108c SS |
3624 | { |
3625 | if (remove_breakpoints ()) | |
3626 | { | |
3627 | target_terminal_ours_for_output (); | |
a3f17187 AC |
3628 | printf_filtered (_("\ |
3629 | Cannot remove breakpoints because program is no longer writable.\n\ | |
3630 | It might be running in another process.\n\ | |
3631 | Further execution is probably impossible.\n")); | |
c906108c SS |
3632 | } |
3633 | } | |
c906108c | 3634 | |
c906108c SS |
3635 | /* If an auto-display called a function and that got a signal, |
3636 | delete that auto-display to avoid an infinite recursion. */ | |
3637 | ||
3638 | if (stopped_by_random_signal) | |
3639 | disable_current_display (); | |
3640 | ||
3641 | /* Don't print a message if in the middle of doing a "step n" | |
3642 | operation for n > 1 */ | |
3643 | if (step_multi && stop_step) | |
3644 | goto done; | |
3645 | ||
3646 | target_terminal_ours (); | |
3647 | ||
7abfe014 DJ |
3648 | /* Set the current source location. This will also happen if we |
3649 | display the frame below, but the current SAL will be incorrect | |
3650 | during a user hook-stop function. */ | |
3651 | if (target_has_stack && !stop_stack_dummy) | |
3652 | set_current_sal_from_frame (get_current_frame (), 1); | |
3653 | ||
5913bcb0 AC |
3654 | /* Look up the hook_stop and run it (CLI internally handles problem |
3655 | of stop_command's pre-hook not existing). */ | |
3656 | if (stop_command) | |
3657 | catch_errors (hook_stop_stub, stop_command, | |
3658 | "Error while running hook_stop:\n", RETURN_MASK_ALL); | |
c906108c SS |
3659 | |
3660 | if (!target_has_stack) | |
3661 | { | |
3662 | ||
3663 | goto done; | |
3664 | } | |
3665 | ||
3666 | /* Select innermost stack frame - i.e., current frame is frame 0, | |
3667 | and current location is based on that. | |
3668 | Don't do this on return from a stack dummy routine, | |
3669 | or if the program has exited. */ | |
3670 | ||
3671 | if (!stop_stack_dummy) | |
3672 | { | |
0f7d239c | 3673 | select_frame (get_current_frame ()); |
c906108c SS |
3674 | |
3675 | /* Print current location without a level number, if | |
c5aa993b JM |
3676 | we have changed functions or hit a breakpoint. |
3677 | Print source line if we have one. | |
3678 | bpstat_print() contains the logic deciding in detail | |
3679 | what to print, based on the event(s) that just occurred. */ | |
c906108c | 3680 | |
d01a8610 AS |
3681 | /* If --batch-silent is enabled then there's no need to print the current |
3682 | source location, and to try risks causing an error message about | |
3683 | missing source files. */ | |
3684 | if (stop_print_frame && !batch_silent) | |
c906108c SS |
3685 | { |
3686 | int bpstat_ret; | |
3687 | int source_flag; | |
917317f4 | 3688 | int do_frame_printing = 1; |
c906108c SS |
3689 | |
3690 | bpstat_ret = bpstat_print (stop_bpstat); | |
917317f4 JM |
3691 | switch (bpstat_ret) |
3692 | { | |
3693 | case PRINT_UNKNOWN: | |
b0f4b84b DJ |
3694 | /* If we had hit a shared library event breakpoint, |
3695 | bpstat_print would print out this message. If we hit | |
3696 | an OS-level shared library event, do the same | |
3697 | thing. */ | |
3698 | if (last.kind == TARGET_WAITKIND_LOADED) | |
3699 | { | |
3700 | printf_filtered (_("Stopped due to shared library event\n")); | |
3701 | source_flag = SRC_LINE; /* something bogus */ | |
3702 | do_frame_printing = 0; | |
3703 | break; | |
3704 | } | |
3705 | ||
aa0cd9c1 | 3706 | /* FIXME: cagney/2002-12-01: Given that a frame ID does |
8fb3e588 AC |
3707 | (or should) carry around the function and does (or |
3708 | should) use that when doing a frame comparison. */ | |
917317f4 | 3709 | if (stop_step |
aa0cd9c1 AC |
3710 | && frame_id_eq (step_frame_id, |
3711 | get_frame_id (get_current_frame ())) | |
917317f4 | 3712 | && step_start_function == find_pc_function (stop_pc)) |
488f131b | 3713 | source_flag = SRC_LINE; /* finished step, just print source line */ |
917317f4 | 3714 | else |
488f131b | 3715 | source_flag = SRC_AND_LOC; /* print location and source line */ |
917317f4 JM |
3716 | break; |
3717 | case PRINT_SRC_AND_LOC: | |
488f131b | 3718 | source_flag = SRC_AND_LOC; /* print location and source line */ |
917317f4 JM |
3719 | break; |
3720 | case PRINT_SRC_ONLY: | |
c5394b80 | 3721 | source_flag = SRC_LINE; |
917317f4 JM |
3722 | break; |
3723 | case PRINT_NOTHING: | |
488f131b | 3724 | source_flag = SRC_LINE; /* something bogus */ |
917317f4 JM |
3725 | do_frame_printing = 0; |
3726 | break; | |
3727 | default: | |
e2e0b3e5 | 3728 | internal_error (__FILE__, __LINE__, _("Unknown value.")); |
917317f4 | 3729 | } |
c906108c | 3730 | |
9dc5e2a9 | 3731 | if (ui_out_is_mi_like_p (uiout)) |
39f77062 | 3732 | ui_out_field_int (uiout, "thread-id", |
488f131b | 3733 | pid_to_thread_id (inferior_ptid)); |
c906108c SS |
3734 | /* The behavior of this routine with respect to the source |
3735 | flag is: | |
c5394b80 JM |
3736 | SRC_LINE: Print only source line |
3737 | LOCATION: Print only location | |
3738 | SRC_AND_LOC: Print location and source line */ | |
917317f4 | 3739 | if (do_frame_printing) |
b04f3ab4 | 3740 | print_stack_frame (get_selected_frame (NULL), 0, source_flag); |
c906108c SS |
3741 | |
3742 | /* Display the auto-display expressions. */ | |
3743 | do_displays (); | |
3744 | } | |
3745 | } | |
3746 | ||
3747 | /* Save the function value return registers, if we care. | |
3748 | We might be about to restore their previous contents. */ | |
3749 | if (proceed_to_finish) | |
d5c31457 UW |
3750 | { |
3751 | /* This should not be necessary. */ | |
3752 | if (stop_registers) | |
3753 | regcache_xfree (stop_registers); | |
3754 | ||
3755 | /* NB: The copy goes through to the target picking up the value of | |
3756 | all the registers. */ | |
3757 | stop_registers = regcache_dup (get_current_regcache ()); | |
3758 | } | |
c906108c SS |
3759 | |
3760 | if (stop_stack_dummy) | |
3761 | { | |
dbe9fe58 AC |
3762 | /* Pop the empty frame that contains the stack dummy. POP_FRAME |
3763 | ends with a setting of the current frame, so we can use that | |
3764 | next. */ | |
3765 | frame_pop (get_current_frame ()); | |
c906108c | 3766 | /* Set stop_pc to what it was before we called the function. |
c5aa993b JM |
3767 | Can't rely on restore_inferior_status because that only gets |
3768 | called if we don't stop in the called function. */ | |
c906108c | 3769 | stop_pc = read_pc (); |
0f7d239c | 3770 | select_frame (get_current_frame ()); |
c906108c SS |
3771 | } |
3772 | ||
c906108c SS |
3773 | done: |
3774 | annotate_stopped (); | |
8f6a8e84 | 3775 | if (!suppress_stop_observer && !step_multi) |
f5871ec0 | 3776 | observer_notify_normal_stop (stop_bpstat); |
2cec12e5 AR |
3777 | /* Delete the breakpoint we stopped at, if it wants to be deleted. |
3778 | Delete any breakpoint that is to be deleted at the next stop. */ | |
3779 | breakpoint_auto_delete (stop_bpstat); | |
e1ac3328 | 3780 | set_running (pid_to_ptid (-1), 0); |
c906108c SS |
3781 | } |
3782 | ||
3783 | static int | |
96baa820 | 3784 | hook_stop_stub (void *cmd) |
c906108c | 3785 | { |
5913bcb0 | 3786 | execute_cmd_pre_hook ((struct cmd_list_element *) cmd); |
c906108c SS |
3787 | return (0); |
3788 | } | |
3789 | \f | |
c5aa993b | 3790 | int |
96baa820 | 3791 | signal_stop_state (int signo) |
c906108c | 3792 | { |
a0ef4274 DJ |
3793 | /* Always stop on signals if we're just gaining control of the |
3794 | program. */ | |
3795 | return signal_stop[signo] || stop_soon != NO_STOP_QUIETLY; | |
c906108c SS |
3796 | } |
3797 | ||
c5aa993b | 3798 | int |
96baa820 | 3799 | signal_print_state (int signo) |
c906108c SS |
3800 | { |
3801 | return signal_print[signo]; | |
3802 | } | |
3803 | ||
c5aa993b | 3804 | int |
96baa820 | 3805 | signal_pass_state (int signo) |
c906108c SS |
3806 | { |
3807 | return signal_program[signo]; | |
3808 | } | |
3809 | ||
488f131b | 3810 | int |
7bda5e4a | 3811 | signal_stop_update (int signo, int state) |
d4f3574e SS |
3812 | { |
3813 | int ret = signal_stop[signo]; | |
3814 | signal_stop[signo] = state; | |
3815 | return ret; | |
3816 | } | |
3817 | ||
488f131b | 3818 | int |
7bda5e4a | 3819 | signal_print_update (int signo, int state) |
d4f3574e SS |
3820 | { |
3821 | int ret = signal_print[signo]; | |
3822 | signal_print[signo] = state; | |
3823 | return ret; | |
3824 | } | |
3825 | ||
488f131b | 3826 | int |
7bda5e4a | 3827 | signal_pass_update (int signo, int state) |
d4f3574e SS |
3828 | { |
3829 | int ret = signal_program[signo]; | |
3830 | signal_program[signo] = state; | |
3831 | return ret; | |
3832 | } | |
3833 | ||
c906108c | 3834 | static void |
96baa820 | 3835 | sig_print_header (void) |
c906108c | 3836 | { |
a3f17187 AC |
3837 | printf_filtered (_("\ |
3838 | Signal Stop\tPrint\tPass to program\tDescription\n")); | |
c906108c SS |
3839 | } |
3840 | ||
3841 | static void | |
96baa820 | 3842 | sig_print_info (enum target_signal oursig) |
c906108c SS |
3843 | { |
3844 | char *name = target_signal_to_name (oursig); | |
3845 | int name_padding = 13 - strlen (name); | |
96baa820 | 3846 | |
c906108c SS |
3847 | if (name_padding <= 0) |
3848 | name_padding = 0; | |
3849 | ||
3850 | printf_filtered ("%s", name); | |
488f131b | 3851 | printf_filtered ("%*.*s ", name_padding, name_padding, " "); |
c906108c SS |
3852 | printf_filtered ("%s\t", signal_stop[oursig] ? "Yes" : "No"); |
3853 | printf_filtered ("%s\t", signal_print[oursig] ? "Yes" : "No"); | |
3854 | printf_filtered ("%s\t\t", signal_program[oursig] ? "Yes" : "No"); | |
3855 | printf_filtered ("%s\n", target_signal_to_string (oursig)); | |
3856 | } | |
3857 | ||
3858 | /* Specify how various signals in the inferior should be handled. */ | |
3859 | ||
3860 | static void | |
96baa820 | 3861 | handle_command (char *args, int from_tty) |
c906108c SS |
3862 | { |
3863 | char **argv; | |
3864 | int digits, wordlen; | |
3865 | int sigfirst, signum, siglast; | |
3866 | enum target_signal oursig; | |
3867 | int allsigs; | |
3868 | int nsigs; | |
3869 | unsigned char *sigs; | |
3870 | struct cleanup *old_chain; | |
3871 | ||
3872 | if (args == NULL) | |
3873 | { | |
e2e0b3e5 | 3874 | error_no_arg (_("signal to handle")); |
c906108c SS |
3875 | } |
3876 | ||
3877 | /* Allocate and zero an array of flags for which signals to handle. */ | |
3878 | ||
3879 | nsigs = (int) TARGET_SIGNAL_LAST; | |
3880 | sigs = (unsigned char *) alloca (nsigs); | |
3881 | memset (sigs, 0, nsigs); | |
3882 | ||
3883 | /* Break the command line up into args. */ | |
3884 | ||
3885 | argv = buildargv (args); | |
3886 | if (argv == NULL) | |
3887 | { | |
3888 | nomem (0); | |
3889 | } | |
7a292a7a | 3890 | old_chain = make_cleanup_freeargv (argv); |
c906108c SS |
3891 | |
3892 | /* Walk through the args, looking for signal oursigs, signal names, and | |
3893 | actions. Signal numbers and signal names may be interspersed with | |
3894 | actions, with the actions being performed for all signals cumulatively | |
3895 | specified. Signal ranges can be specified as <LOW>-<HIGH>. */ | |
3896 | ||
3897 | while (*argv != NULL) | |
3898 | { | |
3899 | wordlen = strlen (*argv); | |
3900 | for (digits = 0; isdigit ((*argv)[digits]); digits++) | |
3901 | {; | |
3902 | } | |
3903 | allsigs = 0; | |
3904 | sigfirst = siglast = -1; | |
3905 | ||
3906 | if (wordlen >= 1 && !strncmp (*argv, "all", wordlen)) | |
3907 | { | |
3908 | /* Apply action to all signals except those used by the | |
3909 | debugger. Silently skip those. */ | |
3910 | allsigs = 1; | |
3911 | sigfirst = 0; | |
3912 | siglast = nsigs - 1; | |
3913 | } | |
3914 | else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen)) | |
3915 | { | |
3916 | SET_SIGS (nsigs, sigs, signal_stop); | |
3917 | SET_SIGS (nsigs, sigs, signal_print); | |
3918 | } | |
3919 | else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen)) | |
3920 | { | |
3921 | UNSET_SIGS (nsigs, sigs, signal_program); | |
3922 | } | |
3923 | else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen)) | |
3924 | { | |
3925 | SET_SIGS (nsigs, sigs, signal_print); | |
3926 | } | |
3927 | else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen)) | |
3928 | { | |
3929 | SET_SIGS (nsigs, sigs, signal_program); | |
3930 | } | |
3931 | else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen)) | |
3932 | { | |
3933 | UNSET_SIGS (nsigs, sigs, signal_stop); | |
3934 | } | |
3935 | else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen)) | |
3936 | { | |
3937 | SET_SIGS (nsigs, sigs, signal_program); | |
3938 | } | |
3939 | else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen)) | |
3940 | { | |
3941 | UNSET_SIGS (nsigs, sigs, signal_print); | |
3942 | UNSET_SIGS (nsigs, sigs, signal_stop); | |
3943 | } | |
3944 | else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen)) | |
3945 | { | |
3946 | UNSET_SIGS (nsigs, sigs, signal_program); | |
3947 | } | |
3948 | else if (digits > 0) | |
3949 | { | |
3950 | /* It is numeric. The numeric signal refers to our own | |
3951 | internal signal numbering from target.h, not to host/target | |
3952 | signal number. This is a feature; users really should be | |
3953 | using symbolic names anyway, and the common ones like | |
3954 | SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */ | |
3955 | ||
3956 | sigfirst = siglast = (int) | |
3957 | target_signal_from_command (atoi (*argv)); | |
3958 | if ((*argv)[digits] == '-') | |
3959 | { | |
3960 | siglast = (int) | |
3961 | target_signal_from_command (atoi ((*argv) + digits + 1)); | |
3962 | } | |
3963 | if (sigfirst > siglast) | |
3964 | { | |
3965 | /* Bet he didn't figure we'd think of this case... */ | |
3966 | signum = sigfirst; | |
3967 | sigfirst = siglast; | |
3968 | siglast = signum; | |
3969 | } | |
3970 | } | |
3971 | else | |
3972 | { | |
3973 | oursig = target_signal_from_name (*argv); | |
3974 | if (oursig != TARGET_SIGNAL_UNKNOWN) | |
3975 | { | |
3976 | sigfirst = siglast = (int) oursig; | |
3977 | } | |
3978 | else | |
3979 | { | |
3980 | /* Not a number and not a recognized flag word => complain. */ | |
8a3fe4f8 | 3981 | error (_("Unrecognized or ambiguous flag word: \"%s\"."), *argv); |
c906108c SS |
3982 | } |
3983 | } | |
3984 | ||
3985 | /* If any signal numbers or symbol names were found, set flags for | |
c5aa993b | 3986 | which signals to apply actions to. */ |
c906108c SS |
3987 | |
3988 | for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++) | |
3989 | { | |
3990 | switch ((enum target_signal) signum) | |
3991 | { | |
3992 | case TARGET_SIGNAL_TRAP: | |
3993 | case TARGET_SIGNAL_INT: | |
3994 | if (!allsigs && !sigs[signum]) | |
3995 | { | |
3996 | if (query ("%s is used by the debugger.\n\ | |
488f131b | 3997 | Are you sure you want to change it? ", target_signal_to_name ((enum target_signal) signum))) |
c906108c SS |
3998 | { |
3999 | sigs[signum] = 1; | |
4000 | } | |
4001 | else | |
4002 | { | |
a3f17187 | 4003 | printf_unfiltered (_("Not confirmed, unchanged.\n")); |
c906108c SS |
4004 | gdb_flush (gdb_stdout); |
4005 | } | |
4006 | } | |
4007 | break; | |
4008 | case TARGET_SIGNAL_0: | |
4009 | case TARGET_SIGNAL_DEFAULT: | |
4010 | case TARGET_SIGNAL_UNKNOWN: | |
4011 | /* Make sure that "all" doesn't print these. */ | |
4012 | break; | |
4013 | default: | |
4014 | sigs[signum] = 1; | |
4015 | break; | |
4016 | } | |
4017 | } | |
4018 | ||
4019 | argv++; | |
4020 | } | |
4021 | ||
39f77062 | 4022 | target_notice_signals (inferior_ptid); |
c906108c SS |
4023 | |
4024 | if (from_tty) | |
4025 | { | |
4026 | /* Show the results. */ | |
4027 | sig_print_header (); | |
4028 | for (signum = 0; signum < nsigs; signum++) | |
4029 | { | |
4030 | if (sigs[signum]) | |
4031 | { | |
4032 | sig_print_info (signum); | |
4033 | } | |
4034 | } | |
4035 | } | |
4036 | ||
4037 | do_cleanups (old_chain); | |
4038 | } | |
4039 | ||
4040 | static void | |
96baa820 | 4041 | xdb_handle_command (char *args, int from_tty) |
c906108c SS |
4042 | { |
4043 | char **argv; | |
4044 | struct cleanup *old_chain; | |
4045 | ||
4046 | /* Break the command line up into args. */ | |
4047 | ||
4048 | argv = buildargv (args); | |
4049 | if (argv == NULL) | |
4050 | { | |
4051 | nomem (0); | |
4052 | } | |
7a292a7a | 4053 | old_chain = make_cleanup_freeargv (argv); |
c906108c SS |
4054 | if (argv[1] != (char *) NULL) |
4055 | { | |
4056 | char *argBuf; | |
4057 | int bufLen; | |
4058 | ||
4059 | bufLen = strlen (argv[0]) + 20; | |
4060 | argBuf = (char *) xmalloc (bufLen); | |
4061 | if (argBuf) | |
4062 | { | |
4063 | int validFlag = 1; | |
4064 | enum target_signal oursig; | |
4065 | ||
4066 | oursig = target_signal_from_name (argv[0]); | |
4067 | memset (argBuf, 0, bufLen); | |
4068 | if (strcmp (argv[1], "Q") == 0) | |
4069 | sprintf (argBuf, "%s %s", argv[0], "noprint"); | |
4070 | else | |
4071 | { | |
4072 | if (strcmp (argv[1], "s") == 0) | |
4073 | { | |
4074 | if (!signal_stop[oursig]) | |
4075 | sprintf (argBuf, "%s %s", argv[0], "stop"); | |
4076 | else | |
4077 | sprintf (argBuf, "%s %s", argv[0], "nostop"); | |
4078 | } | |
4079 | else if (strcmp (argv[1], "i") == 0) | |
4080 | { | |
4081 | if (!signal_program[oursig]) | |
4082 | sprintf (argBuf, "%s %s", argv[0], "pass"); | |
4083 | else | |
4084 | sprintf (argBuf, "%s %s", argv[0], "nopass"); | |
4085 | } | |
4086 | else if (strcmp (argv[1], "r") == 0) | |
4087 | { | |
4088 | if (!signal_print[oursig]) | |
4089 | sprintf (argBuf, "%s %s", argv[0], "print"); | |
4090 | else | |
4091 | sprintf (argBuf, "%s %s", argv[0], "noprint"); | |
4092 | } | |
4093 | else | |
4094 | validFlag = 0; | |
4095 | } | |
4096 | if (validFlag) | |
4097 | handle_command (argBuf, from_tty); | |
4098 | else | |
a3f17187 | 4099 | printf_filtered (_("Invalid signal handling flag.\n")); |
c906108c | 4100 | if (argBuf) |
b8c9b27d | 4101 | xfree (argBuf); |
c906108c SS |
4102 | } |
4103 | } | |
4104 | do_cleanups (old_chain); | |
4105 | } | |
4106 | ||
4107 | /* Print current contents of the tables set by the handle command. | |
4108 | It is possible we should just be printing signals actually used | |
4109 | by the current target (but for things to work right when switching | |
4110 | targets, all signals should be in the signal tables). */ | |
4111 | ||
4112 | static void | |
96baa820 | 4113 | signals_info (char *signum_exp, int from_tty) |
c906108c SS |
4114 | { |
4115 | enum target_signal oursig; | |
4116 | sig_print_header (); | |
4117 | ||
4118 | if (signum_exp) | |
4119 | { | |
4120 | /* First see if this is a symbol name. */ | |
4121 | oursig = target_signal_from_name (signum_exp); | |
4122 | if (oursig == TARGET_SIGNAL_UNKNOWN) | |
4123 | { | |
4124 | /* No, try numeric. */ | |
4125 | oursig = | |
bb518678 | 4126 | target_signal_from_command (parse_and_eval_long (signum_exp)); |
c906108c SS |
4127 | } |
4128 | sig_print_info (oursig); | |
4129 | return; | |
4130 | } | |
4131 | ||
4132 | printf_filtered ("\n"); | |
4133 | /* These ugly casts brought to you by the native VAX compiler. */ | |
4134 | for (oursig = TARGET_SIGNAL_FIRST; | |
4135 | (int) oursig < (int) TARGET_SIGNAL_LAST; | |
4136 | oursig = (enum target_signal) ((int) oursig + 1)) | |
4137 | { | |
4138 | QUIT; | |
4139 | ||
4140 | if (oursig != TARGET_SIGNAL_UNKNOWN | |
488f131b | 4141 | && oursig != TARGET_SIGNAL_DEFAULT && oursig != TARGET_SIGNAL_0) |
c906108c SS |
4142 | sig_print_info (oursig); |
4143 | } | |
4144 | ||
a3f17187 | 4145 | printf_filtered (_("\nUse the \"handle\" command to change these tables.\n")); |
c906108c SS |
4146 | } |
4147 | \f | |
7a292a7a SS |
4148 | struct inferior_status |
4149 | { | |
4150 | enum target_signal stop_signal; | |
4151 | CORE_ADDR stop_pc; | |
4152 | bpstat stop_bpstat; | |
4153 | int stop_step; | |
4154 | int stop_stack_dummy; | |
4155 | int stopped_by_random_signal; | |
ca67fcb8 | 4156 | int stepping_over_breakpoint; |
7a292a7a SS |
4157 | CORE_ADDR step_range_start; |
4158 | CORE_ADDR step_range_end; | |
aa0cd9c1 | 4159 | struct frame_id step_frame_id; |
5fbbeb29 | 4160 | enum step_over_calls_kind step_over_calls; |
7a292a7a SS |
4161 | CORE_ADDR step_resume_break_address; |
4162 | int stop_after_trap; | |
c0236d92 | 4163 | int stop_soon; |
7a292a7a SS |
4164 | |
4165 | /* These are here because if call_function_by_hand has written some | |
4166 | registers and then decides to call error(), we better not have changed | |
4167 | any registers. */ | |
72cec141 | 4168 | struct regcache *registers; |
7a292a7a | 4169 | |
101dcfbe AC |
4170 | /* A frame unique identifier. */ |
4171 | struct frame_id selected_frame_id; | |
4172 | ||
7a292a7a SS |
4173 | int breakpoint_proceeded; |
4174 | int restore_stack_info; | |
4175 | int proceed_to_finish; | |
4176 | }; | |
4177 | ||
7a292a7a | 4178 | void |
96baa820 JM |
4179 | write_inferior_status_register (struct inferior_status *inf_status, int regno, |
4180 | LONGEST val) | |
7a292a7a | 4181 | { |
3acba339 | 4182 | int size = register_size (current_gdbarch, regno); |
7a292a7a SS |
4183 | void *buf = alloca (size); |
4184 | store_signed_integer (buf, size, val); | |
0818c12a | 4185 | regcache_raw_write (inf_status->registers, regno, buf); |
7a292a7a SS |
4186 | } |
4187 | ||
c906108c SS |
4188 | /* Save all of the information associated with the inferior<==>gdb |
4189 | connection. INF_STATUS is a pointer to a "struct inferior_status" | |
4190 | (defined in inferior.h). */ | |
4191 | ||
7a292a7a | 4192 | struct inferior_status * |
96baa820 | 4193 | save_inferior_status (int restore_stack_info) |
c906108c | 4194 | { |
72cec141 | 4195 | struct inferior_status *inf_status = XMALLOC (struct inferior_status); |
7a292a7a | 4196 | |
c906108c SS |
4197 | inf_status->stop_signal = stop_signal; |
4198 | inf_status->stop_pc = stop_pc; | |
4199 | inf_status->stop_step = stop_step; | |
4200 | inf_status->stop_stack_dummy = stop_stack_dummy; | |
4201 | inf_status->stopped_by_random_signal = stopped_by_random_signal; | |
ca67fcb8 | 4202 | inf_status->stepping_over_breakpoint = stepping_over_breakpoint; |
c906108c SS |
4203 | inf_status->step_range_start = step_range_start; |
4204 | inf_status->step_range_end = step_range_end; | |
aa0cd9c1 | 4205 | inf_status->step_frame_id = step_frame_id; |
c906108c SS |
4206 | inf_status->step_over_calls = step_over_calls; |
4207 | inf_status->stop_after_trap = stop_after_trap; | |
c0236d92 | 4208 | inf_status->stop_soon = stop_soon; |
c906108c SS |
4209 | /* Save original bpstat chain here; replace it with copy of chain. |
4210 | If caller's caller is walking the chain, they'll be happier if we | |
7a292a7a SS |
4211 | hand them back the original chain when restore_inferior_status is |
4212 | called. */ | |
c906108c SS |
4213 | inf_status->stop_bpstat = stop_bpstat; |
4214 | stop_bpstat = bpstat_copy (stop_bpstat); | |
4215 | inf_status->breakpoint_proceeded = breakpoint_proceeded; | |
4216 | inf_status->restore_stack_info = restore_stack_info; | |
4217 | inf_status->proceed_to_finish = proceed_to_finish; | |
c5aa993b | 4218 | |
594f7785 | 4219 | inf_status->registers = regcache_dup (get_current_regcache ()); |
c906108c | 4220 | |
206415a3 | 4221 | inf_status->selected_frame_id = get_frame_id (get_selected_frame (NULL)); |
7a292a7a | 4222 | return inf_status; |
c906108c SS |
4223 | } |
4224 | ||
c906108c | 4225 | static int |
96baa820 | 4226 | restore_selected_frame (void *args) |
c906108c | 4227 | { |
488f131b | 4228 | struct frame_id *fid = (struct frame_id *) args; |
c906108c | 4229 | struct frame_info *frame; |
c906108c | 4230 | |
101dcfbe | 4231 | frame = frame_find_by_id (*fid); |
c906108c | 4232 | |
aa0cd9c1 AC |
4233 | /* If inf_status->selected_frame_id is NULL, there was no previously |
4234 | selected frame. */ | |
101dcfbe | 4235 | if (frame == NULL) |
c906108c | 4236 | { |
8a3fe4f8 | 4237 | warning (_("Unable to restore previously selected frame.")); |
c906108c SS |
4238 | return 0; |
4239 | } | |
4240 | ||
0f7d239c | 4241 | select_frame (frame); |
c906108c SS |
4242 | |
4243 | return (1); | |
4244 | } | |
4245 | ||
4246 | void | |
96baa820 | 4247 | restore_inferior_status (struct inferior_status *inf_status) |
c906108c SS |
4248 | { |
4249 | stop_signal = inf_status->stop_signal; | |
4250 | stop_pc = inf_status->stop_pc; | |
4251 | stop_step = inf_status->stop_step; | |
4252 | stop_stack_dummy = inf_status->stop_stack_dummy; | |
4253 | stopped_by_random_signal = inf_status->stopped_by_random_signal; | |
ca67fcb8 | 4254 | stepping_over_breakpoint = inf_status->stepping_over_breakpoint; |
c906108c SS |
4255 | step_range_start = inf_status->step_range_start; |
4256 | step_range_end = inf_status->step_range_end; | |
aa0cd9c1 | 4257 | step_frame_id = inf_status->step_frame_id; |
c906108c SS |
4258 | step_over_calls = inf_status->step_over_calls; |
4259 | stop_after_trap = inf_status->stop_after_trap; | |
c0236d92 | 4260 | stop_soon = inf_status->stop_soon; |
c906108c SS |
4261 | bpstat_clear (&stop_bpstat); |
4262 | stop_bpstat = inf_status->stop_bpstat; | |
4263 | breakpoint_proceeded = inf_status->breakpoint_proceeded; | |
4264 | proceed_to_finish = inf_status->proceed_to_finish; | |
4265 | ||
c906108c SS |
4266 | /* The inferior can be gone if the user types "print exit(0)" |
4267 | (and perhaps other times). */ | |
4268 | if (target_has_execution) | |
72cec141 | 4269 | /* NB: The register write goes through to the target. */ |
594f7785 | 4270 | regcache_cpy (get_current_regcache (), inf_status->registers); |
72cec141 | 4271 | regcache_xfree (inf_status->registers); |
c906108c | 4272 | |
c906108c SS |
4273 | /* FIXME: If we are being called after stopping in a function which |
4274 | is called from gdb, we should not be trying to restore the | |
4275 | selected frame; it just prints a spurious error message (The | |
4276 | message is useful, however, in detecting bugs in gdb (like if gdb | |
4277 | clobbers the stack)). In fact, should we be restoring the | |
4278 | inferior status at all in that case? . */ | |
4279 | ||
4280 | if (target_has_stack && inf_status->restore_stack_info) | |
4281 | { | |
c906108c | 4282 | /* The point of catch_errors is that if the stack is clobbered, |
101dcfbe AC |
4283 | walking the stack might encounter a garbage pointer and |
4284 | error() trying to dereference it. */ | |
488f131b JB |
4285 | if (catch_errors |
4286 | (restore_selected_frame, &inf_status->selected_frame_id, | |
4287 | "Unable to restore previously selected frame:\n", | |
4288 | RETURN_MASK_ERROR) == 0) | |
c906108c SS |
4289 | /* Error in restoring the selected frame. Select the innermost |
4290 | frame. */ | |
0f7d239c | 4291 | select_frame (get_current_frame ()); |
c906108c SS |
4292 | |
4293 | } | |
c906108c | 4294 | |
72cec141 | 4295 | xfree (inf_status); |
7a292a7a | 4296 | } |
c906108c | 4297 | |
74b7792f AC |
4298 | static void |
4299 | do_restore_inferior_status_cleanup (void *sts) | |
4300 | { | |
4301 | restore_inferior_status (sts); | |
4302 | } | |
4303 | ||
4304 | struct cleanup * | |
4305 | make_cleanup_restore_inferior_status (struct inferior_status *inf_status) | |
4306 | { | |
4307 | return make_cleanup (do_restore_inferior_status_cleanup, inf_status); | |
4308 | } | |
4309 | ||
c906108c | 4310 | void |
96baa820 | 4311 | discard_inferior_status (struct inferior_status *inf_status) |
7a292a7a SS |
4312 | { |
4313 | /* See save_inferior_status for info on stop_bpstat. */ | |
4314 | bpstat_clear (&inf_status->stop_bpstat); | |
72cec141 | 4315 | regcache_xfree (inf_status->registers); |
72cec141 | 4316 | xfree (inf_status); |
7a292a7a SS |
4317 | } |
4318 | ||
47932f85 DJ |
4319 | int |
4320 | inferior_has_forked (int pid, int *child_pid) | |
4321 | { | |
4322 | struct target_waitstatus last; | |
4323 | ptid_t last_ptid; | |
4324 | ||
4325 | get_last_target_status (&last_ptid, &last); | |
4326 | ||
4327 | if (last.kind != TARGET_WAITKIND_FORKED) | |
4328 | return 0; | |
4329 | ||
4330 | if (ptid_get_pid (last_ptid) != pid) | |
4331 | return 0; | |
4332 | ||
4333 | *child_pid = last.value.related_pid; | |
4334 | return 1; | |
4335 | } | |
4336 | ||
4337 | int | |
4338 | inferior_has_vforked (int pid, int *child_pid) | |
4339 | { | |
4340 | struct target_waitstatus last; | |
4341 | ptid_t last_ptid; | |
4342 | ||
4343 | get_last_target_status (&last_ptid, &last); | |
4344 | ||
4345 | if (last.kind != TARGET_WAITKIND_VFORKED) | |
4346 | return 0; | |
4347 | ||
4348 | if (ptid_get_pid (last_ptid) != pid) | |
4349 | return 0; | |
4350 | ||
4351 | *child_pid = last.value.related_pid; | |
4352 | return 1; | |
4353 | } | |
4354 | ||
4355 | int | |
4356 | inferior_has_execd (int pid, char **execd_pathname) | |
4357 | { | |
4358 | struct target_waitstatus last; | |
4359 | ptid_t last_ptid; | |
4360 | ||
4361 | get_last_target_status (&last_ptid, &last); | |
4362 | ||
4363 | if (last.kind != TARGET_WAITKIND_EXECD) | |
4364 | return 0; | |
4365 | ||
4366 | if (ptid_get_pid (last_ptid) != pid) | |
4367 | return 0; | |
4368 | ||
4369 | *execd_pathname = xstrdup (last.value.execd_pathname); | |
4370 | return 1; | |
4371 | } | |
4372 | ||
ca6724c1 KB |
4373 | /* Oft used ptids */ |
4374 | ptid_t null_ptid; | |
4375 | ptid_t minus_one_ptid; | |
4376 | ||
4377 | /* Create a ptid given the necessary PID, LWP, and TID components. */ | |
488f131b | 4378 | |
ca6724c1 KB |
4379 | ptid_t |
4380 | ptid_build (int pid, long lwp, long tid) | |
4381 | { | |
4382 | ptid_t ptid; | |
4383 | ||
4384 | ptid.pid = pid; | |
4385 | ptid.lwp = lwp; | |
4386 | ptid.tid = tid; | |
4387 | return ptid; | |
4388 | } | |
4389 | ||
4390 | /* Create a ptid from just a pid. */ | |
4391 | ||
4392 | ptid_t | |
4393 | pid_to_ptid (int pid) | |
4394 | { | |
4395 | return ptid_build (pid, 0, 0); | |
4396 | } | |
4397 | ||
4398 | /* Fetch the pid (process id) component from a ptid. */ | |
4399 | ||
4400 | int | |
4401 | ptid_get_pid (ptid_t ptid) | |
4402 | { | |
4403 | return ptid.pid; | |
4404 | } | |
4405 | ||
4406 | /* Fetch the lwp (lightweight process) component from a ptid. */ | |
4407 | ||
4408 | long | |
4409 | ptid_get_lwp (ptid_t ptid) | |
4410 | { | |
4411 | return ptid.lwp; | |
4412 | } | |
4413 | ||
4414 | /* Fetch the tid (thread id) component from a ptid. */ | |
4415 | ||
4416 | long | |
4417 | ptid_get_tid (ptid_t ptid) | |
4418 | { | |
4419 | return ptid.tid; | |
4420 | } | |
4421 | ||
4422 | /* ptid_equal() is used to test equality of two ptids. */ | |
4423 | ||
4424 | int | |
4425 | ptid_equal (ptid_t ptid1, ptid_t ptid2) | |
4426 | { | |
4427 | return (ptid1.pid == ptid2.pid && ptid1.lwp == ptid2.lwp | |
488f131b | 4428 | && ptid1.tid == ptid2.tid); |
ca6724c1 KB |
4429 | } |
4430 | ||
4431 | /* restore_inferior_ptid() will be used by the cleanup machinery | |
4432 | to restore the inferior_ptid value saved in a call to | |
4433 | save_inferior_ptid(). */ | |
ce696e05 KB |
4434 | |
4435 | static void | |
4436 | restore_inferior_ptid (void *arg) | |
4437 | { | |
4438 | ptid_t *saved_ptid_ptr = arg; | |
4439 | inferior_ptid = *saved_ptid_ptr; | |
4440 | xfree (arg); | |
4441 | } | |
4442 | ||
4443 | /* Save the value of inferior_ptid so that it may be restored by a | |
4444 | later call to do_cleanups(). Returns the struct cleanup pointer | |
4445 | needed for later doing the cleanup. */ | |
4446 | ||
4447 | struct cleanup * | |
4448 | save_inferior_ptid (void) | |
4449 | { | |
4450 | ptid_t *saved_ptid_ptr; | |
4451 | ||
4452 | saved_ptid_ptr = xmalloc (sizeof (ptid_t)); | |
4453 | *saved_ptid_ptr = inferior_ptid; | |
4454 | return make_cleanup (restore_inferior_ptid, saved_ptid_ptr); | |
4455 | } | |
c5aa993b | 4456 | \f |
488f131b | 4457 | |
c906108c | 4458 | void |
96baa820 | 4459 | _initialize_infrun (void) |
c906108c | 4460 | { |
52f0bd74 AC |
4461 | int i; |
4462 | int numsigs; | |
c906108c SS |
4463 | struct cmd_list_element *c; |
4464 | ||
1bedd215 AC |
4465 | add_info ("signals", signals_info, _("\ |
4466 | What debugger does when program gets various signals.\n\ | |
4467 | Specify a signal as argument to print info on that signal only.")); | |
c906108c SS |
4468 | add_info_alias ("handle", "signals", 0); |
4469 | ||
1bedd215 AC |
4470 | add_com ("handle", class_run, handle_command, _("\ |
4471 | Specify how to handle a signal.\n\ | |
c906108c SS |
4472 | Args are signals and actions to apply to those signals.\n\ |
4473 | Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\ | |
4474 | from 1-15 are allowed for compatibility with old versions of GDB.\n\ | |
4475 | Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\ | |
4476 | The special arg \"all\" is recognized to mean all signals except those\n\ | |
1bedd215 AC |
4477 | used by the debugger, typically SIGTRAP and SIGINT.\n\ |
4478 | Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\ | |
c906108c SS |
4479 | \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\ |
4480 | Stop means reenter debugger if this signal happens (implies print).\n\ | |
4481 | Print means print a message if this signal happens.\n\ | |
4482 | Pass means let program see this signal; otherwise program doesn't know.\n\ | |
4483 | Ignore is a synonym for nopass and noignore is a synonym for pass.\n\ | |
1bedd215 | 4484 | Pass and Stop may be combined.")); |
c906108c SS |
4485 | if (xdb_commands) |
4486 | { | |
1bedd215 AC |
4487 | add_com ("lz", class_info, signals_info, _("\ |
4488 | What debugger does when program gets various signals.\n\ | |
4489 | Specify a signal as argument to print info on that signal only.")); | |
4490 | add_com ("z", class_run, xdb_handle_command, _("\ | |
4491 | Specify how to handle a signal.\n\ | |
c906108c SS |
4492 | Args are signals and actions to apply to those signals.\n\ |
4493 | Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\ | |
4494 | from 1-15 are allowed for compatibility with old versions of GDB.\n\ | |
4495 | Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\ | |
4496 | The special arg \"all\" is recognized to mean all signals except those\n\ | |
1bedd215 AC |
4497 | used by the debugger, typically SIGTRAP and SIGINT.\n\ |
4498 | Recognized actions include \"s\" (toggles between stop and nostop), \n\ | |
c906108c SS |
4499 | \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \ |
4500 | nopass), \"Q\" (noprint)\n\ | |
4501 | Stop means reenter debugger if this signal happens (implies print).\n\ | |
4502 | Print means print a message if this signal happens.\n\ | |
4503 | Pass means let program see this signal; otherwise program doesn't know.\n\ | |
4504 | Ignore is a synonym for nopass and noignore is a synonym for pass.\n\ | |
1bedd215 | 4505 | Pass and Stop may be combined.")); |
c906108c SS |
4506 | } |
4507 | ||
4508 | if (!dbx_commands) | |
1a966eab AC |
4509 | stop_command = add_cmd ("stop", class_obscure, |
4510 | not_just_help_class_command, _("\ | |
4511 | There is no `stop' command, but you can set a hook on `stop'.\n\ | |
c906108c | 4512 | This allows you to set a list of commands to be run each time execution\n\ |
1a966eab | 4513 | of the program stops."), &cmdlist); |
c906108c | 4514 | |
85c07804 AC |
4515 | add_setshow_zinteger_cmd ("infrun", class_maintenance, &debug_infrun, _("\ |
4516 | Set inferior debugging."), _("\ | |
4517 | Show inferior debugging."), _("\ | |
4518 | When non-zero, inferior specific debugging is enabled."), | |
4519 | NULL, | |
920d2a44 | 4520 | show_debug_infrun, |
85c07804 | 4521 | &setdebuglist, &showdebuglist); |
527159b7 | 4522 | |
237fc4c9 PA |
4523 | add_setshow_boolean_cmd ("displaced", class_maintenance, &debug_displaced, _("\ |
4524 | Set displaced stepping debugging."), _("\ | |
4525 | Show displaced stepping debugging."), _("\ | |
4526 | When non-zero, displaced stepping specific debugging is enabled."), | |
4527 | NULL, | |
4528 | show_debug_displaced, | |
4529 | &setdebuglist, &showdebuglist); | |
4530 | ||
c906108c | 4531 | numsigs = (int) TARGET_SIGNAL_LAST; |
488f131b | 4532 | signal_stop = (unsigned char *) xmalloc (sizeof (signal_stop[0]) * numsigs); |
c906108c SS |
4533 | signal_print = (unsigned char *) |
4534 | xmalloc (sizeof (signal_print[0]) * numsigs); | |
4535 | signal_program = (unsigned char *) | |
4536 | xmalloc (sizeof (signal_program[0]) * numsigs); | |
4537 | for (i = 0; i < numsigs; i++) | |
4538 | { | |
4539 | signal_stop[i] = 1; | |
4540 | signal_print[i] = 1; | |
4541 | signal_program[i] = 1; | |
4542 | } | |
4543 | ||
4544 | /* Signals caused by debugger's own actions | |
4545 | should not be given to the program afterwards. */ | |
4546 | signal_program[TARGET_SIGNAL_TRAP] = 0; | |
4547 | signal_program[TARGET_SIGNAL_INT] = 0; | |
4548 | ||
4549 | /* Signals that are not errors should not normally enter the debugger. */ | |
4550 | signal_stop[TARGET_SIGNAL_ALRM] = 0; | |
4551 | signal_print[TARGET_SIGNAL_ALRM] = 0; | |
4552 | signal_stop[TARGET_SIGNAL_VTALRM] = 0; | |
4553 | signal_print[TARGET_SIGNAL_VTALRM] = 0; | |
4554 | signal_stop[TARGET_SIGNAL_PROF] = 0; | |
4555 | signal_print[TARGET_SIGNAL_PROF] = 0; | |
4556 | signal_stop[TARGET_SIGNAL_CHLD] = 0; | |
4557 | signal_print[TARGET_SIGNAL_CHLD] = 0; | |
4558 | signal_stop[TARGET_SIGNAL_IO] = 0; | |
4559 | signal_print[TARGET_SIGNAL_IO] = 0; | |
4560 | signal_stop[TARGET_SIGNAL_POLL] = 0; | |
4561 | signal_print[TARGET_SIGNAL_POLL] = 0; | |
4562 | signal_stop[TARGET_SIGNAL_URG] = 0; | |
4563 | signal_print[TARGET_SIGNAL_URG] = 0; | |
4564 | signal_stop[TARGET_SIGNAL_WINCH] = 0; | |
4565 | signal_print[TARGET_SIGNAL_WINCH] = 0; | |
4566 | ||
cd0fc7c3 SS |
4567 | /* These signals are used internally by user-level thread |
4568 | implementations. (See signal(5) on Solaris.) Like the above | |
4569 | signals, a healthy program receives and handles them as part of | |
4570 | its normal operation. */ | |
4571 | signal_stop[TARGET_SIGNAL_LWP] = 0; | |
4572 | signal_print[TARGET_SIGNAL_LWP] = 0; | |
4573 | signal_stop[TARGET_SIGNAL_WAITING] = 0; | |
4574 | signal_print[TARGET_SIGNAL_WAITING] = 0; | |
4575 | signal_stop[TARGET_SIGNAL_CANCEL] = 0; | |
4576 | signal_print[TARGET_SIGNAL_CANCEL] = 0; | |
4577 | ||
85c07804 AC |
4578 | add_setshow_zinteger_cmd ("stop-on-solib-events", class_support, |
4579 | &stop_on_solib_events, _("\ | |
4580 | Set stopping for shared library events."), _("\ | |
4581 | Show stopping for shared library events."), _("\ | |
c906108c SS |
4582 | If nonzero, gdb will give control to the user when the dynamic linker\n\ |
4583 | notifies gdb of shared library events. The most common event of interest\n\ | |
85c07804 AC |
4584 | to the user would be loading/unloading of a new library."), |
4585 | NULL, | |
920d2a44 | 4586 | show_stop_on_solib_events, |
85c07804 | 4587 | &setlist, &showlist); |
c906108c | 4588 | |
7ab04401 AC |
4589 | add_setshow_enum_cmd ("follow-fork-mode", class_run, |
4590 | follow_fork_mode_kind_names, | |
4591 | &follow_fork_mode_string, _("\ | |
4592 | Set debugger response to a program call of fork or vfork."), _("\ | |
4593 | Show debugger response to a program call of fork or vfork."), _("\ | |
c906108c SS |
4594 | A fork or vfork creates a new process. follow-fork-mode can be:\n\ |
4595 | parent - the original process is debugged after a fork\n\ | |
4596 | child - the new process is debugged after a fork\n\ | |
ea1dd7bc | 4597 | The unfollowed process will continue to run.\n\ |
7ab04401 AC |
4598 | By default, the debugger will follow the parent process."), |
4599 | NULL, | |
920d2a44 | 4600 | show_follow_fork_mode_string, |
7ab04401 AC |
4601 | &setlist, &showlist); |
4602 | ||
4603 | add_setshow_enum_cmd ("scheduler-locking", class_run, | |
4604 | scheduler_enums, &scheduler_mode, _("\ | |
4605 | Set mode for locking scheduler during execution."), _("\ | |
4606 | Show mode for locking scheduler during execution."), _("\ | |
c906108c SS |
4607 | off == no locking (threads may preempt at any time)\n\ |
4608 | on == full locking (no thread except the current thread may run)\n\ | |
4609 | step == scheduler locked during every single-step operation.\n\ | |
4610 | In this mode, no other thread may run during a step command.\n\ | |
7ab04401 AC |
4611 | Other threads may run while stepping over a function call ('next')."), |
4612 | set_schedlock_func, /* traps on target vector */ | |
920d2a44 | 4613 | show_scheduler_mode, |
7ab04401 | 4614 | &setlist, &showlist); |
5fbbeb29 | 4615 | |
5bf193a2 AC |
4616 | add_setshow_boolean_cmd ("step-mode", class_run, &step_stop_if_no_debug, _("\ |
4617 | Set mode of the step operation."), _("\ | |
4618 | Show mode of the step operation."), _("\ | |
4619 | When set, doing a step over a function without debug line information\n\ | |
4620 | will stop at the first instruction of that function. Otherwise, the\n\ | |
4621 | function is skipped and the step command stops at a different source line."), | |
4622 | NULL, | |
920d2a44 | 4623 | show_step_stop_if_no_debug, |
5bf193a2 | 4624 | &setlist, &showlist); |
ca6724c1 | 4625 | |
237fc4c9 PA |
4626 | add_setshow_boolean_cmd ("can-use-displaced-stepping", class_maintenance, |
4627 | &can_use_displaced_stepping, _("\ | |
4628 | Set debugger's willingness to use displaced stepping."), _("\ | |
4629 | Show debugger's willingness to use displaced stepping."), _("\ | |
4630 | If zero, gdb will not use to use displaced stepping to step over\n\ | |
4631 | breakpoints, even if such is supported by the target."), | |
4632 | NULL, | |
4633 | show_can_use_displaced_stepping, | |
4634 | &maintenance_set_cmdlist, | |
4635 | &maintenance_show_cmdlist); | |
4636 | ||
4637 | ||
ca6724c1 KB |
4638 | /* ptid initializations */ |
4639 | null_ptid = ptid_build (0, 0, 0); | |
4640 | minus_one_ptid = ptid_build (-1, 0, 0); | |
4641 | inferior_ptid = null_ptid; | |
4642 | target_last_wait_ptid = minus_one_ptid; | |
237fc4c9 | 4643 | displaced_step_ptid = null_ptid; |
c906108c | 4644 | } |