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