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