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