xref: /dflybsd-src/contrib/gdb-7/gdb/infrun.c (revision de8e141f24382815c10a4012d209bbbf7abf1112)
15796c8dcSSimon Schubert /* Target-struct-independent code to start (run) and stop an inferior
25796c8dcSSimon Schubert    process.
35796c8dcSSimon Schubert 
4*ef5ccd6cSJohn Marino    Copyright (C) 1986-2013 Free Software Foundation, Inc.
55796c8dcSSimon Schubert 
65796c8dcSSimon Schubert    This file is part of GDB.
75796c8dcSSimon Schubert 
85796c8dcSSimon Schubert    This program is free software; you can redistribute it and/or modify
95796c8dcSSimon Schubert    it under the terms of the GNU General Public License as published by
105796c8dcSSimon Schubert    the Free Software Foundation; either version 3 of the License, or
115796c8dcSSimon Schubert    (at your option) any later version.
125796c8dcSSimon Schubert 
135796c8dcSSimon Schubert    This program is distributed in the hope that it will be useful,
145796c8dcSSimon Schubert    but WITHOUT ANY WARRANTY; without even the implied warranty of
155796c8dcSSimon Schubert    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
165796c8dcSSimon Schubert    GNU General Public License for more details.
175796c8dcSSimon Schubert 
185796c8dcSSimon Schubert    You should have received a copy of the GNU General Public License
195796c8dcSSimon Schubert    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
205796c8dcSSimon Schubert 
215796c8dcSSimon Schubert #include "defs.h"
225796c8dcSSimon Schubert #include "gdb_string.h"
235796c8dcSSimon Schubert #include <ctype.h>
245796c8dcSSimon Schubert #include "symtab.h"
255796c8dcSSimon Schubert #include "frame.h"
265796c8dcSSimon Schubert #include "inferior.h"
275796c8dcSSimon Schubert #include "exceptions.h"
285796c8dcSSimon Schubert #include "breakpoint.h"
295796c8dcSSimon Schubert #include "gdb_wait.h"
305796c8dcSSimon Schubert #include "gdbcore.h"
315796c8dcSSimon Schubert #include "gdbcmd.h"
325796c8dcSSimon Schubert #include "cli/cli-script.h"
335796c8dcSSimon Schubert #include "target.h"
345796c8dcSSimon Schubert #include "gdbthread.h"
355796c8dcSSimon Schubert #include "annotate.h"
365796c8dcSSimon Schubert #include "symfile.h"
375796c8dcSSimon Schubert #include "top.h"
385796c8dcSSimon Schubert #include <signal.h>
395796c8dcSSimon Schubert #include "inf-loop.h"
405796c8dcSSimon Schubert #include "regcache.h"
415796c8dcSSimon Schubert #include "value.h"
425796c8dcSSimon Schubert #include "observer.h"
435796c8dcSSimon Schubert #include "language.h"
445796c8dcSSimon Schubert #include "solib.h"
455796c8dcSSimon Schubert #include "main.h"
46c50c785cSJohn Marino #include "dictionary.h"
47c50c785cSJohn Marino #include "block.h"
485796c8dcSSimon Schubert #include "gdb_assert.h"
495796c8dcSSimon Schubert #include "mi/mi-common.h"
505796c8dcSSimon Schubert #include "event-top.h"
515796c8dcSSimon Schubert #include "record.h"
52*ef5ccd6cSJohn Marino #include "record-full.h"
535796c8dcSSimon Schubert #include "inline-frame.h"
545796c8dcSSimon Schubert #include "jit.h"
55cf7f2e2dSJohn Marino #include "tracepoint.h"
56a45ae5f8SJohn Marino #include "continuations.h"
57a45ae5f8SJohn Marino #include "interps.h"
58a45ae5f8SJohn Marino #include "skip.h"
59*ef5ccd6cSJohn Marino #include "probe.h"
60*ef5ccd6cSJohn Marino #include "objfiles.h"
61*ef5ccd6cSJohn Marino #include "completer.h"
62*ef5ccd6cSJohn Marino #include "target-descriptions.h"
635796c8dcSSimon Schubert 
645796c8dcSSimon Schubert /* Prototypes for local functions */
655796c8dcSSimon Schubert 
665796c8dcSSimon Schubert static void signals_info (char *, int);
675796c8dcSSimon Schubert 
685796c8dcSSimon Schubert static void handle_command (char *, int);
695796c8dcSSimon Schubert 
70*ef5ccd6cSJohn Marino static void sig_print_info (enum gdb_signal);
715796c8dcSSimon Schubert 
725796c8dcSSimon Schubert static void sig_print_header (void);
735796c8dcSSimon Schubert 
745796c8dcSSimon Schubert static void resume_cleanups (void *);
755796c8dcSSimon Schubert 
765796c8dcSSimon Schubert static int hook_stop_stub (void *);
775796c8dcSSimon Schubert 
785796c8dcSSimon Schubert static int restore_selected_frame (void *);
795796c8dcSSimon Schubert 
805796c8dcSSimon Schubert static int follow_fork (void);
815796c8dcSSimon Schubert 
825796c8dcSSimon Schubert static void set_schedlock_func (char *args, int from_tty,
835796c8dcSSimon Schubert 				struct cmd_list_element *c);
845796c8dcSSimon Schubert 
855796c8dcSSimon Schubert static int currently_stepping (struct thread_info *tp);
865796c8dcSSimon Schubert 
875796c8dcSSimon Schubert static int currently_stepping_or_nexting_callback (struct thread_info *tp,
885796c8dcSSimon Schubert 						   void *data);
895796c8dcSSimon Schubert 
905796c8dcSSimon Schubert static void xdb_handle_command (char *args, int from_tty);
915796c8dcSSimon Schubert 
925796c8dcSSimon Schubert static int prepare_to_proceed (int);
935796c8dcSSimon Schubert 
94c50c785cSJohn Marino static void print_exited_reason (int exitstatus);
95c50c785cSJohn Marino 
96*ef5ccd6cSJohn Marino static void print_signal_exited_reason (enum gdb_signal siggnal);
97c50c785cSJohn Marino 
98c50c785cSJohn Marino static void print_no_history_reason (void);
99c50c785cSJohn Marino 
100*ef5ccd6cSJohn Marino static void print_signal_received_reason (enum gdb_signal siggnal);
101c50c785cSJohn Marino 
102c50c785cSJohn Marino static void print_end_stepping_range_reason (void);
103c50c785cSJohn Marino 
1045796c8dcSSimon Schubert void _initialize_infrun (void);
1055796c8dcSSimon Schubert 
1065796c8dcSSimon Schubert void nullify_last_target_wait_ptid (void);
1075796c8dcSSimon Schubert 
108a45ae5f8SJohn Marino static void insert_hp_step_resume_breakpoint_at_frame (struct frame_info *);
109a45ae5f8SJohn Marino 
110a45ae5f8SJohn Marino static void insert_step_resume_breakpoint_at_caller (struct frame_info *);
111a45ae5f8SJohn Marino 
112a45ae5f8SJohn Marino static void insert_longjmp_resume_breakpoint (struct gdbarch *, CORE_ADDR);
113a45ae5f8SJohn Marino 
1145796c8dcSSimon Schubert /* When set, stop the 'step' command if we enter a function which has
1155796c8dcSSimon Schubert    no line number information.  The normal behavior is that we step
1165796c8dcSSimon Schubert    over such function.  */
1175796c8dcSSimon Schubert int step_stop_if_no_debug = 0;
1185796c8dcSSimon Schubert static void
show_step_stop_if_no_debug(struct ui_file * file,int from_tty,struct cmd_list_element * c,const char * value)1195796c8dcSSimon Schubert show_step_stop_if_no_debug (struct ui_file *file, int from_tty,
1205796c8dcSSimon Schubert 			    struct cmd_list_element *c, const char *value)
1215796c8dcSSimon Schubert {
1225796c8dcSSimon Schubert   fprintf_filtered (file, _("Mode of the step operation is %s.\n"), value);
1235796c8dcSSimon Schubert }
1245796c8dcSSimon Schubert 
1255796c8dcSSimon Schubert /* In asynchronous mode, but simulating synchronous execution.  */
1265796c8dcSSimon Schubert 
1275796c8dcSSimon Schubert int sync_execution = 0;
1285796c8dcSSimon Schubert 
1295796c8dcSSimon Schubert /* wait_for_inferior and normal_stop use this to notify the user
1305796c8dcSSimon Schubert    when the inferior stopped in a different thread than it had been
1315796c8dcSSimon Schubert    running in.  */
1325796c8dcSSimon Schubert 
1335796c8dcSSimon Schubert static ptid_t previous_inferior_ptid;
1345796c8dcSSimon Schubert 
135cf7f2e2dSJohn Marino /* Default behavior is to detach newly forked processes (legacy).  */
136cf7f2e2dSJohn Marino int detach_fork = 1;
137cf7f2e2dSJohn Marino 
1385796c8dcSSimon Schubert int debug_displaced = 0;
1395796c8dcSSimon Schubert static void
show_debug_displaced(struct ui_file * file,int from_tty,struct cmd_list_element * c,const char * value)1405796c8dcSSimon Schubert show_debug_displaced (struct ui_file *file, int from_tty,
1415796c8dcSSimon Schubert 		      struct cmd_list_element *c, const char *value)
1425796c8dcSSimon Schubert {
1435796c8dcSSimon Schubert   fprintf_filtered (file, _("Displace stepping debugging is %s.\n"), value);
1445796c8dcSSimon Schubert }
1455796c8dcSSimon Schubert 
146*ef5ccd6cSJohn Marino unsigned int debug_infrun = 0;
1475796c8dcSSimon Schubert static void
show_debug_infrun(struct ui_file * file,int from_tty,struct cmd_list_element * c,const char * value)1485796c8dcSSimon Schubert show_debug_infrun (struct ui_file *file, int from_tty,
1495796c8dcSSimon Schubert 		   struct cmd_list_element *c, const char *value)
1505796c8dcSSimon Schubert {
1515796c8dcSSimon Schubert   fprintf_filtered (file, _("Inferior debugging is %s.\n"), value);
1525796c8dcSSimon Schubert }
1535796c8dcSSimon Schubert 
154a45ae5f8SJohn Marino 
155a45ae5f8SJohn Marino /* Support for disabling address space randomization.  */
156a45ae5f8SJohn Marino 
157a45ae5f8SJohn Marino int disable_randomization = 1;
158a45ae5f8SJohn Marino 
159a45ae5f8SJohn Marino static void
show_disable_randomization(struct ui_file * file,int from_tty,struct cmd_list_element * c,const char * value)160a45ae5f8SJohn Marino show_disable_randomization (struct ui_file *file, int from_tty,
161a45ae5f8SJohn Marino 			    struct cmd_list_element *c, const char *value)
162a45ae5f8SJohn Marino {
163a45ae5f8SJohn Marino   if (target_supports_disable_randomization ())
164a45ae5f8SJohn Marino     fprintf_filtered (file,
165a45ae5f8SJohn Marino 		      _("Disabling randomization of debuggee's "
166a45ae5f8SJohn Marino 			"virtual address space is %s.\n"),
167a45ae5f8SJohn Marino 		      value);
168a45ae5f8SJohn Marino   else
169a45ae5f8SJohn Marino     fputs_filtered (_("Disabling randomization of debuggee's "
170a45ae5f8SJohn Marino 		      "virtual address space is unsupported on\n"
171a45ae5f8SJohn Marino 		      "this platform.\n"), file);
172a45ae5f8SJohn Marino }
173a45ae5f8SJohn Marino 
174a45ae5f8SJohn Marino static void
set_disable_randomization(char * args,int from_tty,struct cmd_list_element * c)175a45ae5f8SJohn Marino set_disable_randomization (char *args, int from_tty,
176a45ae5f8SJohn Marino 			   struct cmd_list_element *c)
177a45ae5f8SJohn Marino {
178a45ae5f8SJohn Marino   if (!target_supports_disable_randomization ())
179a45ae5f8SJohn Marino     error (_("Disabling randomization of debuggee's "
180a45ae5f8SJohn Marino 	     "virtual address space is unsupported on\n"
181a45ae5f8SJohn Marino 	     "this platform."));
182a45ae5f8SJohn Marino }
183a45ae5f8SJohn Marino 
184a45ae5f8SJohn Marino 
1855796c8dcSSimon Schubert /* If the program uses ELF-style shared libraries, then calls to
1865796c8dcSSimon Schubert    functions in shared libraries go through stubs, which live in a
1875796c8dcSSimon Schubert    table called the PLT (Procedure Linkage Table).  The first time the
1885796c8dcSSimon Schubert    function is called, the stub sends control to the dynamic linker,
1895796c8dcSSimon Schubert    which looks up the function's real address, patches the stub so
1905796c8dcSSimon Schubert    that future calls will go directly to the function, and then passes
1915796c8dcSSimon Schubert    control to the function.
1925796c8dcSSimon Schubert 
1935796c8dcSSimon Schubert    If we are stepping at the source level, we don't want to see any of
1945796c8dcSSimon Schubert    this --- we just want to skip over the stub and the dynamic linker.
1955796c8dcSSimon Schubert    The simple approach is to single-step until control leaves the
1965796c8dcSSimon Schubert    dynamic linker.
1975796c8dcSSimon Schubert 
1985796c8dcSSimon Schubert    However, on some systems (e.g., Red Hat's 5.2 distribution) the
1995796c8dcSSimon Schubert    dynamic linker calls functions in the shared C library, so you
2005796c8dcSSimon Schubert    can't tell from the PC alone whether the dynamic linker is still
2015796c8dcSSimon Schubert    running.  In this case, we use a step-resume breakpoint to get us
2025796c8dcSSimon Schubert    past the dynamic linker, as if we were using "next" to step over a
2035796c8dcSSimon Schubert    function call.
2045796c8dcSSimon Schubert 
2055796c8dcSSimon Schubert    in_solib_dynsym_resolve_code() says whether we're in the dynamic
2065796c8dcSSimon Schubert    linker code or not.  Normally, this means we single-step.  However,
2075796c8dcSSimon Schubert    if SKIP_SOLIB_RESOLVER then returns non-zero, then its value is an
2085796c8dcSSimon Schubert    address where we can place a step-resume breakpoint to get past the
2095796c8dcSSimon Schubert    linker's symbol resolution function.
2105796c8dcSSimon Schubert 
2115796c8dcSSimon Schubert    in_solib_dynsym_resolve_code() can generally be implemented in a
2125796c8dcSSimon Schubert    pretty portable way, by comparing the PC against the address ranges
2135796c8dcSSimon Schubert    of the dynamic linker's sections.
2145796c8dcSSimon Schubert 
2155796c8dcSSimon Schubert    SKIP_SOLIB_RESOLVER is generally going to be system-specific, since
2165796c8dcSSimon Schubert    it depends on internal details of the dynamic linker.  It's usually
2175796c8dcSSimon Schubert    not too hard to figure out where to put a breakpoint, but it
2185796c8dcSSimon Schubert    certainly isn't portable.  SKIP_SOLIB_RESOLVER should do plenty of
2195796c8dcSSimon Schubert    sanity checking.  If it can't figure things out, returning zero and
2205796c8dcSSimon Schubert    getting the (possibly confusing) stepping behavior is better than
2215796c8dcSSimon Schubert    signalling an error, which will obscure the change in the
2225796c8dcSSimon Schubert    inferior's state.  */
2235796c8dcSSimon Schubert 
2245796c8dcSSimon Schubert /* This function returns TRUE if pc is the address of an instruction
2255796c8dcSSimon Schubert    that lies within the dynamic linker (such as the event hook, or the
2265796c8dcSSimon Schubert    dld itself).
2275796c8dcSSimon Schubert 
2285796c8dcSSimon Schubert    This function must be used only when a dynamic linker event has
2295796c8dcSSimon Schubert    been caught, and the inferior is being stepped out of the hook, or
2305796c8dcSSimon Schubert    undefined results are guaranteed.  */
2315796c8dcSSimon Schubert 
2325796c8dcSSimon Schubert #ifndef SOLIB_IN_DYNAMIC_LINKER
2335796c8dcSSimon Schubert #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0
2345796c8dcSSimon Schubert #endif
2355796c8dcSSimon Schubert 
236cf7f2e2dSJohn Marino /* "Observer mode" is somewhat like a more extreme version of
237cf7f2e2dSJohn Marino    non-stop, in which all GDB operations that might affect the
238cf7f2e2dSJohn Marino    target's execution have been disabled.  */
2395796c8dcSSimon Schubert 
240cf7f2e2dSJohn Marino static int non_stop_1 = 0;
2415796c8dcSSimon Schubert 
242cf7f2e2dSJohn Marino int observer_mode = 0;
243cf7f2e2dSJohn Marino static int observer_mode_1 = 0;
244cf7f2e2dSJohn Marino 
245cf7f2e2dSJohn Marino static void
set_observer_mode(char * args,int from_tty,struct cmd_list_element * c)246cf7f2e2dSJohn Marino set_observer_mode (char *args, int from_tty,
247cf7f2e2dSJohn Marino 		   struct cmd_list_element *c)
248cf7f2e2dSJohn Marino {
249cf7f2e2dSJohn Marino   extern int pagination_enabled;
250cf7f2e2dSJohn Marino 
251cf7f2e2dSJohn Marino   if (target_has_execution)
252cf7f2e2dSJohn Marino     {
253cf7f2e2dSJohn Marino       observer_mode_1 = observer_mode;
254cf7f2e2dSJohn Marino       error (_("Cannot change this setting while the inferior is running."));
255cf7f2e2dSJohn Marino     }
256cf7f2e2dSJohn Marino 
257cf7f2e2dSJohn Marino   observer_mode = observer_mode_1;
258cf7f2e2dSJohn Marino 
259cf7f2e2dSJohn Marino   may_write_registers = !observer_mode;
260cf7f2e2dSJohn Marino   may_write_memory = !observer_mode;
261cf7f2e2dSJohn Marino   may_insert_breakpoints = !observer_mode;
262cf7f2e2dSJohn Marino   may_insert_tracepoints = !observer_mode;
263cf7f2e2dSJohn Marino   /* We can insert fast tracepoints in or out of observer mode,
264cf7f2e2dSJohn Marino      but enable them if we're going into this mode.  */
265cf7f2e2dSJohn Marino   if (observer_mode)
266cf7f2e2dSJohn Marino     may_insert_fast_tracepoints = 1;
267cf7f2e2dSJohn Marino   may_stop = !observer_mode;
268cf7f2e2dSJohn Marino   update_target_permissions ();
269cf7f2e2dSJohn Marino 
270cf7f2e2dSJohn Marino   /* Going *into* observer mode we must force non-stop, then
271cf7f2e2dSJohn Marino      going out we leave it that way.  */
272cf7f2e2dSJohn Marino   if (observer_mode)
273cf7f2e2dSJohn Marino     {
274cf7f2e2dSJohn Marino       target_async_permitted = 1;
275cf7f2e2dSJohn Marino       pagination_enabled = 0;
276cf7f2e2dSJohn Marino       non_stop = non_stop_1 = 1;
277cf7f2e2dSJohn Marino     }
278cf7f2e2dSJohn Marino 
279cf7f2e2dSJohn Marino   if (from_tty)
280cf7f2e2dSJohn Marino     printf_filtered (_("Observer mode is now %s.\n"),
281cf7f2e2dSJohn Marino 		     (observer_mode ? "on" : "off"));
282cf7f2e2dSJohn Marino }
283cf7f2e2dSJohn Marino 
284cf7f2e2dSJohn Marino static void
show_observer_mode(struct ui_file * file,int from_tty,struct cmd_list_element * c,const char * value)285cf7f2e2dSJohn Marino show_observer_mode (struct ui_file *file, int from_tty,
286cf7f2e2dSJohn Marino 		    struct cmd_list_element *c, const char *value)
287cf7f2e2dSJohn Marino {
288cf7f2e2dSJohn Marino   fprintf_filtered (file, _("Observer mode is %s.\n"), value);
289cf7f2e2dSJohn Marino }
290cf7f2e2dSJohn Marino 
291cf7f2e2dSJohn Marino /* This updates the value of observer mode based on changes in
292cf7f2e2dSJohn Marino    permissions.  Note that we are deliberately ignoring the values of
293cf7f2e2dSJohn Marino    may-write-registers and may-write-memory, since the user may have
294cf7f2e2dSJohn Marino    reason to enable these during a session, for instance to turn on a
295cf7f2e2dSJohn Marino    debugging-related global.  */
296cf7f2e2dSJohn Marino 
297cf7f2e2dSJohn Marino void
update_observer_mode(void)298cf7f2e2dSJohn Marino update_observer_mode (void)
299cf7f2e2dSJohn Marino {
300cf7f2e2dSJohn Marino   int newval;
301cf7f2e2dSJohn Marino 
302cf7f2e2dSJohn Marino   newval = (!may_insert_breakpoints
303cf7f2e2dSJohn Marino 	    && !may_insert_tracepoints
304cf7f2e2dSJohn Marino 	    && may_insert_fast_tracepoints
305cf7f2e2dSJohn Marino 	    && !may_stop
306cf7f2e2dSJohn Marino 	    && non_stop);
307cf7f2e2dSJohn Marino 
308cf7f2e2dSJohn Marino   /* Let the user know if things change.  */
309cf7f2e2dSJohn Marino   if (newval != observer_mode)
310cf7f2e2dSJohn Marino     printf_filtered (_("Observer mode is now %s.\n"),
311cf7f2e2dSJohn Marino 		     (newval ? "on" : "off"));
312cf7f2e2dSJohn Marino 
313cf7f2e2dSJohn Marino   observer_mode = observer_mode_1 = newval;
314cf7f2e2dSJohn Marino }
3155796c8dcSSimon Schubert 
3165796c8dcSSimon Schubert /* Tables of how to react to signals; the user sets them.  */
3175796c8dcSSimon Schubert 
3185796c8dcSSimon Schubert static unsigned char *signal_stop;
3195796c8dcSSimon Schubert static unsigned char *signal_print;
3205796c8dcSSimon Schubert static unsigned char *signal_program;
3215796c8dcSSimon Schubert 
322*ef5ccd6cSJohn Marino /* Table of signals that are registered with "catch signal".  A
323*ef5ccd6cSJohn Marino    non-zero entry indicates that the signal is caught by some "catch
324*ef5ccd6cSJohn Marino    signal" command.  This has size GDB_SIGNAL_LAST, to accommodate all
325*ef5ccd6cSJohn Marino    signals.  */
326*ef5ccd6cSJohn Marino static unsigned char *signal_catch;
327*ef5ccd6cSJohn Marino 
328a45ae5f8SJohn Marino /* Table of signals that the target may silently handle.
329a45ae5f8SJohn Marino    This is automatically determined from the flags above,
330a45ae5f8SJohn Marino    and simply cached here.  */
331a45ae5f8SJohn Marino static unsigned char *signal_pass;
332a45ae5f8SJohn Marino 
3335796c8dcSSimon Schubert #define SET_SIGS(nsigs,sigs,flags) \
3345796c8dcSSimon Schubert   do { \
3355796c8dcSSimon Schubert     int signum = (nsigs); \
3365796c8dcSSimon Schubert     while (signum-- > 0) \
3375796c8dcSSimon Schubert       if ((sigs)[signum]) \
3385796c8dcSSimon Schubert 	(flags)[signum] = 1; \
3395796c8dcSSimon Schubert   } while (0)
3405796c8dcSSimon Schubert 
3415796c8dcSSimon Schubert #define UNSET_SIGS(nsigs,sigs,flags) \
3425796c8dcSSimon Schubert   do { \
3435796c8dcSSimon Schubert     int signum = (nsigs); \
3445796c8dcSSimon Schubert     while (signum-- > 0) \
3455796c8dcSSimon Schubert       if ((sigs)[signum]) \
3465796c8dcSSimon Schubert 	(flags)[signum] = 0; \
3475796c8dcSSimon Schubert   } while (0)
3485796c8dcSSimon Schubert 
349*ef5ccd6cSJohn Marino /* Update the target's copy of SIGNAL_PROGRAM.  The sole purpose of
350*ef5ccd6cSJohn Marino    this function is to avoid exporting `signal_program'.  */
351*ef5ccd6cSJohn Marino 
352*ef5ccd6cSJohn Marino void
update_signals_program_target(void)353*ef5ccd6cSJohn Marino update_signals_program_target (void)
354*ef5ccd6cSJohn Marino {
355*ef5ccd6cSJohn Marino   target_program_signals ((int) GDB_SIGNAL_LAST, signal_program);
356*ef5ccd6cSJohn Marino }
357*ef5ccd6cSJohn Marino 
358c50c785cSJohn Marino /* Value to pass to target_resume() to cause all threads to resume.  */
3595796c8dcSSimon Schubert 
3605796c8dcSSimon Schubert #define RESUME_ALL minus_one_ptid
3615796c8dcSSimon Schubert 
3625796c8dcSSimon Schubert /* Command list pointer for the "stop" placeholder.  */
3635796c8dcSSimon Schubert 
3645796c8dcSSimon Schubert static struct cmd_list_element *stop_command;
3655796c8dcSSimon Schubert 
3665796c8dcSSimon Schubert /* Function inferior was in as of last step command.  */
3675796c8dcSSimon Schubert 
3685796c8dcSSimon Schubert static struct symbol *step_start_function;
3695796c8dcSSimon Schubert 
3705796c8dcSSimon Schubert /* Nonzero if we want to give control to the user when we're notified
3715796c8dcSSimon Schubert    of shared library events by the dynamic linker.  */
372cf7f2e2dSJohn Marino int stop_on_solib_events;
3735796c8dcSSimon Schubert static void
show_stop_on_solib_events(struct ui_file * file,int from_tty,struct cmd_list_element * c,const char * value)3745796c8dcSSimon Schubert show_stop_on_solib_events (struct ui_file *file, int from_tty,
3755796c8dcSSimon Schubert 			   struct cmd_list_element *c, const char *value)
3765796c8dcSSimon Schubert {
3775796c8dcSSimon Schubert   fprintf_filtered (file, _("Stopping for shared library events is %s.\n"),
3785796c8dcSSimon Schubert 		    value);
3795796c8dcSSimon Schubert }
3805796c8dcSSimon Schubert 
3815796c8dcSSimon Schubert /* Nonzero means expecting a trace trap
3825796c8dcSSimon Schubert    and should stop the inferior and return silently when it happens.  */
3835796c8dcSSimon Schubert 
3845796c8dcSSimon Schubert int stop_after_trap;
3855796c8dcSSimon Schubert 
3865796c8dcSSimon Schubert /* Save register contents here when executing a "finish" command or are
3875796c8dcSSimon Schubert    about to pop a stack dummy frame, if-and-only-if proceed_to_finish is set.
3885796c8dcSSimon Schubert    Thus this contains the return value from the called function (assuming
3895796c8dcSSimon Schubert    values are returned in a register).  */
3905796c8dcSSimon Schubert 
3915796c8dcSSimon Schubert struct regcache *stop_registers;
3925796c8dcSSimon Schubert 
3935796c8dcSSimon Schubert /* Nonzero after stop if current stack frame should be printed.  */
3945796c8dcSSimon Schubert 
3955796c8dcSSimon Schubert static int stop_print_frame;
3965796c8dcSSimon Schubert 
3975796c8dcSSimon Schubert /* This is a cached copy of the pid/waitstatus of the last event
3985796c8dcSSimon Schubert    returned by target_wait()/deprecated_target_wait_hook().  This
3995796c8dcSSimon Schubert    information is returned by get_last_target_status().  */
4005796c8dcSSimon Schubert static ptid_t target_last_wait_ptid;
4015796c8dcSSimon Schubert static struct target_waitstatus target_last_waitstatus;
4025796c8dcSSimon Schubert 
4035796c8dcSSimon Schubert static void context_switch (ptid_t ptid);
4045796c8dcSSimon Schubert 
4055796c8dcSSimon Schubert void init_thread_stepping_state (struct thread_info *tss);
4065796c8dcSSimon Schubert 
407*ef5ccd6cSJohn Marino static void init_infwait_state (void);
4085796c8dcSSimon Schubert 
4095796c8dcSSimon Schubert static const char follow_fork_mode_child[] = "child";
4105796c8dcSSimon Schubert static const char follow_fork_mode_parent[] = "parent";
4115796c8dcSSimon Schubert 
412*ef5ccd6cSJohn Marino static const char *const follow_fork_mode_kind_names[] = {
4135796c8dcSSimon Schubert   follow_fork_mode_child,
4145796c8dcSSimon Schubert   follow_fork_mode_parent,
4155796c8dcSSimon Schubert   NULL
4165796c8dcSSimon Schubert };
4175796c8dcSSimon Schubert 
4185796c8dcSSimon Schubert static const char *follow_fork_mode_string = follow_fork_mode_parent;
4195796c8dcSSimon Schubert static void
show_follow_fork_mode_string(struct ui_file * file,int from_tty,struct cmd_list_element * c,const char * value)4205796c8dcSSimon Schubert show_follow_fork_mode_string (struct ui_file *file, int from_tty,
4215796c8dcSSimon Schubert 			      struct cmd_list_element *c, const char *value)
4225796c8dcSSimon Schubert {
423c50c785cSJohn Marino   fprintf_filtered (file,
424c50c785cSJohn Marino 		    _("Debugger response to a program "
425c50c785cSJohn Marino 		      "call of fork or vfork is \"%s\".\n"),
4265796c8dcSSimon Schubert 		    value);
4275796c8dcSSimon Schubert }
4285796c8dcSSimon Schubert 
4295796c8dcSSimon Schubert 
4305796c8dcSSimon Schubert /* Tell the target to follow the fork we're stopped at.  Returns true
4315796c8dcSSimon Schubert    if the inferior should be resumed; false, if the target for some
4325796c8dcSSimon Schubert    reason decided it's best not to resume.  */
4335796c8dcSSimon Schubert 
4345796c8dcSSimon Schubert static int
follow_fork(void)4355796c8dcSSimon Schubert follow_fork (void)
4365796c8dcSSimon Schubert {
4375796c8dcSSimon Schubert   int follow_child = (follow_fork_mode_string == follow_fork_mode_child);
4385796c8dcSSimon Schubert   int should_resume = 1;
4395796c8dcSSimon Schubert   struct thread_info *tp;
4405796c8dcSSimon Schubert 
4415796c8dcSSimon Schubert   /* Copy user stepping state to the new inferior thread.  FIXME: the
4425796c8dcSSimon Schubert      followed fork child thread should have a copy of most of the
4435796c8dcSSimon Schubert      parent thread structure's run control related fields, not just these.
4445796c8dcSSimon Schubert      Initialized to avoid "may be used uninitialized" warnings from gcc.  */
4455796c8dcSSimon Schubert   struct breakpoint *step_resume_breakpoint = NULL;
446c50c785cSJohn Marino   struct breakpoint *exception_resume_breakpoint = NULL;
4475796c8dcSSimon Schubert   CORE_ADDR step_range_start = 0;
4485796c8dcSSimon Schubert   CORE_ADDR step_range_end = 0;
4495796c8dcSSimon Schubert   struct frame_id step_frame_id = { 0 };
4505796c8dcSSimon Schubert 
4515796c8dcSSimon Schubert   if (!non_stop)
4525796c8dcSSimon Schubert     {
4535796c8dcSSimon Schubert       ptid_t wait_ptid;
4545796c8dcSSimon Schubert       struct target_waitstatus wait_status;
4555796c8dcSSimon Schubert 
4565796c8dcSSimon Schubert       /* Get the last target status returned by target_wait().  */
4575796c8dcSSimon Schubert       get_last_target_status (&wait_ptid, &wait_status);
4585796c8dcSSimon Schubert 
4595796c8dcSSimon Schubert       /* If not stopped at a fork event, then there's nothing else to
4605796c8dcSSimon Schubert 	 do.  */
4615796c8dcSSimon Schubert       if (wait_status.kind != TARGET_WAITKIND_FORKED
4625796c8dcSSimon Schubert 	  && wait_status.kind != TARGET_WAITKIND_VFORKED)
4635796c8dcSSimon Schubert 	return 1;
4645796c8dcSSimon Schubert 
4655796c8dcSSimon Schubert       /* Check if we switched over from WAIT_PTID, since the event was
4665796c8dcSSimon Schubert 	 reported.  */
4675796c8dcSSimon Schubert       if (!ptid_equal (wait_ptid, minus_one_ptid)
4685796c8dcSSimon Schubert 	  && !ptid_equal (inferior_ptid, wait_ptid))
4695796c8dcSSimon Schubert 	{
4705796c8dcSSimon Schubert 	  /* We did.  Switch back to WAIT_PTID thread, to tell the
4715796c8dcSSimon Schubert 	     target to follow it (in either direction).  We'll
4725796c8dcSSimon Schubert 	     afterwards refuse to resume, and inform the user what
4735796c8dcSSimon Schubert 	     happened.  */
4745796c8dcSSimon Schubert 	  switch_to_thread (wait_ptid);
4755796c8dcSSimon Schubert 	  should_resume = 0;
4765796c8dcSSimon Schubert 	}
4775796c8dcSSimon Schubert     }
4785796c8dcSSimon Schubert 
4795796c8dcSSimon Schubert   tp = inferior_thread ();
4805796c8dcSSimon Schubert 
4815796c8dcSSimon Schubert   /* If there were any forks/vforks that were caught and are now to be
4825796c8dcSSimon Schubert      followed, then do so now.  */
4835796c8dcSSimon Schubert   switch (tp->pending_follow.kind)
4845796c8dcSSimon Schubert     {
4855796c8dcSSimon Schubert     case TARGET_WAITKIND_FORKED:
4865796c8dcSSimon Schubert     case TARGET_WAITKIND_VFORKED:
4875796c8dcSSimon Schubert       {
4885796c8dcSSimon Schubert 	ptid_t parent, child;
4895796c8dcSSimon Schubert 
4905796c8dcSSimon Schubert 	/* If the user did a next/step, etc, over a fork call,
4915796c8dcSSimon Schubert 	   preserve the stepping state in the fork child.  */
4925796c8dcSSimon Schubert 	if (follow_child && should_resume)
4935796c8dcSSimon Schubert 	  {
494c50c785cSJohn Marino 	    step_resume_breakpoint = clone_momentary_breakpoint
495c50c785cSJohn Marino 					 (tp->control.step_resume_breakpoint);
496c50c785cSJohn Marino 	    step_range_start = tp->control.step_range_start;
497c50c785cSJohn Marino 	    step_range_end = tp->control.step_range_end;
498c50c785cSJohn Marino 	    step_frame_id = tp->control.step_frame_id;
499c50c785cSJohn Marino 	    exception_resume_breakpoint
500c50c785cSJohn Marino 	      = clone_momentary_breakpoint (tp->control.exception_resume_breakpoint);
5015796c8dcSSimon Schubert 
5025796c8dcSSimon Schubert 	    /* For now, delete the parent's sr breakpoint, otherwise,
5035796c8dcSSimon Schubert 	       parent/child sr breakpoints are considered duplicates,
5045796c8dcSSimon Schubert 	       and the child version will not be installed.  Remove
5055796c8dcSSimon Schubert 	       this when the breakpoints module becomes aware of
5065796c8dcSSimon Schubert 	       inferiors and address spaces.  */
5075796c8dcSSimon Schubert 	    delete_step_resume_breakpoint (tp);
508c50c785cSJohn Marino 	    tp->control.step_range_start = 0;
509c50c785cSJohn Marino 	    tp->control.step_range_end = 0;
510c50c785cSJohn Marino 	    tp->control.step_frame_id = null_frame_id;
511c50c785cSJohn Marino 	    delete_exception_resume_breakpoint (tp);
5125796c8dcSSimon Schubert 	  }
5135796c8dcSSimon Schubert 
5145796c8dcSSimon Schubert 	parent = inferior_ptid;
5155796c8dcSSimon Schubert 	child = tp->pending_follow.value.related_pid;
5165796c8dcSSimon Schubert 
5175796c8dcSSimon Schubert 	/* Tell the target to do whatever is necessary to follow
5185796c8dcSSimon Schubert 	   either parent or child.  */
5195796c8dcSSimon Schubert 	if (target_follow_fork (follow_child))
5205796c8dcSSimon Schubert 	  {
5215796c8dcSSimon Schubert 	    /* Target refused to follow, or there's some other reason
5225796c8dcSSimon Schubert 	       we shouldn't resume.  */
5235796c8dcSSimon Schubert 	    should_resume = 0;
5245796c8dcSSimon Schubert 	  }
5255796c8dcSSimon Schubert 	else
5265796c8dcSSimon Schubert 	  {
5275796c8dcSSimon Schubert 	    /* This pending follow fork event is now handled, one way
5285796c8dcSSimon Schubert 	       or another.  The previous selected thread may be gone
5295796c8dcSSimon Schubert 	       from the lists by now, but if it is still around, need
5305796c8dcSSimon Schubert 	       to clear the pending follow request.  */
5315796c8dcSSimon Schubert 	    tp = find_thread_ptid (parent);
5325796c8dcSSimon Schubert 	    if (tp)
5335796c8dcSSimon Schubert 	      tp->pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
5345796c8dcSSimon Schubert 
5355796c8dcSSimon Schubert 	    /* This makes sure we don't try to apply the "Switched
5365796c8dcSSimon Schubert 	       over from WAIT_PID" logic above.  */
5375796c8dcSSimon Schubert 	    nullify_last_target_wait_ptid ();
5385796c8dcSSimon Schubert 
5395796c8dcSSimon Schubert 	    /* If we followed the child, switch to it...  */
5405796c8dcSSimon Schubert 	    if (follow_child)
5415796c8dcSSimon Schubert 	      {
5425796c8dcSSimon Schubert 		switch_to_thread (child);
5435796c8dcSSimon Schubert 
5445796c8dcSSimon Schubert 		/* ... and preserve the stepping state, in case the
5455796c8dcSSimon Schubert 		   user was stepping over the fork call.  */
5465796c8dcSSimon Schubert 		if (should_resume)
5475796c8dcSSimon Schubert 		  {
5485796c8dcSSimon Schubert 		    tp = inferior_thread ();
549c50c785cSJohn Marino 		    tp->control.step_resume_breakpoint
550c50c785cSJohn Marino 		      = step_resume_breakpoint;
551c50c785cSJohn Marino 		    tp->control.step_range_start = step_range_start;
552c50c785cSJohn Marino 		    tp->control.step_range_end = step_range_end;
553c50c785cSJohn Marino 		    tp->control.step_frame_id = step_frame_id;
554c50c785cSJohn Marino 		    tp->control.exception_resume_breakpoint
555c50c785cSJohn Marino 		      = exception_resume_breakpoint;
5565796c8dcSSimon Schubert 		  }
5575796c8dcSSimon Schubert 		else
5585796c8dcSSimon Schubert 		  {
5595796c8dcSSimon Schubert 		    /* If we get here, it was because we're trying to
5605796c8dcSSimon Schubert 		       resume from a fork catchpoint, but, the user
5615796c8dcSSimon Schubert 		       has switched threads away from the thread that
5625796c8dcSSimon Schubert 		       forked.  In that case, the resume command
5635796c8dcSSimon Schubert 		       issued is most likely not applicable to the
5645796c8dcSSimon Schubert 		       child, so just warn, and refuse to resume.  */
565c50c785cSJohn Marino 		    warning (_("Not resuming: switched threads "
566c50c785cSJohn Marino 			       "before following fork child.\n"));
5675796c8dcSSimon Schubert 		  }
5685796c8dcSSimon Schubert 
5695796c8dcSSimon Schubert 		/* Reset breakpoints in the child as appropriate.  */
5705796c8dcSSimon Schubert 		follow_inferior_reset_breakpoints ();
5715796c8dcSSimon Schubert 	      }
5725796c8dcSSimon Schubert 	    else
5735796c8dcSSimon Schubert 	      switch_to_thread (parent);
5745796c8dcSSimon Schubert 	  }
5755796c8dcSSimon Schubert       }
5765796c8dcSSimon Schubert       break;
5775796c8dcSSimon Schubert     case TARGET_WAITKIND_SPURIOUS:
5785796c8dcSSimon Schubert       /* Nothing to follow.  */
5795796c8dcSSimon Schubert       break;
5805796c8dcSSimon Schubert     default:
5815796c8dcSSimon Schubert       internal_error (__FILE__, __LINE__,
5825796c8dcSSimon Schubert 		      "Unexpected pending_follow.kind %d\n",
5835796c8dcSSimon Schubert 		      tp->pending_follow.kind);
5845796c8dcSSimon Schubert       break;
5855796c8dcSSimon Schubert     }
5865796c8dcSSimon Schubert 
5875796c8dcSSimon Schubert   return should_resume;
5885796c8dcSSimon Schubert }
5895796c8dcSSimon Schubert 
5905796c8dcSSimon Schubert void
follow_inferior_reset_breakpoints(void)5915796c8dcSSimon Schubert follow_inferior_reset_breakpoints (void)
5925796c8dcSSimon Schubert {
5935796c8dcSSimon Schubert   struct thread_info *tp = inferior_thread ();
5945796c8dcSSimon Schubert 
5955796c8dcSSimon Schubert   /* Was there a step_resume breakpoint?  (There was if the user
5965796c8dcSSimon Schubert      did a "next" at the fork() call.)  If so, explicitly reset its
5975796c8dcSSimon Schubert      thread number.
5985796c8dcSSimon Schubert 
5995796c8dcSSimon Schubert      step_resumes are a form of bp that are made to be per-thread.
6005796c8dcSSimon Schubert      Since we created the step_resume bp when the parent process
6015796c8dcSSimon Schubert      was being debugged, and now are switching to the child process,
6025796c8dcSSimon Schubert      from the breakpoint package's viewpoint, that's a switch of
6035796c8dcSSimon Schubert      "threads".  We must update the bp's notion of which thread
6045796c8dcSSimon Schubert      it is for, or it'll be ignored when it triggers.  */
6055796c8dcSSimon Schubert 
606c50c785cSJohn Marino   if (tp->control.step_resume_breakpoint)
607c50c785cSJohn Marino     breakpoint_re_set_thread (tp->control.step_resume_breakpoint);
608c50c785cSJohn Marino 
609c50c785cSJohn Marino   if (tp->control.exception_resume_breakpoint)
610c50c785cSJohn Marino     breakpoint_re_set_thread (tp->control.exception_resume_breakpoint);
6115796c8dcSSimon Schubert 
6125796c8dcSSimon Schubert   /* Reinsert all breakpoints in the child.  The user may have set
6135796c8dcSSimon Schubert      breakpoints after catching the fork, in which case those
6145796c8dcSSimon Schubert      were never set in the child, but only in the parent.  This makes
6155796c8dcSSimon Schubert      sure the inserted breakpoints match the breakpoint list.  */
6165796c8dcSSimon Schubert 
6175796c8dcSSimon Schubert   breakpoint_re_set ();
6185796c8dcSSimon Schubert   insert_breakpoints ();
6195796c8dcSSimon Schubert }
6205796c8dcSSimon Schubert 
621cf7f2e2dSJohn Marino /* The child has exited or execed: resume threads of the parent the
622cf7f2e2dSJohn Marino    user wanted to be executing.  */
623cf7f2e2dSJohn Marino 
624cf7f2e2dSJohn Marino static int
proceed_after_vfork_done(struct thread_info * thread,void * arg)625cf7f2e2dSJohn Marino proceed_after_vfork_done (struct thread_info *thread,
626cf7f2e2dSJohn Marino 			  void *arg)
627cf7f2e2dSJohn Marino {
628cf7f2e2dSJohn Marino   int pid = * (int *) arg;
629cf7f2e2dSJohn Marino 
630cf7f2e2dSJohn Marino   if (ptid_get_pid (thread->ptid) == pid
631cf7f2e2dSJohn Marino       && is_running (thread->ptid)
632cf7f2e2dSJohn Marino       && !is_executing (thread->ptid)
633cf7f2e2dSJohn Marino       && !thread->stop_requested
634*ef5ccd6cSJohn Marino       && thread->suspend.stop_signal == GDB_SIGNAL_0)
635cf7f2e2dSJohn Marino     {
636cf7f2e2dSJohn Marino       if (debug_infrun)
637cf7f2e2dSJohn Marino 	fprintf_unfiltered (gdb_stdlog,
638cf7f2e2dSJohn Marino 			    "infrun: resuming vfork parent thread %s\n",
639cf7f2e2dSJohn Marino 			    target_pid_to_str (thread->ptid));
640cf7f2e2dSJohn Marino 
641cf7f2e2dSJohn Marino       switch_to_thread (thread->ptid);
642cf7f2e2dSJohn Marino       clear_proceed_status ();
643*ef5ccd6cSJohn Marino       proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT, 0);
644cf7f2e2dSJohn Marino     }
645cf7f2e2dSJohn Marino 
646cf7f2e2dSJohn Marino   return 0;
647cf7f2e2dSJohn Marino }
648cf7f2e2dSJohn Marino 
649cf7f2e2dSJohn Marino /* Called whenever we notice an exec or exit event, to handle
650cf7f2e2dSJohn Marino    detaching or resuming a vfork parent.  */
651cf7f2e2dSJohn Marino 
652cf7f2e2dSJohn Marino static void
handle_vfork_child_exec_or_exit(int exec)653cf7f2e2dSJohn Marino handle_vfork_child_exec_or_exit (int exec)
654cf7f2e2dSJohn Marino {
655cf7f2e2dSJohn Marino   struct inferior *inf = current_inferior ();
656cf7f2e2dSJohn Marino 
657cf7f2e2dSJohn Marino   if (inf->vfork_parent)
658cf7f2e2dSJohn Marino     {
659cf7f2e2dSJohn Marino       int resume_parent = -1;
660cf7f2e2dSJohn Marino 
661cf7f2e2dSJohn Marino       /* This exec or exit marks the end of the shared memory region
662cf7f2e2dSJohn Marino 	 between the parent and the child.  If the user wanted to
663cf7f2e2dSJohn Marino 	 detach from the parent, now is the time.  */
664cf7f2e2dSJohn Marino 
665cf7f2e2dSJohn Marino       if (inf->vfork_parent->pending_detach)
666cf7f2e2dSJohn Marino 	{
667cf7f2e2dSJohn Marino 	  struct thread_info *tp;
668cf7f2e2dSJohn Marino 	  struct cleanup *old_chain;
669cf7f2e2dSJohn Marino 	  struct program_space *pspace;
670cf7f2e2dSJohn Marino 	  struct address_space *aspace;
671cf7f2e2dSJohn Marino 
672c50c785cSJohn Marino 	  /* follow-fork child, detach-on-fork on.  */
673cf7f2e2dSJohn Marino 
674*ef5ccd6cSJohn Marino 	  inf->vfork_parent->pending_detach = 0;
675*ef5ccd6cSJohn Marino 
676*ef5ccd6cSJohn Marino 	  if (!exec)
677*ef5ccd6cSJohn Marino 	    {
678*ef5ccd6cSJohn Marino 	      /* If we're handling a child exit, then inferior_ptid
679*ef5ccd6cSJohn Marino 		 points at the inferior's pid, not to a thread.  */
680*ef5ccd6cSJohn Marino 	      old_chain = save_inferior_ptid ();
681*ef5ccd6cSJohn Marino 	      save_current_program_space ();
682*ef5ccd6cSJohn Marino 	      save_current_inferior ();
683*ef5ccd6cSJohn Marino 	    }
684*ef5ccd6cSJohn Marino 	  else
685*ef5ccd6cSJohn Marino 	    old_chain = save_current_space_and_thread ();
686cf7f2e2dSJohn Marino 
687cf7f2e2dSJohn Marino 	  /* We're letting loose of the parent.  */
688cf7f2e2dSJohn Marino 	  tp = any_live_thread_of_process (inf->vfork_parent->pid);
689cf7f2e2dSJohn Marino 	  switch_to_thread (tp->ptid);
690cf7f2e2dSJohn Marino 
691cf7f2e2dSJohn Marino 	  /* We're about to detach from the parent, which implicitly
692cf7f2e2dSJohn Marino 	     removes breakpoints from its address space.  There's a
693cf7f2e2dSJohn Marino 	     catch here: we want to reuse the spaces for the child,
694cf7f2e2dSJohn Marino 	     but, parent/child are still sharing the pspace at this
695cf7f2e2dSJohn Marino 	     point, although the exec in reality makes the kernel give
696cf7f2e2dSJohn Marino 	     the child a fresh set of new pages.  The problem here is
697cf7f2e2dSJohn Marino 	     that the breakpoints module being unaware of this, would
698cf7f2e2dSJohn Marino 	     likely chose the child process to write to the parent
699cf7f2e2dSJohn Marino 	     address space.  Swapping the child temporarily away from
700cf7f2e2dSJohn Marino 	     the spaces has the desired effect.  Yes, this is "sort
701cf7f2e2dSJohn Marino 	     of" a hack.  */
702cf7f2e2dSJohn Marino 
703cf7f2e2dSJohn Marino 	  pspace = inf->pspace;
704cf7f2e2dSJohn Marino 	  aspace = inf->aspace;
705cf7f2e2dSJohn Marino 	  inf->aspace = NULL;
706cf7f2e2dSJohn Marino 	  inf->pspace = NULL;
707cf7f2e2dSJohn Marino 
708cf7f2e2dSJohn Marino 	  if (debug_infrun || info_verbose)
709cf7f2e2dSJohn Marino 	    {
710cf7f2e2dSJohn Marino 	      target_terminal_ours ();
711cf7f2e2dSJohn Marino 
712cf7f2e2dSJohn Marino 	      if (exec)
713cf7f2e2dSJohn Marino 		fprintf_filtered (gdb_stdlog,
714c50c785cSJohn Marino 				  "Detaching vfork parent process "
715c50c785cSJohn Marino 				  "%d after child exec.\n",
716cf7f2e2dSJohn Marino 				  inf->vfork_parent->pid);
717cf7f2e2dSJohn Marino 	      else
718cf7f2e2dSJohn Marino 		fprintf_filtered (gdb_stdlog,
719c50c785cSJohn Marino 				  "Detaching vfork parent process "
720c50c785cSJohn Marino 				  "%d after child exit.\n",
721cf7f2e2dSJohn Marino 				  inf->vfork_parent->pid);
722cf7f2e2dSJohn Marino 	    }
723cf7f2e2dSJohn Marino 
724cf7f2e2dSJohn Marino 	  target_detach (NULL, 0);
725cf7f2e2dSJohn Marino 
726cf7f2e2dSJohn Marino 	  /* Put it back.  */
727cf7f2e2dSJohn Marino 	  inf->pspace = pspace;
728cf7f2e2dSJohn Marino 	  inf->aspace = aspace;
729cf7f2e2dSJohn Marino 
730cf7f2e2dSJohn Marino 	  do_cleanups (old_chain);
731cf7f2e2dSJohn Marino 	}
732cf7f2e2dSJohn Marino       else if (exec)
733cf7f2e2dSJohn Marino 	{
734cf7f2e2dSJohn Marino 	  /* We're staying attached to the parent, so, really give the
735cf7f2e2dSJohn Marino 	     child a new address space.  */
736cf7f2e2dSJohn Marino 	  inf->pspace = add_program_space (maybe_new_address_space ());
737cf7f2e2dSJohn Marino 	  inf->aspace = inf->pspace->aspace;
738cf7f2e2dSJohn Marino 	  inf->removable = 1;
739cf7f2e2dSJohn Marino 	  set_current_program_space (inf->pspace);
740cf7f2e2dSJohn Marino 
741cf7f2e2dSJohn Marino 	  resume_parent = inf->vfork_parent->pid;
742cf7f2e2dSJohn Marino 
743cf7f2e2dSJohn Marino 	  /* Break the bonds.  */
744cf7f2e2dSJohn Marino 	  inf->vfork_parent->vfork_child = NULL;
745cf7f2e2dSJohn Marino 	}
746cf7f2e2dSJohn Marino       else
747cf7f2e2dSJohn Marino 	{
748cf7f2e2dSJohn Marino 	  struct cleanup *old_chain;
749cf7f2e2dSJohn Marino 	  struct program_space *pspace;
750cf7f2e2dSJohn Marino 
751cf7f2e2dSJohn Marino 	  /* If this is a vfork child exiting, then the pspace and
752cf7f2e2dSJohn Marino 	     aspaces were shared with the parent.  Since we're
753cf7f2e2dSJohn Marino 	     reporting the process exit, we'll be mourning all that is
754cf7f2e2dSJohn Marino 	     found in the address space, and switching to null_ptid,
755cf7f2e2dSJohn Marino 	     preparing to start a new inferior.  But, since we don't
756cf7f2e2dSJohn Marino 	     want to clobber the parent's address/program spaces, we
757cf7f2e2dSJohn Marino 	     go ahead and create a new one for this exiting
758cf7f2e2dSJohn Marino 	     inferior.  */
759cf7f2e2dSJohn Marino 
760cf7f2e2dSJohn Marino 	  /* Switch to null_ptid, so that clone_program_space doesn't want
761cf7f2e2dSJohn Marino 	     to read the selected frame of a dead process.  */
762cf7f2e2dSJohn Marino 	  old_chain = save_inferior_ptid ();
763cf7f2e2dSJohn Marino 	  inferior_ptid = null_ptid;
764cf7f2e2dSJohn Marino 
765cf7f2e2dSJohn Marino 	  /* This inferior is dead, so avoid giving the breakpoints
766cf7f2e2dSJohn Marino 	     module the option to write through to it (cloning a
767cf7f2e2dSJohn Marino 	     program space resets breakpoints).  */
768cf7f2e2dSJohn Marino 	  inf->aspace = NULL;
769cf7f2e2dSJohn Marino 	  inf->pspace = NULL;
770cf7f2e2dSJohn Marino 	  pspace = add_program_space (maybe_new_address_space ());
771cf7f2e2dSJohn Marino 	  set_current_program_space (pspace);
772cf7f2e2dSJohn Marino 	  inf->removable = 1;
773*ef5ccd6cSJohn Marino 	  inf->symfile_flags = SYMFILE_NO_READ;
774cf7f2e2dSJohn Marino 	  clone_program_space (pspace, inf->vfork_parent->pspace);
775cf7f2e2dSJohn Marino 	  inf->pspace = pspace;
776cf7f2e2dSJohn Marino 	  inf->aspace = pspace->aspace;
777cf7f2e2dSJohn Marino 
778cf7f2e2dSJohn Marino 	  /* Put back inferior_ptid.  We'll continue mourning this
779cf7f2e2dSJohn Marino 	     inferior.  */
780cf7f2e2dSJohn Marino 	  do_cleanups (old_chain);
781cf7f2e2dSJohn Marino 
782cf7f2e2dSJohn Marino 	  resume_parent = inf->vfork_parent->pid;
783cf7f2e2dSJohn Marino 	  /* Break the bonds.  */
784cf7f2e2dSJohn Marino 	  inf->vfork_parent->vfork_child = NULL;
785cf7f2e2dSJohn Marino 	}
786cf7f2e2dSJohn Marino 
787cf7f2e2dSJohn Marino       inf->vfork_parent = NULL;
788cf7f2e2dSJohn Marino 
789cf7f2e2dSJohn Marino       gdb_assert (current_program_space == inf->pspace);
790cf7f2e2dSJohn Marino 
791cf7f2e2dSJohn Marino       if (non_stop && resume_parent != -1)
792cf7f2e2dSJohn Marino 	{
793cf7f2e2dSJohn Marino 	  /* If the user wanted the parent to be running, let it go
794cf7f2e2dSJohn Marino 	     free now.  */
795cf7f2e2dSJohn Marino 	  struct cleanup *old_chain = make_cleanup_restore_current_thread ();
796cf7f2e2dSJohn Marino 
797cf7f2e2dSJohn Marino 	  if (debug_infrun)
798c50c785cSJohn Marino 	    fprintf_unfiltered (gdb_stdlog,
799c50c785cSJohn Marino 				"infrun: resuming vfork parent process %d\n",
800cf7f2e2dSJohn Marino 				resume_parent);
801cf7f2e2dSJohn Marino 
802cf7f2e2dSJohn Marino 	  iterate_over_threads (proceed_after_vfork_done, &resume_parent);
803cf7f2e2dSJohn Marino 
804cf7f2e2dSJohn Marino 	  do_cleanups (old_chain);
805cf7f2e2dSJohn Marino 	}
806cf7f2e2dSJohn Marino     }
807cf7f2e2dSJohn Marino }
808cf7f2e2dSJohn Marino 
809cf7f2e2dSJohn Marino /* Enum strings for "set|show displaced-stepping".  */
810cf7f2e2dSJohn Marino 
811cf7f2e2dSJohn Marino static const char follow_exec_mode_new[] = "new";
812cf7f2e2dSJohn Marino static const char follow_exec_mode_same[] = "same";
813*ef5ccd6cSJohn Marino static const char *const follow_exec_mode_names[] =
814cf7f2e2dSJohn Marino {
815cf7f2e2dSJohn Marino   follow_exec_mode_new,
816cf7f2e2dSJohn Marino   follow_exec_mode_same,
817cf7f2e2dSJohn Marino   NULL,
818cf7f2e2dSJohn Marino };
819cf7f2e2dSJohn Marino 
820cf7f2e2dSJohn Marino static const char *follow_exec_mode_string = follow_exec_mode_same;
821cf7f2e2dSJohn Marino static void
show_follow_exec_mode_string(struct ui_file * file,int from_tty,struct cmd_list_element * c,const char * value)822cf7f2e2dSJohn Marino show_follow_exec_mode_string (struct ui_file *file, int from_tty,
823cf7f2e2dSJohn Marino 			      struct cmd_list_element *c, const char *value)
824cf7f2e2dSJohn Marino {
825cf7f2e2dSJohn Marino   fprintf_filtered (file, _("Follow exec mode is \"%s\".\n"),  value);
826cf7f2e2dSJohn Marino }
827cf7f2e2dSJohn Marino 
8285796c8dcSSimon Schubert /* EXECD_PATHNAME is assumed to be non-NULL.  */
8295796c8dcSSimon Schubert 
8305796c8dcSSimon Schubert static void
follow_exec(ptid_t pid,char * execd_pathname)8315796c8dcSSimon Schubert follow_exec (ptid_t pid, char *execd_pathname)
8325796c8dcSSimon Schubert {
8335796c8dcSSimon Schubert   struct thread_info *th = inferior_thread ();
834cf7f2e2dSJohn Marino   struct inferior *inf = current_inferior ();
8355796c8dcSSimon Schubert 
8365796c8dcSSimon Schubert   /* This is an exec event that we actually wish to pay attention to.
8375796c8dcSSimon Schubert      Refresh our symbol table to the newly exec'd program, remove any
8385796c8dcSSimon Schubert      momentary bp's, etc.
8395796c8dcSSimon Schubert 
8405796c8dcSSimon Schubert      If there are breakpoints, they aren't really inserted now,
8415796c8dcSSimon Schubert      since the exec() transformed our inferior into a fresh set
8425796c8dcSSimon Schubert      of instructions.
8435796c8dcSSimon Schubert 
8445796c8dcSSimon Schubert      We want to preserve symbolic breakpoints on the list, since
8455796c8dcSSimon Schubert      we have hopes that they can be reset after the new a.out's
8465796c8dcSSimon Schubert      symbol table is read.
8475796c8dcSSimon Schubert 
8485796c8dcSSimon Schubert      However, any "raw" breakpoints must be removed from the list
8495796c8dcSSimon Schubert      (e.g., the solib bp's), since their address is probably invalid
8505796c8dcSSimon Schubert      now.
8515796c8dcSSimon Schubert 
8525796c8dcSSimon Schubert      And, we DON'T want to call delete_breakpoints() here, since
8535796c8dcSSimon Schubert      that may write the bp's "shadow contents" (the instruction
8545796c8dcSSimon Schubert      value that was overwritten witha TRAP instruction).  Since
8555796c8dcSSimon Schubert      we now have a new a.out, those shadow contents aren't valid.  */
856cf7f2e2dSJohn Marino 
857cf7f2e2dSJohn Marino   mark_breakpoints_out ();
858cf7f2e2dSJohn Marino 
8595796c8dcSSimon Schubert   update_breakpoints_after_exec ();
8605796c8dcSSimon Schubert 
8615796c8dcSSimon Schubert   /* If there was one, it's gone now.  We cannot truly step-to-next
8625796c8dcSSimon Schubert      statement through an exec().  */
863c50c785cSJohn Marino   th->control.step_resume_breakpoint = NULL;
864c50c785cSJohn Marino   th->control.exception_resume_breakpoint = NULL;
865c50c785cSJohn Marino   th->control.step_range_start = 0;
866c50c785cSJohn Marino   th->control.step_range_end = 0;
8675796c8dcSSimon Schubert 
8685796c8dcSSimon Schubert   /* The target reports the exec event to the main thread, even if
8695796c8dcSSimon Schubert      some other thread does the exec, and even if the main thread was
8705796c8dcSSimon Schubert      already stopped --- if debugging in non-stop mode, it's possible
8715796c8dcSSimon Schubert      the user had the main thread held stopped in the previous image
8725796c8dcSSimon Schubert      --- release it now.  This is the same behavior as step-over-exec
8735796c8dcSSimon Schubert      with scheduler-locking on in all-stop mode.  */
8745796c8dcSSimon Schubert   th->stop_requested = 0;
8755796c8dcSSimon Schubert 
8765796c8dcSSimon Schubert   /* What is this a.out's name?  */
877cf7f2e2dSJohn Marino   printf_unfiltered (_("%s is executing new program: %s\n"),
878cf7f2e2dSJohn Marino 		     target_pid_to_str (inferior_ptid),
879cf7f2e2dSJohn Marino 		     execd_pathname);
8805796c8dcSSimon Schubert 
8815796c8dcSSimon Schubert   /* We've followed the inferior through an exec.  Therefore, the
8825796c8dcSSimon Schubert      inferior has essentially been killed & reborn.  */
8835796c8dcSSimon Schubert 
8845796c8dcSSimon Schubert   gdb_flush (gdb_stdout);
8855796c8dcSSimon Schubert 
8865796c8dcSSimon Schubert   breakpoint_init_inferior (inf_execd);
8875796c8dcSSimon Schubert 
8885796c8dcSSimon Schubert   if (gdb_sysroot && *gdb_sysroot)
8895796c8dcSSimon Schubert     {
8905796c8dcSSimon Schubert       char *name = alloca (strlen (gdb_sysroot)
8915796c8dcSSimon Schubert 			    + strlen (execd_pathname)
8925796c8dcSSimon Schubert 			    + 1);
893cf7f2e2dSJohn Marino 
8945796c8dcSSimon Schubert       strcpy (name, gdb_sysroot);
8955796c8dcSSimon Schubert       strcat (name, execd_pathname);
8965796c8dcSSimon Schubert       execd_pathname = name;
8975796c8dcSSimon Schubert     }
8985796c8dcSSimon Schubert 
8995796c8dcSSimon Schubert   /* Reset the shared library package.  This ensures that we get a
9005796c8dcSSimon Schubert      shlib event when the child reaches "_start", at which point the
9015796c8dcSSimon Schubert      dld will have had a chance to initialize the child.  */
9025796c8dcSSimon Schubert   /* Also, loading a symbol file below may trigger symbol lookups, and
9035796c8dcSSimon Schubert      we don't want those to be satisfied by the libraries of the
9045796c8dcSSimon Schubert      previous incarnation of this process.  */
9055796c8dcSSimon Schubert   no_shared_libraries (NULL, 0);
9065796c8dcSSimon Schubert 
907cf7f2e2dSJohn Marino   if (follow_exec_mode_string == follow_exec_mode_new)
908cf7f2e2dSJohn Marino     {
909cf7f2e2dSJohn Marino       struct program_space *pspace;
910cf7f2e2dSJohn Marino 
911cf7f2e2dSJohn Marino       /* The user wants to keep the old inferior and program spaces
912cf7f2e2dSJohn Marino 	 around.  Create a new fresh one, and switch to it.  */
913cf7f2e2dSJohn Marino 
914cf7f2e2dSJohn Marino       inf = add_inferior (current_inferior ()->pid);
915cf7f2e2dSJohn Marino       pspace = add_program_space (maybe_new_address_space ());
916cf7f2e2dSJohn Marino       inf->pspace = pspace;
917cf7f2e2dSJohn Marino       inf->aspace = pspace->aspace;
918cf7f2e2dSJohn Marino 
919cf7f2e2dSJohn Marino       exit_inferior_num_silent (current_inferior ()->num);
920cf7f2e2dSJohn Marino 
921cf7f2e2dSJohn Marino       set_current_inferior (inf);
922cf7f2e2dSJohn Marino       set_current_program_space (pspace);
923cf7f2e2dSJohn Marino     }
924*ef5ccd6cSJohn Marino   else
925*ef5ccd6cSJohn Marino     {
926*ef5ccd6cSJohn Marino       /* The old description may no longer be fit for the new image.
927*ef5ccd6cSJohn Marino 	 E.g, a 64-bit process exec'ed a 32-bit process.  Clear the
928*ef5ccd6cSJohn Marino 	 old description; we'll read a new one below.  No need to do
929*ef5ccd6cSJohn Marino 	 this on "follow-exec-mode new", as the old inferior stays
930*ef5ccd6cSJohn Marino 	 around (its description is later cleared/refetched on
931*ef5ccd6cSJohn Marino 	 restart).  */
932*ef5ccd6cSJohn Marino       target_clear_description ();
933*ef5ccd6cSJohn Marino     }
934cf7f2e2dSJohn Marino 
935cf7f2e2dSJohn Marino   gdb_assert (current_program_space == inf->pspace);
936cf7f2e2dSJohn Marino 
937cf7f2e2dSJohn Marino   /* That a.out is now the one to use.  */
938cf7f2e2dSJohn Marino   exec_file_attach (execd_pathname, 0);
939cf7f2e2dSJohn Marino 
940c50c785cSJohn Marino   /* SYMFILE_DEFER_BP_RESET is used as the proper displacement for PIE
941c50c785cSJohn Marino      (Position Independent Executable) main symbol file will get applied by
942c50c785cSJohn Marino      solib_create_inferior_hook below.  breakpoint_re_set would fail to insert
943c50c785cSJohn Marino      the breakpoints with the zero displacement.  */
944c50c785cSJohn Marino 
945*ef5ccd6cSJohn Marino   symbol_file_add (execd_pathname,
946*ef5ccd6cSJohn Marino 		   (inf->symfile_flags
947*ef5ccd6cSJohn Marino 		    | SYMFILE_MAINLINE | SYMFILE_DEFER_BP_RESET),
948c50c785cSJohn Marino 		   NULL, 0);
949c50c785cSJohn Marino 
950*ef5ccd6cSJohn Marino   if ((inf->symfile_flags & SYMFILE_NO_READ) == 0)
951c50c785cSJohn Marino     set_initial_language ();
9525796c8dcSSimon Schubert 
953*ef5ccd6cSJohn Marino   /* If the target can specify a description, read it.  Must do this
954*ef5ccd6cSJohn Marino      after flipping to the new executable (because the target supplied
955*ef5ccd6cSJohn Marino      description must be compatible with the executable's
956*ef5ccd6cSJohn Marino      architecture, and the old executable may e.g., be 32-bit, while
957*ef5ccd6cSJohn Marino      the new one 64-bit), and before anything involving memory or
958*ef5ccd6cSJohn Marino      registers.  */
959*ef5ccd6cSJohn Marino   target_find_description ();
960*ef5ccd6cSJohn Marino 
9615796c8dcSSimon Schubert #ifdef SOLIB_CREATE_INFERIOR_HOOK
9625796c8dcSSimon Schubert   SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid));
9635796c8dcSSimon Schubert #else
964cf7f2e2dSJohn Marino   solib_create_inferior_hook (0);
9655796c8dcSSimon Schubert #endif
9665796c8dcSSimon Schubert 
9675796c8dcSSimon Schubert   jit_inferior_created_hook ();
9685796c8dcSSimon Schubert 
969c50c785cSJohn Marino   breakpoint_re_set ();
970c50c785cSJohn Marino 
9715796c8dcSSimon Schubert   /* Reinsert all breakpoints.  (Those which were symbolic have
9725796c8dcSSimon Schubert      been reset to the proper address in the new a.out, thanks
973c50c785cSJohn Marino      to symbol_file_command...).  */
9745796c8dcSSimon Schubert   insert_breakpoints ();
9755796c8dcSSimon Schubert 
9765796c8dcSSimon Schubert   /* The next resume of this inferior should bring it to the shlib
9775796c8dcSSimon Schubert      startup breakpoints.  (If the user had also set bp's on
9785796c8dcSSimon Schubert      "main" from the old (parent) process, then they'll auto-
979c50c785cSJohn Marino      matically get reset there in the new process.).  */
9805796c8dcSSimon Schubert }
9815796c8dcSSimon Schubert 
9825796c8dcSSimon Schubert /* Non-zero if we just simulating a single-step.  This is needed
9835796c8dcSSimon Schubert    because we cannot remove the breakpoints in the inferior process
9845796c8dcSSimon Schubert    until after the `wait' in `wait_for_inferior'.  */
9855796c8dcSSimon Schubert static int singlestep_breakpoints_inserted_p = 0;
9865796c8dcSSimon Schubert 
9875796c8dcSSimon Schubert /* The thread we inserted single-step breakpoints for.  */
9885796c8dcSSimon Schubert static ptid_t singlestep_ptid;
9895796c8dcSSimon Schubert 
9905796c8dcSSimon Schubert /* PC when we started this single-step.  */
9915796c8dcSSimon Schubert static CORE_ADDR singlestep_pc;
9925796c8dcSSimon Schubert 
9935796c8dcSSimon Schubert /* If another thread hit the singlestep breakpoint, we save the original
9945796c8dcSSimon Schubert    thread here so that we can resume single-stepping it later.  */
9955796c8dcSSimon Schubert static ptid_t saved_singlestep_ptid;
9965796c8dcSSimon Schubert static int stepping_past_singlestep_breakpoint;
9975796c8dcSSimon Schubert 
9985796c8dcSSimon Schubert /* If not equal to null_ptid, this means that after stepping over breakpoint
9995796c8dcSSimon Schubert    is finished, we need to switch to deferred_step_ptid, and step it.
10005796c8dcSSimon Schubert 
10015796c8dcSSimon Schubert    The use case is when one thread has hit a breakpoint, and then the user
10025796c8dcSSimon Schubert    has switched to another thread and issued 'step'.  We need to step over
10035796c8dcSSimon Schubert    breakpoint in the thread which hit the breakpoint, but then continue
10045796c8dcSSimon Schubert    stepping the thread user has selected.  */
10055796c8dcSSimon Schubert static ptid_t deferred_step_ptid;
10065796c8dcSSimon Schubert 
10075796c8dcSSimon Schubert /* Displaced stepping.  */
10085796c8dcSSimon Schubert 
10095796c8dcSSimon Schubert /* In non-stop debugging mode, we must take special care to manage
10105796c8dcSSimon Schubert    breakpoints properly; in particular, the traditional strategy for
10115796c8dcSSimon Schubert    stepping a thread past a breakpoint it has hit is unsuitable.
10125796c8dcSSimon Schubert    'Displaced stepping' is a tactic for stepping one thread past a
10135796c8dcSSimon Schubert    breakpoint it has hit while ensuring that other threads running
10145796c8dcSSimon Schubert    concurrently will hit the breakpoint as they should.
10155796c8dcSSimon Schubert 
10165796c8dcSSimon Schubert    The traditional way to step a thread T off a breakpoint in a
10175796c8dcSSimon Schubert    multi-threaded program in all-stop mode is as follows:
10185796c8dcSSimon Schubert 
10195796c8dcSSimon Schubert    a0) Initially, all threads are stopped, and breakpoints are not
10205796c8dcSSimon Schubert        inserted.
10215796c8dcSSimon Schubert    a1) We single-step T, leaving breakpoints uninserted.
10225796c8dcSSimon Schubert    a2) We insert breakpoints, and resume all threads.
10235796c8dcSSimon Schubert 
10245796c8dcSSimon Schubert    In non-stop debugging, however, this strategy is unsuitable: we
10255796c8dcSSimon Schubert    don't want to have to stop all threads in the system in order to
10265796c8dcSSimon Schubert    continue or step T past a breakpoint.  Instead, we use displaced
10275796c8dcSSimon Schubert    stepping:
10285796c8dcSSimon Schubert 
10295796c8dcSSimon Schubert    n0) Initially, T is stopped, other threads are running, and
10305796c8dcSSimon Schubert        breakpoints are inserted.
10315796c8dcSSimon Schubert    n1) We copy the instruction "under" the breakpoint to a separate
10325796c8dcSSimon Schubert        location, outside the main code stream, making any adjustments
10335796c8dcSSimon Schubert        to the instruction, register, and memory state as directed by
10345796c8dcSSimon Schubert        T's architecture.
10355796c8dcSSimon Schubert    n2) We single-step T over the instruction at its new location.
10365796c8dcSSimon Schubert    n3) We adjust the resulting register and memory state as directed
10375796c8dcSSimon Schubert        by T's architecture.  This includes resetting T's PC to point
10385796c8dcSSimon Schubert        back into the main instruction stream.
10395796c8dcSSimon Schubert    n4) We resume T.
10405796c8dcSSimon Schubert 
10415796c8dcSSimon Schubert    This approach depends on the following gdbarch methods:
10425796c8dcSSimon Schubert 
10435796c8dcSSimon Schubert    - gdbarch_max_insn_length and gdbarch_displaced_step_location
10445796c8dcSSimon Schubert      indicate where to copy the instruction, and how much space must
10455796c8dcSSimon Schubert      be reserved there.  We use these in step n1.
10465796c8dcSSimon Schubert 
10475796c8dcSSimon Schubert    - gdbarch_displaced_step_copy_insn copies a instruction to a new
10485796c8dcSSimon Schubert      address, and makes any necessary adjustments to the instruction,
10495796c8dcSSimon Schubert      register contents, and memory.  We use this in step n1.
10505796c8dcSSimon Schubert 
10515796c8dcSSimon Schubert    - gdbarch_displaced_step_fixup adjusts registers and memory after
10525796c8dcSSimon Schubert      we have successfuly single-stepped the instruction, to yield the
10535796c8dcSSimon Schubert      same effect the instruction would have had if we had executed it
10545796c8dcSSimon Schubert      at its original address.  We use this in step n3.
10555796c8dcSSimon Schubert 
10565796c8dcSSimon Schubert    - gdbarch_displaced_step_free_closure provides cleanup.
10575796c8dcSSimon Schubert 
10585796c8dcSSimon Schubert    The gdbarch_displaced_step_copy_insn and
10595796c8dcSSimon Schubert    gdbarch_displaced_step_fixup functions must be written so that
10605796c8dcSSimon Schubert    copying an instruction with gdbarch_displaced_step_copy_insn,
10615796c8dcSSimon Schubert    single-stepping across the copied instruction, and then applying
10625796c8dcSSimon Schubert    gdbarch_displaced_insn_fixup should have the same effects on the
10635796c8dcSSimon Schubert    thread's memory and registers as stepping the instruction in place
10645796c8dcSSimon Schubert    would have.  Exactly which responsibilities fall to the copy and
10655796c8dcSSimon Schubert    which fall to the fixup is up to the author of those functions.
10665796c8dcSSimon Schubert 
10675796c8dcSSimon Schubert    See the comments in gdbarch.sh for details.
10685796c8dcSSimon Schubert 
10695796c8dcSSimon Schubert    Note that displaced stepping and software single-step cannot
10705796c8dcSSimon Schubert    currently be used in combination, although with some care I think
10715796c8dcSSimon Schubert    they could be made to.  Software single-step works by placing
10725796c8dcSSimon Schubert    breakpoints on all possible subsequent instructions; if the
10735796c8dcSSimon Schubert    displaced instruction is a PC-relative jump, those breakpoints
10745796c8dcSSimon Schubert    could fall in very strange places --- on pages that aren't
10755796c8dcSSimon Schubert    executable, or at addresses that are not proper instruction
10765796c8dcSSimon Schubert    boundaries.  (We do generally let other threads run while we wait
10775796c8dcSSimon Schubert    to hit the software single-step breakpoint, and they might
10785796c8dcSSimon Schubert    encounter such a corrupted instruction.)  One way to work around
10795796c8dcSSimon Schubert    this would be to have gdbarch_displaced_step_copy_insn fully
10805796c8dcSSimon Schubert    simulate the effect of PC-relative instructions (and return NULL)
10815796c8dcSSimon Schubert    on architectures that use software single-stepping.
10825796c8dcSSimon Schubert 
10835796c8dcSSimon Schubert    In non-stop mode, we can have independent and simultaneous step
10845796c8dcSSimon Schubert    requests, so more than one thread may need to simultaneously step
10855796c8dcSSimon Schubert    over a breakpoint.  The current implementation assumes there is
10865796c8dcSSimon Schubert    only one scratch space per process.  In this case, we have to
10875796c8dcSSimon Schubert    serialize access to the scratch space.  If thread A wants to step
10885796c8dcSSimon Schubert    over a breakpoint, but we are currently waiting for some other
10895796c8dcSSimon Schubert    thread to complete a displaced step, we leave thread A stopped and
10905796c8dcSSimon Schubert    place it in the displaced_step_request_queue.  Whenever a displaced
10915796c8dcSSimon Schubert    step finishes, we pick the next thread in the queue and start a new
10925796c8dcSSimon Schubert    displaced step operation on it.  See displaced_step_prepare and
10935796c8dcSSimon Schubert    displaced_step_fixup for details.  */
10945796c8dcSSimon Schubert 
10955796c8dcSSimon Schubert struct displaced_step_request
10965796c8dcSSimon Schubert {
10975796c8dcSSimon Schubert   ptid_t ptid;
10985796c8dcSSimon Schubert   struct displaced_step_request *next;
10995796c8dcSSimon Schubert };
11005796c8dcSSimon Schubert 
1101cf7f2e2dSJohn Marino /* Per-inferior displaced stepping state.  */
1102cf7f2e2dSJohn Marino struct displaced_step_inferior_state
1103cf7f2e2dSJohn Marino {
1104cf7f2e2dSJohn Marino   /* Pointer to next in linked list.  */
1105cf7f2e2dSJohn Marino   struct displaced_step_inferior_state *next;
1106cf7f2e2dSJohn Marino 
1107cf7f2e2dSJohn Marino   /* The process this displaced step state refers to.  */
1108cf7f2e2dSJohn Marino   int pid;
1109cf7f2e2dSJohn Marino 
1110cf7f2e2dSJohn Marino   /* A queue of pending displaced stepping requests.  One entry per
1111cf7f2e2dSJohn Marino      thread that needs to do a displaced step.  */
1112cf7f2e2dSJohn Marino   struct displaced_step_request *step_request_queue;
1113cf7f2e2dSJohn Marino 
1114cf7f2e2dSJohn Marino   /* If this is not null_ptid, this is the thread carrying out a
1115cf7f2e2dSJohn Marino      displaced single-step in process PID.  This thread's state will
1116cf7f2e2dSJohn Marino      require fixing up once it has completed its step.  */
1117cf7f2e2dSJohn Marino   ptid_t step_ptid;
11185796c8dcSSimon Schubert 
11195796c8dcSSimon Schubert   /* The architecture the thread had when we stepped it.  */
1120cf7f2e2dSJohn Marino   struct gdbarch *step_gdbarch;
11215796c8dcSSimon Schubert 
11225796c8dcSSimon Schubert   /* The closure provided gdbarch_displaced_step_copy_insn, to be used
11235796c8dcSSimon Schubert      for post-step cleanup.  */
1124cf7f2e2dSJohn Marino   struct displaced_step_closure *step_closure;
11255796c8dcSSimon Schubert 
1126cf7f2e2dSJohn Marino   /* The address of the original instruction, and the copy we
1127cf7f2e2dSJohn Marino      made.  */
1128cf7f2e2dSJohn Marino   CORE_ADDR step_original, step_copy;
11295796c8dcSSimon Schubert 
11305796c8dcSSimon Schubert   /* Saved contents of copy area.  */
1131cf7f2e2dSJohn Marino   gdb_byte *step_saved_copy;
1132cf7f2e2dSJohn Marino };
1133cf7f2e2dSJohn Marino 
1134cf7f2e2dSJohn Marino /* The list of states of processes involved in displaced stepping
1135cf7f2e2dSJohn Marino    presently.  */
1136cf7f2e2dSJohn Marino static struct displaced_step_inferior_state *displaced_step_inferior_states;
1137cf7f2e2dSJohn Marino 
1138cf7f2e2dSJohn Marino /* Get the displaced stepping state of process PID.  */
1139cf7f2e2dSJohn Marino 
1140cf7f2e2dSJohn Marino static struct displaced_step_inferior_state *
get_displaced_stepping_state(int pid)1141cf7f2e2dSJohn Marino get_displaced_stepping_state (int pid)
1142cf7f2e2dSJohn Marino {
1143cf7f2e2dSJohn Marino   struct displaced_step_inferior_state *state;
1144cf7f2e2dSJohn Marino 
1145cf7f2e2dSJohn Marino   for (state = displaced_step_inferior_states;
1146cf7f2e2dSJohn Marino        state != NULL;
1147cf7f2e2dSJohn Marino        state = state->next)
1148cf7f2e2dSJohn Marino     if (state->pid == pid)
1149cf7f2e2dSJohn Marino       return state;
1150cf7f2e2dSJohn Marino 
1151cf7f2e2dSJohn Marino   return NULL;
1152cf7f2e2dSJohn Marino }
1153cf7f2e2dSJohn Marino 
1154cf7f2e2dSJohn Marino /* Add a new displaced stepping state for process PID to the displaced
1155cf7f2e2dSJohn Marino    stepping state list, or return a pointer to an already existing
1156cf7f2e2dSJohn Marino    entry, if it already exists.  Never returns NULL.  */
1157cf7f2e2dSJohn Marino 
1158cf7f2e2dSJohn Marino static struct displaced_step_inferior_state *
add_displaced_stepping_state(int pid)1159cf7f2e2dSJohn Marino add_displaced_stepping_state (int pid)
1160cf7f2e2dSJohn Marino {
1161cf7f2e2dSJohn Marino   struct displaced_step_inferior_state *state;
1162cf7f2e2dSJohn Marino 
1163cf7f2e2dSJohn Marino   for (state = displaced_step_inferior_states;
1164cf7f2e2dSJohn Marino        state != NULL;
1165cf7f2e2dSJohn Marino        state = state->next)
1166cf7f2e2dSJohn Marino     if (state->pid == pid)
1167cf7f2e2dSJohn Marino       return state;
1168cf7f2e2dSJohn Marino 
1169cf7f2e2dSJohn Marino   state = xcalloc (1, sizeof (*state));
1170cf7f2e2dSJohn Marino   state->pid = pid;
1171cf7f2e2dSJohn Marino   state->next = displaced_step_inferior_states;
1172cf7f2e2dSJohn Marino   displaced_step_inferior_states = state;
1173cf7f2e2dSJohn Marino 
1174cf7f2e2dSJohn Marino   return state;
1175cf7f2e2dSJohn Marino }
1176cf7f2e2dSJohn Marino 
1177c50c785cSJohn Marino /* If inferior is in displaced stepping, and ADDR equals to starting address
1178c50c785cSJohn Marino    of copy area, return corresponding displaced_step_closure.  Otherwise,
1179c50c785cSJohn Marino    return NULL.  */
1180c50c785cSJohn Marino 
1181c50c785cSJohn Marino struct displaced_step_closure*
get_displaced_step_closure_by_addr(CORE_ADDR addr)1182c50c785cSJohn Marino get_displaced_step_closure_by_addr (CORE_ADDR addr)
1183c50c785cSJohn Marino {
1184c50c785cSJohn Marino   struct displaced_step_inferior_state *displaced
1185c50c785cSJohn Marino     = get_displaced_stepping_state (ptid_get_pid (inferior_ptid));
1186c50c785cSJohn Marino 
1187c50c785cSJohn Marino   /* If checking the mode of displaced instruction in copy area.  */
1188c50c785cSJohn Marino   if (displaced && !ptid_equal (displaced->step_ptid, null_ptid)
1189c50c785cSJohn Marino      && (displaced->step_copy == addr))
1190c50c785cSJohn Marino     return displaced->step_closure;
1191c50c785cSJohn Marino 
1192c50c785cSJohn Marino   return NULL;
1193c50c785cSJohn Marino }
1194c50c785cSJohn Marino 
1195cf7f2e2dSJohn Marino /* Remove the displaced stepping state of process PID.  */
1196cf7f2e2dSJohn Marino 
1197cf7f2e2dSJohn Marino static void
remove_displaced_stepping_state(int pid)1198cf7f2e2dSJohn Marino remove_displaced_stepping_state (int pid)
1199cf7f2e2dSJohn Marino {
1200cf7f2e2dSJohn Marino   struct displaced_step_inferior_state *it, **prev_next_p;
1201cf7f2e2dSJohn Marino 
1202cf7f2e2dSJohn Marino   gdb_assert (pid != 0);
1203cf7f2e2dSJohn Marino 
1204cf7f2e2dSJohn Marino   it = displaced_step_inferior_states;
1205cf7f2e2dSJohn Marino   prev_next_p = &displaced_step_inferior_states;
1206cf7f2e2dSJohn Marino   while (it)
1207cf7f2e2dSJohn Marino     {
1208cf7f2e2dSJohn Marino       if (it->pid == pid)
1209cf7f2e2dSJohn Marino 	{
1210cf7f2e2dSJohn Marino 	  *prev_next_p = it->next;
1211cf7f2e2dSJohn Marino 	  xfree (it);
1212cf7f2e2dSJohn Marino 	  return;
1213cf7f2e2dSJohn Marino 	}
1214cf7f2e2dSJohn Marino 
1215cf7f2e2dSJohn Marino       prev_next_p = &it->next;
1216cf7f2e2dSJohn Marino       it = *prev_next_p;
1217cf7f2e2dSJohn Marino     }
1218cf7f2e2dSJohn Marino }
1219cf7f2e2dSJohn Marino 
1220cf7f2e2dSJohn Marino static void
infrun_inferior_exit(struct inferior * inf)1221cf7f2e2dSJohn Marino infrun_inferior_exit (struct inferior *inf)
1222cf7f2e2dSJohn Marino {
1223cf7f2e2dSJohn Marino   remove_displaced_stepping_state (inf->pid);
1224cf7f2e2dSJohn Marino }
12255796c8dcSSimon Schubert 
12265796c8dcSSimon Schubert /* If ON, and the architecture supports it, GDB will use displaced
12275796c8dcSSimon Schubert    stepping to step over breakpoints.  If OFF, or if the architecture
12285796c8dcSSimon Schubert    doesn't support it, GDB will instead use the traditional
12295796c8dcSSimon Schubert    hold-and-step approach.  If AUTO (which is the default), GDB will
12305796c8dcSSimon Schubert    decide which technique to use to step over breakpoints depending on
12315796c8dcSSimon Schubert    which of all-stop or non-stop mode is active --- displaced stepping
12325796c8dcSSimon Schubert    in non-stop mode; hold-and-step in all-stop mode.  */
12335796c8dcSSimon Schubert 
1234*ef5ccd6cSJohn Marino static enum auto_boolean can_use_displaced_stepping = AUTO_BOOLEAN_AUTO;
12355796c8dcSSimon Schubert 
12365796c8dcSSimon Schubert static void
show_can_use_displaced_stepping(struct ui_file * file,int from_tty,struct cmd_list_element * c,const char * value)12375796c8dcSSimon Schubert show_can_use_displaced_stepping (struct ui_file *file, int from_tty,
12385796c8dcSSimon Schubert 				 struct cmd_list_element *c,
12395796c8dcSSimon Schubert 				 const char *value)
12405796c8dcSSimon Schubert {
1241*ef5ccd6cSJohn Marino   if (can_use_displaced_stepping == AUTO_BOOLEAN_AUTO)
1242c50c785cSJohn Marino     fprintf_filtered (file,
1243c50c785cSJohn Marino 		      _("Debugger's willingness to use displaced stepping "
1244c50c785cSJohn Marino 			"to step over breakpoints is %s (currently %s).\n"),
12455796c8dcSSimon Schubert 		      value, non_stop ? "on" : "off");
12465796c8dcSSimon Schubert   else
1247c50c785cSJohn Marino     fprintf_filtered (file,
1248c50c785cSJohn Marino 		      _("Debugger's willingness to use displaced stepping "
1249c50c785cSJohn Marino 			"to step over breakpoints is %s.\n"), value);
12505796c8dcSSimon Schubert }
12515796c8dcSSimon Schubert 
12525796c8dcSSimon Schubert /* Return non-zero if displaced stepping can/should be used to step
12535796c8dcSSimon Schubert    over breakpoints.  */
12545796c8dcSSimon Schubert 
12555796c8dcSSimon Schubert static int
use_displaced_stepping(struct gdbarch * gdbarch)12565796c8dcSSimon Schubert use_displaced_stepping (struct gdbarch *gdbarch)
12575796c8dcSSimon Schubert {
1258*ef5ccd6cSJohn Marino   return (((can_use_displaced_stepping == AUTO_BOOLEAN_AUTO && non_stop)
1259*ef5ccd6cSJohn Marino 	   || can_use_displaced_stepping == AUTO_BOOLEAN_TRUE)
12605796c8dcSSimon Schubert 	  && gdbarch_displaced_step_copy_insn_p (gdbarch)
12615796c8dcSSimon Schubert 	  && !RECORD_IS_USED);
12625796c8dcSSimon Schubert }
12635796c8dcSSimon Schubert 
12645796c8dcSSimon Schubert /* Clean out any stray displaced stepping state.  */
12655796c8dcSSimon Schubert static void
displaced_step_clear(struct displaced_step_inferior_state * displaced)1266cf7f2e2dSJohn Marino displaced_step_clear (struct displaced_step_inferior_state *displaced)
12675796c8dcSSimon Schubert {
12685796c8dcSSimon Schubert   /* Indicate that there is no cleanup pending.  */
1269cf7f2e2dSJohn Marino   displaced->step_ptid = null_ptid;
12705796c8dcSSimon Schubert 
1271cf7f2e2dSJohn Marino   if (displaced->step_closure)
12725796c8dcSSimon Schubert     {
1273cf7f2e2dSJohn Marino       gdbarch_displaced_step_free_closure (displaced->step_gdbarch,
1274cf7f2e2dSJohn Marino                                            displaced->step_closure);
1275cf7f2e2dSJohn Marino       displaced->step_closure = NULL;
12765796c8dcSSimon Schubert     }
12775796c8dcSSimon Schubert }
12785796c8dcSSimon Schubert 
12795796c8dcSSimon Schubert static void
displaced_step_clear_cleanup(void * arg)1280cf7f2e2dSJohn Marino displaced_step_clear_cleanup (void *arg)
12815796c8dcSSimon Schubert {
1282cf7f2e2dSJohn Marino   struct displaced_step_inferior_state *state = arg;
1283cf7f2e2dSJohn Marino 
1284cf7f2e2dSJohn Marino   displaced_step_clear (state);
12855796c8dcSSimon Schubert }
12865796c8dcSSimon Schubert 
12875796c8dcSSimon Schubert /* Dump LEN bytes at BUF in hex to FILE, followed by a newline.  */
12885796c8dcSSimon Schubert void
displaced_step_dump_bytes(struct ui_file * file,const gdb_byte * buf,size_t len)12895796c8dcSSimon Schubert displaced_step_dump_bytes (struct ui_file *file,
12905796c8dcSSimon Schubert                            const gdb_byte *buf,
12915796c8dcSSimon Schubert                            size_t len)
12925796c8dcSSimon Schubert {
12935796c8dcSSimon Schubert   int i;
12945796c8dcSSimon Schubert 
12955796c8dcSSimon Schubert   for (i = 0; i < len; i++)
12965796c8dcSSimon Schubert     fprintf_unfiltered (file, "%02x ", buf[i]);
12975796c8dcSSimon Schubert   fputs_unfiltered ("\n", file);
12985796c8dcSSimon Schubert }
12995796c8dcSSimon Schubert 
13005796c8dcSSimon Schubert /* Prepare to single-step, using displaced stepping.
13015796c8dcSSimon Schubert 
13025796c8dcSSimon Schubert    Note that we cannot use displaced stepping when we have a signal to
13035796c8dcSSimon Schubert    deliver.  If we have a signal to deliver and an instruction to step
13045796c8dcSSimon Schubert    over, then after the step, there will be no indication from the
13055796c8dcSSimon Schubert    target whether the thread entered a signal handler or ignored the
13065796c8dcSSimon Schubert    signal and stepped over the instruction successfully --- both cases
13075796c8dcSSimon Schubert    result in a simple SIGTRAP.  In the first case we mustn't do a
13085796c8dcSSimon Schubert    fixup, and in the second case we must --- but we can't tell which.
13095796c8dcSSimon Schubert    Comments in the code for 'random signals' in handle_inferior_event
13105796c8dcSSimon Schubert    explain how we handle this case instead.
13115796c8dcSSimon Schubert 
13125796c8dcSSimon Schubert    Returns 1 if preparing was successful -- this thread is going to be
13135796c8dcSSimon Schubert    stepped now; or 0 if displaced stepping this thread got queued.  */
13145796c8dcSSimon Schubert static int
displaced_step_prepare(ptid_t ptid)13155796c8dcSSimon Schubert displaced_step_prepare (ptid_t ptid)
13165796c8dcSSimon Schubert {
13175796c8dcSSimon Schubert   struct cleanup *old_cleanups, *ignore_cleanups;
13185796c8dcSSimon Schubert   struct regcache *regcache = get_thread_regcache (ptid);
13195796c8dcSSimon Schubert   struct gdbarch *gdbarch = get_regcache_arch (regcache);
13205796c8dcSSimon Schubert   CORE_ADDR original, copy;
13215796c8dcSSimon Schubert   ULONGEST len;
13225796c8dcSSimon Schubert   struct displaced_step_closure *closure;
1323cf7f2e2dSJohn Marino   struct displaced_step_inferior_state *displaced;
1324*ef5ccd6cSJohn Marino   int status;
13255796c8dcSSimon Schubert 
13265796c8dcSSimon Schubert   /* We should never reach this function if the architecture does not
13275796c8dcSSimon Schubert      support displaced stepping.  */
13285796c8dcSSimon Schubert   gdb_assert (gdbarch_displaced_step_copy_insn_p (gdbarch));
13295796c8dcSSimon Schubert 
1330cf7f2e2dSJohn Marino   /* We have to displaced step one thread at a time, as we only have
1331cf7f2e2dSJohn Marino      access to a single scratch space per inferior.  */
13325796c8dcSSimon Schubert 
1333cf7f2e2dSJohn Marino   displaced = add_displaced_stepping_state (ptid_get_pid (ptid));
1334cf7f2e2dSJohn Marino 
1335cf7f2e2dSJohn Marino   if (!ptid_equal (displaced->step_ptid, null_ptid))
13365796c8dcSSimon Schubert     {
13375796c8dcSSimon Schubert       /* Already waiting for a displaced step to finish.  Defer this
13385796c8dcSSimon Schubert 	 request and place in queue.  */
13395796c8dcSSimon Schubert       struct displaced_step_request *req, *new_req;
13405796c8dcSSimon Schubert 
13415796c8dcSSimon Schubert       if (debug_displaced)
13425796c8dcSSimon Schubert 	fprintf_unfiltered (gdb_stdlog,
13435796c8dcSSimon Schubert 			    "displaced: defering step of %s\n",
13445796c8dcSSimon Schubert 			    target_pid_to_str (ptid));
13455796c8dcSSimon Schubert 
13465796c8dcSSimon Schubert       new_req = xmalloc (sizeof (*new_req));
13475796c8dcSSimon Schubert       new_req->ptid = ptid;
13485796c8dcSSimon Schubert       new_req->next = NULL;
13495796c8dcSSimon Schubert 
1350cf7f2e2dSJohn Marino       if (displaced->step_request_queue)
13515796c8dcSSimon Schubert 	{
1352cf7f2e2dSJohn Marino 	  for (req = displaced->step_request_queue;
13535796c8dcSSimon Schubert 	       req && req->next;
13545796c8dcSSimon Schubert 	       req = req->next)
13555796c8dcSSimon Schubert 	    ;
13565796c8dcSSimon Schubert 	  req->next = new_req;
13575796c8dcSSimon Schubert 	}
13585796c8dcSSimon Schubert       else
1359cf7f2e2dSJohn Marino 	displaced->step_request_queue = new_req;
13605796c8dcSSimon Schubert 
13615796c8dcSSimon Schubert       return 0;
13625796c8dcSSimon Schubert     }
13635796c8dcSSimon Schubert   else
13645796c8dcSSimon Schubert     {
13655796c8dcSSimon Schubert       if (debug_displaced)
13665796c8dcSSimon Schubert 	fprintf_unfiltered (gdb_stdlog,
13675796c8dcSSimon Schubert 			    "displaced: stepping %s now\n",
13685796c8dcSSimon Schubert 			    target_pid_to_str (ptid));
13695796c8dcSSimon Schubert     }
13705796c8dcSSimon Schubert 
1371cf7f2e2dSJohn Marino   displaced_step_clear (displaced);
13725796c8dcSSimon Schubert 
13735796c8dcSSimon Schubert   old_cleanups = save_inferior_ptid ();
13745796c8dcSSimon Schubert   inferior_ptid = ptid;
13755796c8dcSSimon Schubert 
13765796c8dcSSimon Schubert   original = regcache_read_pc (regcache);
13775796c8dcSSimon Schubert 
13785796c8dcSSimon Schubert   copy = gdbarch_displaced_step_location (gdbarch);
13795796c8dcSSimon Schubert   len = gdbarch_max_insn_length (gdbarch);
13805796c8dcSSimon Schubert 
13815796c8dcSSimon Schubert   /* Save the original contents of the copy area.  */
1382cf7f2e2dSJohn Marino   displaced->step_saved_copy = xmalloc (len);
13835796c8dcSSimon Schubert   ignore_cleanups = make_cleanup (free_current_contents,
1384cf7f2e2dSJohn Marino 				  &displaced->step_saved_copy);
1385*ef5ccd6cSJohn Marino   status = target_read_memory (copy, displaced->step_saved_copy, len);
1386*ef5ccd6cSJohn Marino   if (status != 0)
1387*ef5ccd6cSJohn Marino     throw_error (MEMORY_ERROR,
1388*ef5ccd6cSJohn Marino 		 _("Error accessing memory address %s (%s) for "
1389*ef5ccd6cSJohn Marino 		   "displaced-stepping scratch space."),
1390*ef5ccd6cSJohn Marino 		 paddress (gdbarch, copy), safe_strerror (status));
13915796c8dcSSimon Schubert   if (debug_displaced)
13925796c8dcSSimon Schubert     {
13935796c8dcSSimon Schubert       fprintf_unfiltered (gdb_stdlog, "displaced: saved %s: ",
13945796c8dcSSimon Schubert 			  paddress (gdbarch, copy));
1395cf7f2e2dSJohn Marino       displaced_step_dump_bytes (gdb_stdlog,
1396cf7f2e2dSJohn Marino 				 displaced->step_saved_copy,
1397cf7f2e2dSJohn Marino 				 len);
13985796c8dcSSimon Schubert     };
13995796c8dcSSimon Schubert 
14005796c8dcSSimon Schubert   closure = gdbarch_displaced_step_copy_insn (gdbarch,
14015796c8dcSSimon Schubert 					      original, copy, regcache);
14025796c8dcSSimon Schubert 
14035796c8dcSSimon Schubert   /* We don't support the fully-simulated case at present.  */
14045796c8dcSSimon Schubert   gdb_assert (closure);
14055796c8dcSSimon Schubert 
14065796c8dcSSimon Schubert   /* Save the information we need to fix things up if the step
14075796c8dcSSimon Schubert      succeeds.  */
1408cf7f2e2dSJohn Marino   displaced->step_ptid = ptid;
1409cf7f2e2dSJohn Marino   displaced->step_gdbarch = gdbarch;
1410cf7f2e2dSJohn Marino   displaced->step_closure = closure;
1411cf7f2e2dSJohn Marino   displaced->step_original = original;
1412cf7f2e2dSJohn Marino   displaced->step_copy = copy;
14135796c8dcSSimon Schubert 
1414cf7f2e2dSJohn Marino   make_cleanup (displaced_step_clear_cleanup, displaced);
14155796c8dcSSimon Schubert 
14165796c8dcSSimon Schubert   /* Resume execution at the copy.  */
14175796c8dcSSimon Schubert   regcache_write_pc (regcache, copy);
14185796c8dcSSimon Schubert 
14195796c8dcSSimon Schubert   discard_cleanups (ignore_cleanups);
14205796c8dcSSimon Schubert 
14215796c8dcSSimon Schubert   do_cleanups (old_cleanups);
14225796c8dcSSimon Schubert 
14235796c8dcSSimon Schubert   if (debug_displaced)
14245796c8dcSSimon Schubert     fprintf_unfiltered (gdb_stdlog, "displaced: displaced pc to %s\n",
14255796c8dcSSimon Schubert 			paddress (gdbarch, copy));
14265796c8dcSSimon Schubert 
14275796c8dcSSimon Schubert   return 1;
14285796c8dcSSimon Schubert }
14295796c8dcSSimon Schubert 
14305796c8dcSSimon Schubert static void
write_memory_ptid(ptid_t ptid,CORE_ADDR memaddr,const gdb_byte * myaddr,int len)1431c50c785cSJohn Marino write_memory_ptid (ptid_t ptid, CORE_ADDR memaddr,
1432c50c785cSJohn Marino 		   const gdb_byte *myaddr, int len)
14335796c8dcSSimon Schubert {
14345796c8dcSSimon Schubert   struct cleanup *ptid_cleanup = save_inferior_ptid ();
1435cf7f2e2dSJohn Marino 
14365796c8dcSSimon Schubert   inferior_ptid = ptid;
14375796c8dcSSimon Schubert   write_memory (memaddr, myaddr, len);
14385796c8dcSSimon Schubert   do_cleanups (ptid_cleanup);
14395796c8dcSSimon Schubert }
14405796c8dcSSimon Schubert 
1441a45ae5f8SJohn Marino /* Restore the contents of the copy area for thread PTID.  */
1442a45ae5f8SJohn Marino 
1443a45ae5f8SJohn Marino static void
displaced_step_restore(struct displaced_step_inferior_state * displaced,ptid_t ptid)1444a45ae5f8SJohn Marino displaced_step_restore (struct displaced_step_inferior_state *displaced,
1445a45ae5f8SJohn Marino 			ptid_t ptid)
1446a45ae5f8SJohn Marino {
1447a45ae5f8SJohn Marino   ULONGEST len = gdbarch_max_insn_length (displaced->step_gdbarch);
1448a45ae5f8SJohn Marino 
1449a45ae5f8SJohn Marino   write_memory_ptid (ptid, displaced->step_copy,
1450a45ae5f8SJohn Marino 		     displaced->step_saved_copy, len);
1451a45ae5f8SJohn Marino   if (debug_displaced)
1452a45ae5f8SJohn Marino     fprintf_unfiltered (gdb_stdlog, "displaced: restored %s %s\n",
1453a45ae5f8SJohn Marino 			target_pid_to_str (ptid),
1454a45ae5f8SJohn Marino 			paddress (displaced->step_gdbarch,
1455a45ae5f8SJohn Marino 				  displaced->step_copy));
1456a45ae5f8SJohn Marino }
1457a45ae5f8SJohn Marino 
14585796c8dcSSimon Schubert static void
displaced_step_fixup(ptid_t event_ptid,enum gdb_signal signal)1459*ef5ccd6cSJohn Marino displaced_step_fixup (ptid_t event_ptid, enum gdb_signal signal)
14605796c8dcSSimon Schubert {
14615796c8dcSSimon Schubert   struct cleanup *old_cleanups;
1462cf7f2e2dSJohn Marino   struct displaced_step_inferior_state *displaced
1463cf7f2e2dSJohn Marino     = get_displaced_stepping_state (ptid_get_pid (event_ptid));
14645796c8dcSSimon Schubert 
1465cf7f2e2dSJohn Marino   /* Was any thread of this process doing a displaced step?  */
1466cf7f2e2dSJohn Marino   if (displaced == NULL)
14675796c8dcSSimon Schubert     return;
14685796c8dcSSimon Schubert 
1469cf7f2e2dSJohn Marino   /* Was this event for the pid we displaced?  */
1470cf7f2e2dSJohn Marino   if (ptid_equal (displaced->step_ptid, null_ptid)
1471cf7f2e2dSJohn Marino       || ! ptid_equal (displaced->step_ptid, event_ptid))
1472cf7f2e2dSJohn Marino     return;
1473cf7f2e2dSJohn Marino 
1474cf7f2e2dSJohn Marino   old_cleanups = make_cleanup (displaced_step_clear_cleanup, displaced);
14755796c8dcSSimon Schubert 
1476a45ae5f8SJohn Marino   displaced_step_restore (displaced, displaced->step_ptid);
14775796c8dcSSimon Schubert 
14785796c8dcSSimon Schubert   /* Did the instruction complete successfully?  */
1479*ef5ccd6cSJohn Marino   if (signal == GDB_SIGNAL_TRAP)
14805796c8dcSSimon Schubert     {
14815796c8dcSSimon Schubert       /* Fix up the resulting state.  */
1482cf7f2e2dSJohn Marino       gdbarch_displaced_step_fixup (displaced->step_gdbarch,
1483cf7f2e2dSJohn Marino                                     displaced->step_closure,
1484cf7f2e2dSJohn Marino                                     displaced->step_original,
1485cf7f2e2dSJohn Marino                                     displaced->step_copy,
1486cf7f2e2dSJohn Marino                                     get_thread_regcache (displaced->step_ptid));
14875796c8dcSSimon Schubert     }
14885796c8dcSSimon Schubert   else
14895796c8dcSSimon Schubert     {
14905796c8dcSSimon Schubert       /* Since the instruction didn't complete, all we can do is
14915796c8dcSSimon Schubert          relocate the PC.  */
14925796c8dcSSimon Schubert       struct regcache *regcache = get_thread_regcache (event_ptid);
14935796c8dcSSimon Schubert       CORE_ADDR pc = regcache_read_pc (regcache);
1494cf7f2e2dSJohn Marino 
1495cf7f2e2dSJohn Marino       pc = displaced->step_original + (pc - displaced->step_copy);
14965796c8dcSSimon Schubert       regcache_write_pc (regcache, pc);
14975796c8dcSSimon Schubert     }
14985796c8dcSSimon Schubert 
14995796c8dcSSimon Schubert   do_cleanups (old_cleanups);
15005796c8dcSSimon Schubert 
1501cf7f2e2dSJohn Marino   displaced->step_ptid = null_ptid;
15025796c8dcSSimon Schubert 
15035796c8dcSSimon Schubert   /* Are there any pending displaced stepping requests?  If so, run
1504cf7f2e2dSJohn Marino      one now.  Leave the state object around, since we're likely to
1505cf7f2e2dSJohn Marino      need it again soon.  */
1506cf7f2e2dSJohn Marino   while (displaced->step_request_queue)
15075796c8dcSSimon Schubert     {
15085796c8dcSSimon Schubert       struct displaced_step_request *head;
15095796c8dcSSimon Schubert       ptid_t ptid;
15105796c8dcSSimon Schubert       struct regcache *regcache;
15115796c8dcSSimon Schubert       struct gdbarch *gdbarch;
15125796c8dcSSimon Schubert       CORE_ADDR actual_pc;
1513cf7f2e2dSJohn Marino       struct address_space *aspace;
15145796c8dcSSimon Schubert 
1515cf7f2e2dSJohn Marino       head = displaced->step_request_queue;
15165796c8dcSSimon Schubert       ptid = head->ptid;
1517cf7f2e2dSJohn Marino       displaced->step_request_queue = head->next;
15185796c8dcSSimon Schubert       xfree (head);
15195796c8dcSSimon Schubert 
15205796c8dcSSimon Schubert       context_switch (ptid);
15215796c8dcSSimon Schubert 
15225796c8dcSSimon Schubert       regcache = get_thread_regcache (ptid);
15235796c8dcSSimon Schubert       actual_pc = regcache_read_pc (regcache);
1524cf7f2e2dSJohn Marino       aspace = get_regcache_aspace (regcache);
15255796c8dcSSimon Schubert 
1526cf7f2e2dSJohn Marino       if (breakpoint_here_p (aspace, actual_pc))
15275796c8dcSSimon Schubert 	{
15285796c8dcSSimon Schubert 	  if (debug_displaced)
15295796c8dcSSimon Schubert 	    fprintf_unfiltered (gdb_stdlog,
15305796c8dcSSimon Schubert 				"displaced: stepping queued %s now\n",
15315796c8dcSSimon Schubert 				target_pid_to_str (ptid));
15325796c8dcSSimon Schubert 
15335796c8dcSSimon Schubert 	  displaced_step_prepare (ptid);
15345796c8dcSSimon Schubert 
15355796c8dcSSimon Schubert 	  gdbarch = get_regcache_arch (regcache);
15365796c8dcSSimon Schubert 
15375796c8dcSSimon Schubert 	  if (debug_displaced)
15385796c8dcSSimon Schubert 	    {
15395796c8dcSSimon Schubert 	      CORE_ADDR actual_pc = regcache_read_pc (regcache);
15405796c8dcSSimon Schubert 	      gdb_byte buf[4];
15415796c8dcSSimon Schubert 
15425796c8dcSSimon Schubert 	      fprintf_unfiltered (gdb_stdlog, "displaced: run %s: ",
15435796c8dcSSimon Schubert 				  paddress (gdbarch, actual_pc));
15445796c8dcSSimon Schubert 	      read_memory (actual_pc, buf, sizeof (buf));
15455796c8dcSSimon Schubert 	      displaced_step_dump_bytes (gdb_stdlog, buf, sizeof (buf));
15465796c8dcSSimon Schubert 	    }
15475796c8dcSSimon Schubert 
1548cf7f2e2dSJohn Marino 	  if (gdbarch_displaced_step_hw_singlestep (gdbarch,
1549cf7f2e2dSJohn Marino 						    displaced->step_closure))
1550*ef5ccd6cSJohn Marino 	    target_resume (ptid, 1, GDB_SIGNAL_0);
15515796c8dcSSimon Schubert 	  else
1552*ef5ccd6cSJohn Marino 	    target_resume (ptid, 0, GDB_SIGNAL_0);
15535796c8dcSSimon Schubert 
15545796c8dcSSimon Schubert 	  /* Done, we're stepping a thread.  */
15555796c8dcSSimon Schubert 	  break;
15565796c8dcSSimon Schubert 	}
15575796c8dcSSimon Schubert       else
15585796c8dcSSimon Schubert 	{
15595796c8dcSSimon Schubert 	  int step;
15605796c8dcSSimon Schubert 	  struct thread_info *tp = inferior_thread ();
15615796c8dcSSimon Schubert 
15625796c8dcSSimon Schubert 	  /* The breakpoint we were sitting under has since been
15635796c8dcSSimon Schubert 	     removed.  */
1564c50c785cSJohn Marino 	  tp->control.trap_expected = 0;
15655796c8dcSSimon Schubert 
15665796c8dcSSimon Schubert 	  /* Go back to what we were trying to do.  */
15675796c8dcSSimon Schubert 	  step = currently_stepping (tp);
15685796c8dcSSimon Schubert 
15695796c8dcSSimon Schubert 	  if (debug_displaced)
1570c50c785cSJohn Marino 	    fprintf_unfiltered (gdb_stdlog,
1571*ef5ccd6cSJohn Marino 				"displaced: breakpoint is gone: %s, step(%d)\n",
15725796c8dcSSimon Schubert 				target_pid_to_str (tp->ptid), step);
15735796c8dcSSimon Schubert 
1574*ef5ccd6cSJohn Marino 	  target_resume (ptid, step, GDB_SIGNAL_0);
1575*ef5ccd6cSJohn Marino 	  tp->suspend.stop_signal = GDB_SIGNAL_0;
15765796c8dcSSimon Schubert 
15775796c8dcSSimon Schubert 	  /* This request was discarded.  See if there's any other
15785796c8dcSSimon Schubert 	     thread waiting for its turn.  */
15795796c8dcSSimon Schubert 	}
15805796c8dcSSimon Schubert     }
15815796c8dcSSimon Schubert }
15825796c8dcSSimon Schubert 
15835796c8dcSSimon Schubert /* Update global variables holding ptids to hold NEW_PTID if they were
15845796c8dcSSimon Schubert    holding OLD_PTID.  */
15855796c8dcSSimon Schubert static void
infrun_thread_ptid_changed(ptid_t old_ptid,ptid_t new_ptid)15865796c8dcSSimon Schubert infrun_thread_ptid_changed (ptid_t old_ptid, ptid_t new_ptid)
15875796c8dcSSimon Schubert {
15885796c8dcSSimon Schubert   struct displaced_step_request *it;
1589cf7f2e2dSJohn Marino   struct displaced_step_inferior_state *displaced;
15905796c8dcSSimon Schubert 
15915796c8dcSSimon Schubert   if (ptid_equal (inferior_ptid, old_ptid))
15925796c8dcSSimon Schubert     inferior_ptid = new_ptid;
15935796c8dcSSimon Schubert 
15945796c8dcSSimon Schubert   if (ptid_equal (singlestep_ptid, old_ptid))
15955796c8dcSSimon Schubert     singlestep_ptid = new_ptid;
15965796c8dcSSimon Schubert 
15975796c8dcSSimon Schubert   if (ptid_equal (deferred_step_ptid, old_ptid))
15985796c8dcSSimon Schubert     deferred_step_ptid = new_ptid;
15995796c8dcSSimon Schubert 
1600cf7f2e2dSJohn Marino   for (displaced = displaced_step_inferior_states;
1601cf7f2e2dSJohn Marino        displaced;
1602cf7f2e2dSJohn Marino        displaced = displaced->next)
1603cf7f2e2dSJohn Marino     {
1604cf7f2e2dSJohn Marino       if (ptid_equal (displaced->step_ptid, old_ptid))
1605cf7f2e2dSJohn Marino 	displaced->step_ptid = new_ptid;
1606cf7f2e2dSJohn Marino 
1607cf7f2e2dSJohn Marino       for (it = displaced->step_request_queue; it; it = it->next)
16085796c8dcSSimon Schubert 	if (ptid_equal (it->ptid, old_ptid))
16095796c8dcSSimon Schubert 	  it->ptid = new_ptid;
16105796c8dcSSimon Schubert     }
1611cf7f2e2dSJohn Marino }
16125796c8dcSSimon Schubert 
16135796c8dcSSimon Schubert 
16145796c8dcSSimon Schubert /* Resuming.  */
16155796c8dcSSimon Schubert 
16165796c8dcSSimon Schubert /* Things to clean up if we QUIT out of resume ().  */
16175796c8dcSSimon Schubert static void
resume_cleanups(void * ignore)16185796c8dcSSimon Schubert resume_cleanups (void *ignore)
16195796c8dcSSimon Schubert {
16205796c8dcSSimon Schubert   normal_stop ();
16215796c8dcSSimon Schubert }
16225796c8dcSSimon Schubert 
16235796c8dcSSimon Schubert static const char schedlock_off[] = "off";
16245796c8dcSSimon Schubert static const char schedlock_on[] = "on";
16255796c8dcSSimon Schubert static const char schedlock_step[] = "step";
1626*ef5ccd6cSJohn Marino static const char *const scheduler_enums[] = {
16275796c8dcSSimon Schubert   schedlock_off,
16285796c8dcSSimon Schubert   schedlock_on,
16295796c8dcSSimon Schubert   schedlock_step,
16305796c8dcSSimon Schubert   NULL
16315796c8dcSSimon Schubert };
16325796c8dcSSimon Schubert static const char *scheduler_mode = schedlock_off;
16335796c8dcSSimon Schubert static void
show_scheduler_mode(struct ui_file * file,int from_tty,struct cmd_list_element * c,const char * value)16345796c8dcSSimon Schubert show_scheduler_mode (struct ui_file *file, int from_tty,
16355796c8dcSSimon Schubert 		     struct cmd_list_element *c, const char *value)
16365796c8dcSSimon Schubert {
1637c50c785cSJohn Marino   fprintf_filtered (file,
1638c50c785cSJohn Marino 		    _("Mode for locking scheduler "
1639c50c785cSJohn Marino 		      "during execution is \"%s\".\n"),
16405796c8dcSSimon Schubert 		    value);
16415796c8dcSSimon Schubert }
16425796c8dcSSimon Schubert 
16435796c8dcSSimon Schubert static void
set_schedlock_func(char * args,int from_tty,struct cmd_list_element * c)16445796c8dcSSimon Schubert set_schedlock_func (char *args, int from_tty, struct cmd_list_element *c)
16455796c8dcSSimon Schubert {
16465796c8dcSSimon Schubert   if (!target_can_lock_scheduler)
16475796c8dcSSimon Schubert     {
16485796c8dcSSimon Schubert       scheduler_mode = schedlock_off;
16495796c8dcSSimon Schubert       error (_("Target '%s' cannot support this command."), target_shortname);
16505796c8dcSSimon Schubert     }
16515796c8dcSSimon Schubert }
16525796c8dcSSimon Schubert 
16535796c8dcSSimon Schubert /* True if execution commands resume all threads of all processes by
16545796c8dcSSimon Schubert    default; otherwise, resume only threads of the current inferior
16555796c8dcSSimon Schubert    process.  */
16565796c8dcSSimon Schubert int sched_multi = 0;
16575796c8dcSSimon Schubert 
16585796c8dcSSimon Schubert /* Try to setup for software single stepping over the specified location.
16595796c8dcSSimon Schubert    Return 1 if target_resume() should use hardware single step.
16605796c8dcSSimon Schubert 
16615796c8dcSSimon Schubert    GDBARCH the current gdbarch.
16625796c8dcSSimon Schubert    PC the location to step over.  */
16635796c8dcSSimon Schubert 
16645796c8dcSSimon Schubert static int
maybe_software_singlestep(struct gdbarch * gdbarch,CORE_ADDR pc)16655796c8dcSSimon Schubert maybe_software_singlestep (struct gdbarch *gdbarch, CORE_ADDR pc)
16665796c8dcSSimon Schubert {
16675796c8dcSSimon Schubert   int hw_step = 1;
16685796c8dcSSimon Schubert 
1669c50c785cSJohn Marino   if (execution_direction == EXEC_FORWARD
1670c50c785cSJohn Marino       && gdbarch_software_single_step_p (gdbarch)
16715796c8dcSSimon Schubert       && gdbarch_software_single_step (gdbarch, get_current_frame ()))
16725796c8dcSSimon Schubert     {
16735796c8dcSSimon Schubert       hw_step = 0;
16745796c8dcSSimon Schubert       /* Do not pull these breakpoints until after a `wait' in
1675c50c785cSJohn Marino 	 `wait_for_inferior'.  */
16765796c8dcSSimon Schubert       singlestep_breakpoints_inserted_p = 1;
16775796c8dcSSimon Schubert       singlestep_ptid = inferior_ptid;
16785796c8dcSSimon Schubert       singlestep_pc = pc;
16795796c8dcSSimon Schubert     }
16805796c8dcSSimon Schubert   return hw_step;
16815796c8dcSSimon Schubert }
16825796c8dcSSimon Schubert 
1683a45ae5f8SJohn Marino /* Return a ptid representing the set of threads that we will proceed,
1684a45ae5f8SJohn Marino    in the perspective of the user/frontend.  We may actually resume
1685a45ae5f8SJohn Marino    fewer threads at first, e.g., if a thread is stopped at a
1686a45ae5f8SJohn Marino    breakpoint that needs stepping-off, but that should not be visible
1687a45ae5f8SJohn Marino    to the user/frontend, and neither should the frontend/user be
1688a45ae5f8SJohn Marino    allowed to proceed any of the threads that happen to be stopped for
1689a45ae5f8SJohn Marino    internal run control handling, if a previous command wanted them
1690a45ae5f8SJohn Marino    resumed.  */
1691a45ae5f8SJohn Marino 
1692a45ae5f8SJohn Marino ptid_t
user_visible_resume_ptid(int step)1693a45ae5f8SJohn Marino user_visible_resume_ptid (int step)
1694a45ae5f8SJohn Marino {
1695a45ae5f8SJohn Marino   /* By default, resume all threads of all processes.  */
1696a45ae5f8SJohn Marino   ptid_t resume_ptid = RESUME_ALL;
1697a45ae5f8SJohn Marino 
1698a45ae5f8SJohn Marino   /* Maybe resume only all threads of the current process.  */
1699a45ae5f8SJohn Marino   if (!sched_multi && target_supports_multi_process ())
1700a45ae5f8SJohn Marino     {
1701a45ae5f8SJohn Marino       resume_ptid = pid_to_ptid (ptid_get_pid (inferior_ptid));
1702a45ae5f8SJohn Marino     }
1703a45ae5f8SJohn Marino 
1704a45ae5f8SJohn Marino   /* Maybe resume a single thread after all.  */
1705a45ae5f8SJohn Marino   if (non_stop)
1706a45ae5f8SJohn Marino     {
1707a45ae5f8SJohn Marino       /* With non-stop mode on, threads are always handled
1708a45ae5f8SJohn Marino 	 individually.  */
1709a45ae5f8SJohn Marino       resume_ptid = inferior_ptid;
1710a45ae5f8SJohn Marino     }
1711a45ae5f8SJohn Marino   else if ((scheduler_mode == schedlock_on)
1712a45ae5f8SJohn Marino 	   || (scheduler_mode == schedlock_step
1713a45ae5f8SJohn Marino 	       && (step || singlestep_breakpoints_inserted_p)))
1714a45ae5f8SJohn Marino     {
1715a45ae5f8SJohn Marino       /* User-settable 'scheduler' mode requires solo thread resume.  */
1716a45ae5f8SJohn Marino       resume_ptid = inferior_ptid;
1717a45ae5f8SJohn Marino     }
1718a45ae5f8SJohn Marino 
1719a45ae5f8SJohn Marino   return resume_ptid;
1720a45ae5f8SJohn Marino }
1721a45ae5f8SJohn Marino 
17225796c8dcSSimon Schubert /* Resume the inferior, but allow a QUIT.  This is useful if the user
17235796c8dcSSimon Schubert    wants to interrupt some lengthy single-stepping operation
17245796c8dcSSimon Schubert    (for child processes, the SIGINT goes to the inferior, and so
17255796c8dcSSimon Schubert    we get a SIGINT random_signal, but for remote debugging and perhaps
17265796c8dcSSimon Schubert    other targets, that's not true).
17275796c8dcSSimon Schubert 
17285796c8dcSSimon Schubert    STEP nonzero if we should step (zero to continue instead).
17295796c8dcSSimon Schubert    SIG is the signal to give the inferior (zero for none).  */
17305796c8dcSSimon Schubert void
resume(int step,enum gdb_signal sig)1731*ef5ccd6cSJohn Marino resume (int step, enum gdb_signal sig)
17325796c8dcSSimon Schubert {
17335796c8dcSSimon Schubert   int should_resume = 1;
17345796c8dcSSimon Schubert   struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0);
17355796c8dcSSimon Schubert   struct regcache *regcache = get_current_regcache ();
17365796c8dcSSimon Schubert   struct gdbarch *gdbarch = get_regcache_arch (regcache);
17375796c8dcSSimon Schubert   struct thread_info *tp = inferior_thread ();
17385796c8dcSSimon Schubert   CORE_ADDR pc = regcache_read_pc (regcache);
1739cf7f2e2dSJohn Marino   struct address_space *aspace = get_regcache_aspace (regcache);
17405796c8dcSSimon Schubert 
17415796c8dcSSimon Schubert   QUIT;
17425796c8dcSSimon Schubert 
1743c50c785cSJohn Marino   if (current_inferior ()->waiting_for_vfork_done)
1744c50c785cSJohn Marino     {
1745c50c785cSJohn Marino       /* Don't try to single-step a vfork parent that is waiting for
1746c50c785cSJohn Marino 	 the child to get out of the shared memory region (by exec'ing
1747c50c785cSJohn Marino 	 or exiting).  This is particularly important on software
1748c50c785cSJohn Marino 	 single-step archs, as the child process would trip on the
1749c50c785cSJohn Marino 	 software single step breakpoint inserted for the parent
1750c50c785cSJohn Marino 	 process.  Since the parent will not actually execute any
1751c50c785cSJohn Marino 	 instruction until the child is out of the shared region (such
1752c50c785cSJohn Marino 	 are vfork's semantics), it is safe to simply continue it.
1753c50c785cSJohn Marino 	 Eventually, we'll see a TARGET_WAITKIND_VFORK_DONE event for
1754c50c785cSJohn Marino 	 the parent, and tell it to `keep_going', which automatically
1755c50c785cSJohn Marino 	 re-sets it stepping.  */
1756c50c785cSJohn Marino       if (debug_infrun)
1757c50c785cSJohn Marino 	fprintf_unfiltered (gdb_stdlog,
1758c50c785cSJohn Marino 			    "infrun: resume : clear step\n");
1759c50c785cSJohn Marino       step = 0;
1760c50c785cSJohn Marino     }
1761c50c785cSJohn Marino 
17625796c8dcSSimon Schubert   if (debug_infrun)
17635796c8dcSSimon Schubert     fprintf_unfiltered (gdb_stdlog,
17645796c8dcSSimon Schubert                         "infrun: resume (step=%d, signal=%d), "
1765a45ae5f8SJohn Marino 			"trap_expected=%d, current thread [%s] at %s\n",
1766a45ae5f8SJohn Marino  			step, sig, tp->control.trap_expected,
1767a45ae5f8SJohn Marino 			target_pid_to_str (inferior_ptid),
1768a45ae5f8SJohn Marino 			paddress (gdbarch, pc));
17695796c8dcSSimon Schubert 
17705796c8dcSSimon Schubert   /* Normally, by the time we reach `resume', the breakpoints are either
17715796c8dcSSimon Schubert      removed or inserted, as appropriate.  The exception is if we're sitting
17725796c8dcSSimon Schubert      at a permanent breakpoint; we need to step over it, but permanent
17735796c8dcSSimon Schubert      breakpoints can't be removed.  So we have to test for it here.  */
1774cf7f2e2dSJohn Marino   if (breakpoint_here_p (aspace, pc) == permanent_breakpoint_here)
17755796c8dcSSimon Schubert     {
17765796c8dcSSimon Schubert       if (gdbarch_skip_permanent_breakpoint_p (gdbarch))
17775796c8dcSSimon Schubert 	gdbarch_skip_permanent_breakpoint (gdbarch, regcache);
17785796c8dcSSimon Schubert       else
17795796c8dcSSimon Schubert 	error (_("\
17805796c8dcSSimon Schubert The program is stopped at a permanent breakpoint, but GDB does not know\n\
17815796c8dcSSimon Schubert how to step past a permanent breakpoint on this architecture.  Try using\n\
17825796c8dcSSimon Schubert a command like `return' or `jump' to continue execution."));
17835796c8dcSSimon Schubert     }
17845796c8dcSSimon Schubert 
17855796c8dcSSimon Schubert   /* If enabled, step over breakpoints by executing a copy of the
17865796c8dcSSimon Schubert      instruction at a different address.
17875796c8dcSSimon Schubert 
17885796c8dcSSimon Schubert      We can't use displaced stepping when we have a signal to deliver;
17895796c8dcSSimon Schubert      the comments for displaced_step_prepare explain why.  The
17905796c8dcSSimon Schubert      comments in the handle_inferior event for dealing with 'random
1791c50c785cSJohn Marino      signals' explain what we do instead.
1792c50c785cSJohn Marino 
1793c50c785cSJohn Marino      We can't use displaced stepping when we are waiting for vfork_done
1794c50c785cSJohn Marino      event, displaced stepping breaks the vfork child similarly as single
1795c50c785cSJohn Marino      step software breakpoint.  */
17965796c8dcSSimon Schubert   if (use_displaced_stepping (gdbarch)
1797c50c785cSJohn Marino       && (tp->control.trap_expected
17985796c8dcSSimon Schubert 	  || (step && gdbarch_software_single_step_p (gdbarch)))
1799*ef5ccd6cSJohn Marino       && sig == GDB_SIGNAL_0
1800c50c785cSJohn Marino       && !current_inferior ()->waiting_for_vfork_done)
18015796c8dcSSimon Schubert     {
1802cf7f2e2dSJohn Marino       struct displaced_step_inferior_state *displaced;
1803cf7f2e2dSJohn Marino 
18045796c8dcSSimon Schubert       if (!displaced_step_prepare (inferior_ptid))
18055796c8dcSSimon Schubert 	{
18065796c8dcSSimon Schubert 	  /* Got placed in displaced stepping queue.  Will be resumed
18075796c8dcSSimon Schubert 	     later when all the currently queued displaced stepping
18085796c8dcSSimon Schubert 	     requests finish.  The thread is not executing at this point,
18095796c8dcSSimon Schubert 	     and the call to set_executing will be made later.  But we
18105796c8dcSSimon Schubert 	     need to call set_running here, since from frontend point of view,
18115796c8dcSSimon Schubert 	     the thread is running.  */
18125796c8dcSSimon Schubert 	  set_running (inferior_ptid, 1);
18135796c8dcSSimon Schubert 	  discard_cleanups (old_cleanups);
18145796c8dcSSimon Schubert 	  return;
18155796c8dcSSimon Schubert 	}
18165796c8dcSSimon Schubert 
1817*ef5ccd6cSJohn Marino       /* Update pc to reflect the new address from which we will execute
1818*ef5ccd6cSJohn Marino 	 instructions due to displaced stepping.  */
1819*ef5ccd6cSJohn Marino       pc = regcache_read_pc (get_thread_regcache (inferior_ptid));
1820*ef5ccd6cSJohn Marino 
1821cf7f2e2dSJohn Marino       displaced = get_displaced_stepping_state (ptid_get_pid (inferior_ptid));
1822cf7f2e2dSJohn Marino       step = gdbarch_displaced_step_hw_singlestep (gdbarch,
1823cf7f2e2dSJohn Marino 						   displaced->step_closure);
18245796c8dcSSimon Schubert     }
18255796c8dcSSimon Schubert 
18265796c8dcSSimon Schubert   /* Do we need to do it the hard way, w/temp breakpoints?  */
18275796c8dcSSimon Schubert   else if (step)
18285796c8dcSSimon Schubert     step = maybe_software_singlestep (gdbarch, pc);
18295796c8dcSSimon Schubert 
1830a45ae5f8SJohn Marino   /* Currently, our software single-step implementation leads to different
1831a45ae5f8SJohn Marino      results than hardware single-stepping in one situation: when stepping
1832a45ae5f8SJohn Marino      into delivering a signal which has an associated signal handler,
1833a45ae5f8SJohn Marino      hardware single-step will stop at the first instruction of the handler,
1834a45ae5f8SJohn Marino      while software single-step will simply skip execution of the handler.
1835a45ae5f8SJohn Marino 
1836a45ae5f8SJohn Marino      For now, this difference in behavior is accepted since there is no
1837a45ae5f8SJohn Marino      easy way to actually implement single-stepping into a signal handler
1838a45ae5f8SJohn Marino      without kernel support.
1839a45ae5f8SJohn Marino 
1840a45ae5f8SJohn Marino      However, there is one scenario where this difference leads to follow-on
1841a45ae5f8SJohn Marino      problems: if we're stepping off a breakpoint by removing all breakpoints
1842a45ae5f8SJohn Marino      and then single-stepping.  In this case, the software single-step
1843a45ae5f8SJohn Marino      behavior means that even if there is a *breakpoint* in the signal
1844a45ae5f8SJohn Marino      handler, GDB still would not stop.
1845a45ae5f8SJohn Marino 
1846a45ae5f8SJohn Marino      Fortunately, we can at least fix this particular issue.  We detect
1847a45ae5f8SJohn Marino      here the case where we are about to deliver a signal while software
1848a45ae5f8SJohn Marino      single-stepping with breakpoints removed.  In this situation, we
1849a45ae5f8SJohn Marino      revert the decisions to remove all breakpoints and insert single-
1850a45ae5f8SJohn Marino      step breakpoints, and instead we install a step-resume breakpoint
1851a45ae5f8SJohn Marino      at the current address, deliver the signal without stepping, and
1852a45ae5f8SJohn Marino      once we arrive back at the step-resume breakpoint, actually step
1853a45ae5f8SJohn Marino      over the breakpoint we originally wanted to step over.  */
1854a45ae5f8SJohn Marino   if (singlestep_breakpoints_inserted_p
1855*ef5ccd6cSJohn Marino       && tp->control.trap_expected && sig != GDB_SIGNAL_0)
1856a45ae5f8SJohn Marino     {
1857a45ae5f8SJohn Marino       /* If we have nested signals or a pending signal is delivered
1858a45ae5f8SJohn Marino 	 immediately after a handler returns, might might already have
1859a45ae5f8SJohn Marino 	 a step-resume breakpoint set on the earlier handler.  We cannot
1860a45ae5f8SJohn Marino 	 set another step-resume breakpoint; just continue on until the
1861a45ae5f8SJohn Marino 	 original breakpoint is hit.  */
1862a45ae5f8SJohn Marino       if (tp->control.step_resume_breakpoint == NULL)
1863a45ae5f8SJohn Marino 	{
1864a45ae5f8SJohn Marino 	  insert_hp_step_resume_breakpoint_at_frame (get_current_frame ());
1865a45ae5f8SJohn Marino 	  tp->step_after_step_resume_breakpoint = 1;
1866a45ae5f8SJohn Marino 	}
1867a45ae5f8SJohn Marino 
1868a45ae5f8SJohn Marino       remove_single_step_breakpoints ();
1869a45ae5f8SJohn Marino       singlestep_breakpoints_inserted_p = 0;
1870a45ae5f8SJohn Marino 
1871a45ae5f8SJohn Marino       insert_breakpoints ();
1872a45ae5f8SJohn Marino       tp->control.trap_expected = 0;
1873a45ae5f8SJohn Marino     }
1874a45ae5f8SJohn Marino 
18755796c8dcSSimon Schubert   if (should_resume)
18765796c8dcSSimon Schubert     {
18775796c8dcSSimon Schubert       ptid_t resume_ptid;
18785796c8dcSSimon Schubert 
18795796c8dcSSimon Schubert       /* If STEP is set, it's a request to use hardware stepping
18805796c8dcSSimon Schubert 	 facilities.  But in that case, we should never
18815796c8dcSSimon Schubert 	 use singlestep breakpoint.  */
18825796c8dcSSimon Schubert       gdb_assert (!(singlestep_breakpoints_inserted_p && step));
18835796c8dcSSimon Schubert 
18845796c8dcSSimon Schubert       /* Decide the set of threads to ask the target to resume.  Start
18855796c8dcSSimon Schubert 	 by assuming everything will be resumed, than narrow the set
18865796c8dcSSimon Schubert 	 by applying increasingly restricting conditions.  */
1887a45ae5f8SJohn Marino       resume_ptid = user_visible_resume_ptid (step);
18885796c8dcSSimon Schubert 
18895796c8dcSSimon Schubert       /* Maybe resume a single thread after all.  */
18905796c8dcSSimon Schubert       if (singlestep_breakpoints_inserted_p
18915796c8dcSSimon Schubert 	  && stepping_past_singlestep_breakpoint)
18925796c8dcSSimon Schubert 	{
18935796c8dcSSimon Schubert 	  /* The situation here is as follows.  In thread T1 we wanted to
18945796c8dcSSimon Schubert 	     single-step.  Lacking hardware single-stepping we've
18955796c8dcSSimon Schubert 	     set breakpoint at the PC of the next instruction -- call it
18965796c8dcSSimon Schubert 	     P.  After resuming, we've hit that breakpoint in thread T2.
18975796c8dcSSimon Schubert 	     Now we've removed original breakpoint, inserted breakpoint
18985796c8dcSSimon Schubert 	     at P+1, and try to step to advance T2 past breakpoint.
18995796c8dcSSimon Schubert 	     We need to step only T2, as if T1 is allowed to freely run,
19005796c8dcSSimon Schubert 	     it can run past P, and if other threads are allowed to run,
19015796c8dcSSimon Schubert 	     they can hit breakpoint at P+1, and nested hits of single-step
19025796c8dcSSimon Schubert 	     breakpoints is not something we'd want -- that's complicated
19035796c8dcSSimon Schubert 	     to support, and has no value.  */
19045796c8dcSSimon Schubert 	  resume_ptid = inferior_ptid;
19055796c8dcSSimon Schubert 	}
19065796c8dcSSimon Schubert       else if ((step || singlestep_breakpoints_inserted_p)
1907c50c785cSJohn Marino 	       && tp->control.trap_expected)
19085796c8dcSSimon Schubert 	{
19095796c8dcSSimon Schubert 	  /* We're allowing a thread to run past a breakpoint it has
19105796c8dcSSimon Schubert 	     hit, by single-stepping the thread with the breakpoint
19115796c8dcSSimon Schubert 	     removed.  In which case, we need to single-step only this
19125796c8dcSSimon Schubert 	     thread, and keep others stopped, as they can miss this
19135796c8dcSSimon Schubert 	     breakpoint if allowed to run.
19145796c8dcSSimon Schubert 
19155796c8dcSSimon Schubert 	     The current code actually removes all breakpoints when
19165796c8dcSSimon Schubert 	     doing this, not just the one being stepped over, so if we
19175796c8dcSSimon Schubert 	     let other threads run, we can actually miss any
19185796c8dcSSimon Schubert 	     breakpoint, not just the one at PC.  */
19195796c8dcSSimon Schubert 	  resume_ptid = inferior_ptid;
19205796c8dcSSimon Schubert 	}
19215796c8dcSSimon Schubert 
19225796c8dcSSimon Schubert       if (gdbarch_cannot_step_breakpoint (gdbarch))
19235796c8dcSSimon Schubert 	{
19245796c8dcSSimon Schubert 	  /* Most targets can step a breakpoint instruction, thus
19255796c8dcSSimon Schubert 	     executing it normally.  But if this one cannot, just
19265796c8dcSSimon Schubert 	     continue and we will hit it anyway.  */
1927cf7f2e2dSJohn Marino 	  if (step && breakpoint_inserted_here_p (aspace, pc))
19285796c8dcSSimon Schubert 	    step = 0;
19295796c8dcSSimon Schubert 	}
19305796c8dcSSimon Schubert 
19315796c8dcSSimon Schubert       if (debug_displaced
19325796c8dcSSimon Schubert           && use_displaced_stepping (gdbarch)
1933c50c785cSJohn Marino           && tp->control.trap_expected)
19345796c8dcSSimon Schubert         {
19355796c8dcSSimon Schubert 	  struct regcache *resume_regcache = get_thread_regcache (resume_ptid);
19365796c8dcSSimon Schubert 	  struct gdbarch *resume_gdbarch = get_regcache_arch (resume_regcache);
19375796c8dcSSimon Schubert           CORE_ADDR actual_pc = regcache_read_pc (resume_regcache);
19385796c8dcSSimon Schubert           gdb_byte buf[4];
19395796c8dcSSimon Schubert 
19405796c8dcSSimon Schubert           fprintf_unfiltered (gdb_stdlog, "displaced: run %s: ",
19415796c8dcSSimon Schubert                               paddress (resume_gdbarch, actual_pc));
19425796c8dcSSimon Schubert           read_memory (actual_pc, buf, sizeof (buf));
19435796c8dcSSimon Schubert           displaced_step_dump_bytes (gdb_stdlog, buf, sizeof (buf));
19445796c8dcSSimon Schubert         }
19455796c8dcSSimon Schubert 
19465796c8dcSSimon Schubert       /* Install inferior's terminal modes.  */
19475796c8dcSSimon Schubert       target_terminal_inferior ();
19485796c8dcSSimon Schubert 
19495796c8dcSSimon Schubert       /* Avoid confusing the next resume, if the next stop/resume
19505796c8dcSSimon Schubert 	 happens to apply to another thread.  */
1951*ef5ccd6cSJohn Marino       tp->suspend.stop_signal = GDB_SIGNAL_0;
19525796c8dcSSimon Schubert 
1953a45ae5f8SJohn Marino       /* Advise target which signals may be handled silently.  If we have
1954a45ae5f8SJohn Marino 	 removed breakpoints because we are stepping over one (which can
1955a45ae5f8SJohn Marino 	 happen only if we are not using displaced stepping), we need to
1956a45ae5f8SJohn Marino 	 receive all signals to avoid accidentally skipping a breakpoint
1957a45ae5f8SJohn Marino 	 during execution of a signal handler.  */
1958a45ae5f8SJohn Marino       if ((step || singlestep_breakpoints_inserted_p)
1959a45ae5f8SJohn Marino 	  && tp->control.trap_expected
1960a45ae5f8SJohn Marino 	  && !use_displaced_stepping (gdbarch))
1961a45ae5f8SJohn Marino 	target_pass_signals (0, NULL);
1962a45ae5f8SJohn Marino       else
1963*ef5ccd6cSJohn Marino 	target_pass_signals ((int) GDB_SIGNAL_LAST, signal_pass);
1964a45ae5f8SJohn Marino 
19655796c8dcSSimon Schubert       target_resume (resume_ptid, step, sig);
19665796c8dcSSimon Schubert     }
19675796c8dcSSimon Schubert 
19685796c8dcSSimon Schubert   discard_cleanups (old_cleanups);
19695796c8dcSSimon Schubert }
19705796c8dcSSimon Schubert 
19715796c8dcSSimon Schubert /* Proceeding.  */
19725796c8dcSSimon Schubert 
19735796c8dcSSimon Schubert /* Clear out all variables saying what to do when inferior is continued.
19745796c8dcSSimon Schubert    First do this, then set the ones you want, then call `proceed'.  */
19755796c8dcSSimon Schubert 
19765796c8dcSSimon Schubert static void
clear_proceed_status_thread(struct thread_info * tp)19775796c8dcSSimon Schubert clear_proceed_status_thread (struct thread_info *tp)
19785796c8dcSSimon Schubert {
19795796c8dcSSimon Schubert   if (debug_infrun)
19805796c8dcSSimon Schubert     fprintf_unfiltered (gdb_stdlog,
19815796c8dcSSimon Schubert 			"infrun: clear_proceed_status_thread (%s)\n",
19825796c8dcSSimon Schubert 			target_pid_to_str (tp->ptid));
19835796c8dcSSimon Schubert 
1984c50c785cSJohn Marino   tp->control.trap_expected = 0;
1985c50c785cSJohn Marino   tp->control.step_range_start = 0;
1986c50c785cSJohn Marino   tp->control.step_range_end = 0;
1987c50c785cSJohn Marino   tp->control.step_frame_id = null_frame_id;
1988c50c785cSJohn Marino   tp->control.step_stack_frame_id = null_frame_id;
1989c50c785cSJohn Marino   tp->control.step_over_calls = STEP_OVER_UNDEBUGGABLE;
19905796c8dcSSimon Schubert   tp->stop_requested = 0;
19915796c8dcSSimon Schubert 
1992c50c785cSJohn Marino   tp->control.stop_step = 0;
19935796c8dcSSimon Schubert 
1994c50c785cSJohn Marino   tp->control.proceed_to_finish = 0;
19955796c8dcSSimon Schubert 
19965796c8dcSSimon Schubert   /* Discard any remaining commands or status from previous stop.  */
1997c50c785cSJohn Marino   bpstat_clear (&tp->control.stop_bpstat);
19985796c8dcSSimon Schubert }
19995796c8dcSSimon Schubert 
20005796c8dcSSimon Schubert static int
clear_proceed_status_callback(struct thread_info * tp,void * data)20015796c8dcSSimon Schubert clear_proceed_status_callback (struct thread_info *tp, void *data)
20025796c8dcSSimon Schubert {
20035796c8dcSSimon Schubert   if (is_exited (tp->ptid))
20045796c8dcSSimon Schubert     return 0;
20055796c8dcSSimon Schubert 
20065796c8dcSSimon Schubert   clear_proceed_status_thread (tp);
20075796c8dcSSimon Schubert   return 0;
20085796c8dcSSimon Schubert }
20095796c8dcSSimon Schubert 
20105796c8dcSSimon Schubert void
clear_proceed_status(void)20115796c8dcSSimon Schubert clear_proceed_status (void)
20125796c8dcSSimon Schubert {
2013cf7f2e2dSJohn Marino   if (!non_stop)
2014cf7f2e2dSJohn Marino     {
2015cf7f2e2dSJohn Marino       /* In all-stop mode, delete the per-thread status of all
2016cf7f2e2dSJohn Marino 	 threads, even if inferior_ptid is null_ptid, there may be
2017cf7f2e2dSJohn Marino 	 threads on the list.  E.g., we may be launching a new
2018cf7f2e2dSJohn Marino 	 process, while selecting the executable.  */
2019cf7f2e2dSJohn Marino       iterate_over_threads (clear_proceed_status_callback, NULL);
2020cf7f2e2dSJohn Marino     }
2021cf7f2e2dSJohn Marino 
20225796c8dcSSimon Schubert   if (!ptid_equal (inferior_ptid, null_ptid))
20235796c8dcSSimon Schubert     {
20245796c8dcSSimon Schubert       struct inferior *inferior;
20255796c8dcSSimon Schubert 
20265796c8dcSSimon Schubert       if (non_stop)
20275796c8dcSSimon Schubert 	{
2028cf7f2e2dSJohn Marino 	  /* If in non-stop mode, only delete the per-thread status of
2029cf7f2e2dSJohn Marino 	     the current thread.  */
20305796c8dcSSimon Schubert 	  clear_proceed_status_thread (inferior_thread ());
20315796c8dcSSimon Schubert 	}
20325796c8dcSSimon Schubert 
20335796c8dcSSimon Schubert       inferior = current_inferior ();
2034c50c785cSJohn Marino       inferior->control.stop_soon = NO_STOP_QUIETLY;
20355796c8dcSSimon Schubert     }
20365796c8dcSSimon Schubert 
20375796c8dcSSimon Schubert   stop_after_trap = 0;
20385796c8dcSSimon Schubert 
20395796c8dcSSimon Schubert   observer_notify_about_to_proceed ();
20405796c8dcSSimon Schubert 
20415796c8dcSSimon Schubert   if (stop_registers)
20425796c8dcSSimon Schubert     {
20435796c8dcSSimon Schubert       regcache_xfree (stop_registers);
20445796c8dcSSimon Schubert       stop_registers = NULL;
20455796c8dcSSimon Schubert     }
20465796c8dcSSimon Schubert }
20475796c8dcSSimon Schubert 
20485796c8dcSSimon Schubert /* Check the current thread against the thread that reported the most recent
20495796c8dcSSimon Schubert    event.  If a step-over is required return TRUE and set the current thread
20505796c8dcSSimon Schubert    to the old thread.  Otherwise return FALSE.
20515796c8dcSSimon Schubert 
20525796c8dcSSimon Schubert    This should be suitable for any targets that support threads.  */
20535796c8dcSSimon Schubert 
20545796c8dcSSimon Schubert static int
prepare_to_proceed(int step)20555796c8dcSSimon Schubert prepare_to_proceed (int step)
20565796c8dcSSimon Schubert {
20575796c8dcSSimon Schubert   ptid_t wait_ptid;
20585796c8dcSSimon Schubert   struct target_waitstatus wait_status;
20595796c8dcSSimon Schubert   int schedlock_enabled;
20605796c8dcSSimon Schubert 
20615796c8dcSSimon Schubert   /* With non-stop mode on, threads are always handled individually.  */
20625796c8dcSSimon Schubert   gdb_assert (! non_stop);
20635796c8dcSSimon Schubert 
20645796c8dcSSimon Schubert   /* Get the last target status returned by target_wait().  */
20655796c8dcSSimon Schubert   get_last_target_status (&wait_ptid, &wait_status);
20665796c8dcSSimon Schubert 
20675796c8dcSSimon Schubert   /* Make sure we were stopped at a breakpoint.  */
20685796c8dcSSimon Schubert   if (wait_status.kind != TARGET_WAITKIND_STOPPED
2069*ef5ccd6cSJohn Marino       || (wait_status.value.sig != GDB_SIGNAL_TRAP
2070*ef5ccd6cSJohn Marino 	  && wait_status.value.sig != GDB_SIGNAL_ILL
2071*ef5ccd6cSJohn Marino 	  && wait_status.value.sig != GDB_SIGNAL_SEGV
2072*ef5ccd6cSJohn Marino 	  && wait_status.value.sig != GDB_SIGNAL_EMT))
20735796c8dcSSimon Schubert     {
20745796c8dcSSimon Schubert       return 0;
20755796c8dcSSimon Schubert     }
20765796c8dcSSimon Schubert 
20775796c8dcSSimon Schubert   schedlock_enabled = (scheduler_mode == schedlock_on
20785796c8dcSSimon Schubert 		       || (scheduler_mode == schedlock_step
20795796c8dcSSimon Schubert 			   && step));
20805796c8dcSSimon Schubert 
20815796c8dcSSimon Schubert   /* Don't switch over to WAIT_PTID if scheduler locking is on.  */
20825796c8dcSSimon Schubert   if (schedlock_enabled)
20835796c8dcSSimon Schubert     return 0;
20845796c8dcSSimon Schubert 
20855796c8dcSSimon Schubert   /* Don't switch over if we're about to resume some other process
20865796c8dcSSimon Schubert      other than WAIT_PTID's, and schedule-multiple is off.  */
20875796c8dcSSimon Schubert   if (!sched_multi
20885796c8dcSSimon Schubert       && ptid_get_pid (wait_ptid) != ptid_get_pid (inferior_ptid))
20895796c8dcSSimon Schubert     return 0;
20905796c8dcSSimon Schubert 
20915796c8dcSSimon Schubert   /* Switched over from WAIT_PID.  */
20925796c8dcSSimon Schubert   if (!ptid_equal (wait_ptid, minus_one_ptid)
20935796c8dcSSimon Schubert       && !ptid_equal (inferior_ptid, wait_ptid))
20945796c8dcSSimon Schubert     {
20955796c8dcSSimon Schubert       struct regcache *regcache = get_thread_regcache (wait_ptid);
20965796c8dcSSimon Schubert 
2097cf7f2e2dSJohn Marino       if (breakpoint_here_p (get_regcache_aspace (regcache),
2098cf7f2e2dSJohn Marino 			     regcache_read_pc (regcache)))
20995796c8dcSSimon Schubert 	{
21005796c8dcSSimon Schubert 	  /* If stepping, remember current thread to switch back to.  */
21015796c8dcSSimon Schubert 	  if (step)
21025796c8dcSSimon Schubert 	    deferred_step_ptid = inferior_ptid;
21035796c8dcSSimon Schubert 
21045796c8dcSSimon Schubert 	  /* Switch back to WAIT_PID thread.  */
21055796c8dcSSimon Schubert 	  switch_to_thread (wait_ptid);
21065796c8dcSSimon Schubert 
2107a45ae5f8SJohn Marino 	  if (debug_infrun)
2108a45ae5f8SJohn Marino 	    fprintf_unfiltered (gdb_stdlog,
2109a45ae5f8SJohn Marino 				"infrun: prepare_to_proceed (step=%d), "
2110a45ae5f8SJohn Marino 				"switched to [%s]\n",
2111a45ae5f8SJohn Marino 				step, target_pid_to_str (inferior_ptid));
2112a45ae5f8SJohn Marino 
21135796c8dcSSimon Schubert 	  /* We return 1 to indicate that there is a breakpoint here,
21145796c8dcSSimon Schubert 	     so we need to step over it before continuing to avoid
21155796c8dcSSimon Schubert 	     hitting it straight away.  */
21165796c8dcSSimon Schubert 	  return 1;
21175796c8dcSSimon Schubert 	}
21185796c8dcSSimon Schubert     }
21195796c8dcSSimon Schubert 
21205796c8dcSSimon Schubert   return 0;
21215796c8dcSSimon Schubert }
21225796c8dcSSimon Schubert 
21235796c8dcSSimon Schubert /* Basic routine for continuing the program in various fashions.
21245796c8dcSSimon Schubert 
21255796c8dcSSimon Schubert    ADDR is the address to resume at, or -1 for resume where stopped.
21265796c8dcSSimon Schubert    SIGGNAL is the signal to give it, or 0 for none,
21275796c8dcSSimon Schubert    or -1 for act according to how it stopped.
21285796c8dcSSimon Schubert    STEP is nonzero if should trap after one instruction.
21295796c8dcSSimon Schubert    -1 means return after that and print nothing.
21305796c8dcSSimon Schubert    You should probably set various step_... variables
21315796c8dcSSimon Schubert    before calling here, if you are stepping.
21325796c8dcSSimon Schubert 
21335796c8dcSSimon Schubert    You should call clear_proceed_status before calling proceed.  */
21345796c8dcSSimon Schubert 
21355796c8dcSSimon Schubert void
proceed(CORE_ADDR addr,enum gdb_signal siggnal,int step)2136*ef5ccd6cSJohn Marino proceed (CORE_ADDR addr, enum gdb_signal siggnal, int step)
21375796c8dcSSimon Schubert {
21385796c8dcSSimon Schubert   struct regcache *regcache;
21395796c8dcSSimon Schubert   struct gdbarch *gdbarch;
21405796c8dcSSimon Schubert   struct thread_info *tp;
21415796c8dcSSimon Schubert   CORE_ADDR pc;
2142cf7f2e2dSJohn Marino   struct address_space *aspace;
2143*ef5ccd6cSJohn Marino   /* GDB may force the inferior to step due to various reasons.  */
2144*ef5ccd6cSJohn Marino   int force_step = 0;
21455796c8dcSSimon Schubert 
21465796c8dcSSimon Schubert   /* If we're stopped at a fork/vfork, follow the branch set by the
21475796c8dcSSimon Schubert      "set follow-fork-mode" command; otherwise, we'll just proceed
21485796c8dcSSimon Schubert      resuming the current thread.  */
21495796c8dcSSimon Schubert   if (!follow_fork ())
21505796c8dcSSimon Schubert     {
21515796c8dcSSimon Schubert       /* The target for some reason decided not to resume.  */
21525796c8dcSSimon Schubert       normal_stop ();
2153a45ae5f8SJohn Marino       if (target_can_async_p ())
2154a45ae5f8SJohn Marino 	inferior_event_handler (INF_EXEC_COMPLETE, NULL);
21555796c8dcSSimon Schubert       return;
21565796c8dcSSimon Schubert     }
21575796c8dcSSimon Schubert 
2158a45ae5f8SJohn Marino   /* We'll update this if & when we switch to a new thread.  */
2159a45ae5f8SJohn Marino   previous_inferior_ptid = inferior_ptid;
2160a45ae5f8SJohn Marino 
21615796c8dcSSimon Schubert   regcache = get_current_regcache ();
21625796c8dcSSimon Schubert   gdbarch = get_regcache_arch (regcache);
2163cf7f2e2dSJohn Marino   aspace = get_regcache_aspace (regcache);
21645796c8dcSSimon Schubert   pc = regcache_read_pc (regcache);
21655796c8dcSSimon Schubert 
21665796c8dcSSimon Schubert   if (step > 0)
21675796c8dcSSimon Schubert     step_start_function = find_pc_function (pc);
21685796c8dcSSimon Schubert   if (step < 0)
21695796c8dcSSimon Schubert     stop_after_trap = 1;
21705796c8dcSSimon Schubert 
21715796c8dcSSimon Schubert   if (addr == (CORE_ADDR) -1)
21725796c8dcSSimon Schubert     {
2173cf7f2e2dSJohn Marino       if (pc == stop_pc && breakpoint_here_p (aspace, pc)
21745796c8dcSSimon Schubert 	  && execution_direction != EXEC_REVERSE)
21755796c8dcSSimon Schubert 	/* There is a breakpoint at the address we will resume at,
21765796c8dcSSimon Schubert 	   step one instruction before inserting breakpoints so that
21775796c8dcSSimon Schubert 	   we do not stop right away (and report a second hit at this
21785796c8dcSSimon Schubert 	   breakpoint).
21795796c8dcSSimon Schubert 
21805796c8dcSSimon Schubert 	   Note, we don't do this in reverse, because we won't
21815796c8dcSSimon Schubert 	   actually be executing the breakpoint insn anyway.
21825796c8dcSSimon Schubert 	   We'll be (un-)executing the previous instruction.  */
21835796c8dcSSimon Schubert 
2184*ef5ccd6cSJohn Marino 	force_step = 1;
21855796c8dcSSimon Schubert       else if (gdbarch_single_step_through_delay_p (gdbarch)
21865796c8dcSSimon Schubert 	       && gdbarch_single_step_through_delay (gdbarch,
21875796c8dcSSimon Schubert 						     get_current_frame ()))
21885796c8dcSSimon Schubert 	/* We stepped onto an instruction that needs to be stepped
21895796c8dcSSimon Schubert 	   again before re-inserting the breakpoint, do so.  */
2190*ef5ccd6cSJohn Marino 	force_step = 1;
21915796c8dcSSimon Schubert     }
21925796c8dcSSimon Schubert   else
21935796c8dcSSimon Schubert     {
21945796c8dcSSimon Schubert       regcache_write_pc (regcache, addr);
21955796c8dcSSimon Schubert     }
21965796c8dcSSimon Schubert 
21975796c8dcSSimon Schubert   if (debug_infrun)
21985796c8dcSSimon Schubert     fprintf_unfiltered (gdb_stdlog,
21995796c8dcSSimon Schubert 			"infrun: proceed (addr=%s, signal=%d, step=%d)\n",
22005796c8dcSSimon Schubert 			paddress (gdbarch, addr), siggnal, step);
22015796c8dcSSimon Schubert 
22025796c8dcSSimon Schubert   if (non_stop)
22035796c8dcSSimon Schubert     /* In non-stop, each thread is handled individually.  The context
22045796c8dcSSimon Schubert        must already be set to the right thread here.  */
22055796c8dcSSimon Schubert     ;
22065796c8dcSSimon Schubert   else
22075796c8dcSSimon Schubert     {
22085796c8dcSSimon Schubert       /* In a multi-threaded task we may select another thread and
22095796c8dcSSimon Schubert 	 then continue or step.
22105796c8dcSSimon Schubert 
22115796c8dcSSimon Schubert 	 But if the old thread was stopped at a breakpoint, it will
22125796c8dcSSimon Schubert 	 immediately cause another breakpoint stop without any
22135796c8dcSSimon Schubert 	 execution (i.e. it will report a breakpoint hit incorrectly).
22145796c8dcSSimon Schubert 	 So we must step over it first.
22155796c8dcSSimon Schubert 
22165796c8dcSSimon Schubert 	 prepare_to_proceed checks the current thread against the
22175796c8dcSSimon Schubert 	 thread that reported the most recent event.  If a step-over
22185796c8dcSSimon Schubert 	 is required it returns TRUE and sets the current thread to
22195796c8dcSSimon Schubert 	 the old thread.  */
22205796c8dcSSimon Schubert       if (prepare_to_proceed (step))
2221*ef5ccd6cSJohn Marino 	force_step = 1;
22225796c8dcSSimon Schubert     }
22235796c8dcSSimon Schubert 
22245796c8dcSSimon Schubert   /* prepare_to_proceed may change the current thread.  */
22255796c8dcSSimon Schubert   tp = inferior_thread ();
22265796c8dcSSimon Schubert 
2227*ef5ccd6cSJohn Marino   if (force_step)
22285796c8dcSSimon Schubert     {
2229c50c785cSJohn Marino       tp->control.trap_expected = 1;
22305796c8dcSSimon Schubert       /* If displaced stepping is enabled, we can step over the
22315796c8dcSSimon Schubert 	 breakpoint without hitting it, so leave all breakpoints
22325796c8dcSSimon Schubert 	 inserted.  Otherwise we need to disable all breakpoints, step
22335796c8dcSSimon Schubert 	 one instruction, and then re-add them when that step is
22345796c8dcSSimon Schubert 	 finished.  */
22355796c8dcSSimon Schubert       if (!use_displaced_stepping (gdbarch))
22365796c8dcSSimon Schubert 	remove_breakpoints ();
22375796c8dcSSimon Schubert     }
22385796c8dcSSimon Schubert 
22395796c8dcSSimon Schubert   /* We can insert breakpoints if we're not trying to step over one,
22405796c8dcSSimon Schubert      or if we are stepping over one but we're using displaced stepping
22415796c8dcSSimon Schubert      to do so.  */
2242c50c785cSJohn Marino   if (! tp->control.trap_expected || use_displaced_stepping (gdbarch))
22435796c8dcSSimon Schubert     insert_breakpoints ();
22445796c8dcSSimon Schubert 
22455796c8dcSSimon Schubert   if (!non_stop)
22465796c8dcSSimon Schubert     {
22475796c8dcSSimon Schubert       /* Pass the last stop signal to the thread we're resuming,
22485796c8dcSSimon Schubert 	 irrespective of whether the current thread is the thread that
22495796c8dcSSimon Schubert 	 got the last event or not.  This was historically GDB's
22505796c8dcSSimon Schubert 	 behaviour before keeping a stop_signal per thread.  */
22515796c8dcSSimon Schubert 
22525796c8dcSSimon Schubert       struct thread_info *last_thread;
22535796c8dcSSimon Schubert       ptid_t last_ptid;
22545796c8dcSSimon Schubert       struct target_waitstatus last_status;
22555796c8dcSSimon Schubert 
22565796c8dcSSimon Schubert       get_last_target_status (&last_ptid, &last_status);
22575796c8dcSSimon Schubert       if (!ptid_equal (inferior_ptid, last_ptid)
22585796c8dcSSimon Schubert 	  && !ptid_equal (last_ptid, null_ptid)
22595796c8dcSSimon Schubert 	  && !ptid_equal (last_ptid, minus_one_ptid))
22605796c8dcSSimon Schubert 	{
22615796c8dcSSimon Schubert 	  last_thread = find_thread_ptid (last_ptid);
22625796c8dcSSimon Schubert 	  if (last_thread)
22635796c8dcSSimon Schubert 	    {
2264c50c785cSJohn Marino 	      tp->suspend.stop_signal = last_thread->suspend.stop_signal;
2265*ef5ccd6cSJohn Marino 	      last_thread->suspend.stop_signal = GDB_SIGNAL_0;
22665796c8dcSSimon Schubert 	    }
22675796c8dcSSimon Schubert 	}
22685796c8dcSSimon Schubert     }
22695796c8dcSSimon Schubert 
2270*ef5ccd6cSJohn Marino   if (siggnal != GDB_SIGNAL_DEFAULT)
2271c50c785cSJohn Marino     tp->suspend.stop_signal = siggnal;
22725796c8dcSSimon Schubert   /* If this signal should not be seen by program,
22735796c8dcSSimon Schubert      give it zero.  Used for debugging signals.  */
2274c50c785cSJohn Marino   else if (!signal_program[tp->suspend.stop_signal])
2275*ef5ccd6cSJohn Marino     tp->suspend.stop_signal = GDB_SIGNAL_0;
22765796c8dcSSimon Schubert 
22775796c8dcSSimon Schubert   annotate_starting ();
22785796c8dcSSimon Schubert 
22795796c8dcSSimon Schubert   /* Make sure that output from GDB appears before output from the
22805796c8dcSSimon Schubert      inferior.  */
22815796c8dcSSimon Schubert   gdb_flush (gdb_stdout);
22825796c8dcSSimon Schubert 
22835796c8dcSSimon Schubert   /* Refresh prev_pc value just prior to resuming.  This used to be
22845796c8dcSSimon Schubert      done in stop_stepping, however, setting prev_pc there did not handle
22855796c8dcSSimon Schubert      scenarios such as inferior function calls or returning from
22865796c8dcSSimon Schubert      a function via the return command.  In those cases, the prev_pc
22875796c8dcSSimon Schubert      value was not set properly for subsequent commands.  The prev_pc value
22885796c8dcSSimon Schubert      is used to initialize the starting line number in the ecs.  With an
22895796c8dcSSimon Schubert      invalid value, the gdb next command ends up stopping at the position
22905796c8dcSSimon Schubert      represented by the next line table entry past our start position.
22915796c8dcSSimon Schubert      On platforms that generate one line table entry per line, this
22925796c8dcSSimon Schubert      is not a problem.  However, on the ia64, the compiler generates
22935796c8dcSSimon Schubert      extraneous line table entries that do not increase the line number.
22945796c8dcSSimon Schubert      When we issue the gdb next command on the ia64 after an inferior call
22955796c8dcSSimon Schubert      or a return command, we often end up a few instructions forward, still
22965796c8dcSSimon Schubert      within the original line we started.
22975796c8dcSSimon Schubert 
2298cf7f2e2dSJohn Marino      An attempt was made to refresh the prev_pc at the same time the
2299cf7f2e2dSJohn Marino      execution_control_state is initialized (for instance, just before
2300cf7f2e2dSJohn Marino      waiting for an inferior event).  But this approach did not work
2301cf7f2e2dSJohn Marino      because of platforms that use ptrace, where the pc register cannot
2302cf7f2e2dSJohn Marino      be read unless the inferior is stopped.  At that point, we are not
2303cf7f2e2dSJohn Marino      guaranteed the inferior is stopped and so the regcache_read_pc() call
2304cf7f2e2dSJohn Marino      can fail.  Setting the prev_pc value here ensures the value is updated
2305cf7f2e2dSJohn Marino      correctly when the inferior is stopped.  */
23065796c8dcSSimon Schubert   tp->prev_pc = regcache_read_pc (get_current_regcache ());
23075796c8dcSSimon Schubert 
23085796c8dcSSimon Schubert   /* Fill in with reasonable starting values.  */
23095796c8dcSSimon Schubert   init_thread_stepping_state (tp);
23105796c8dcSSimon Schubert 
23115796c8dcSSimon Schubert   /* Reset to normal state.  */
23125796c8dcSSimon Schubert   init_infwait_state ();
23135796c8dcSSimon Schubert 
23145796c8dcSSimon Schubert   /* Resume inferior.  */
2315*ef5ccd6cSJohn Marino   resume (force_step || step || bpstat_should_step (),
2316*ef5ccd6cSJohn Marino 	  tp->suspend.stop_signal);
23175796c8dcSSimon Schubert 
23185796c8dcSSimon Schubert   /* Wait for it to stop (if not standalone)
23195796c8dcSSimon Schubert      and in any case decode why it stopped, and act accordingly.  */
23205796c8dcSSimon Schubert   /* Do this only if we are not using the event loop, or if the target
23215796c8dcSSimon Schubert      does not support asynchronous execution.  */
23225796c8dcSSimon Schubert   if (!target_can_async_p ())
23235796c8dcSSimon Schubert     {
2324a45ae5f8SJohn Marino       wait_for_inferior ();
23255796c8dcSSimon Schubert       normal_stop ();
23265796c8dcSSimon Schubert     }
23275796c8dcSSimon Schubert }
23285796c8dcSSimon Schubert 
23295796c8dcSSimon Schubert 
23305796c8dcSSimon Schubert /* Start remote-debugging of a machine over a serial link.  */
23315796c8dcSSimon Schubert 
23325796c8dcSSimon Schubert void
start_remote(int from_tty)23335796c8dcSSimon Schubert start_remote (int from_tty)
23345796c8dcSSimon Schubert {
23355796c8dcSSimon Schubert   struct inferior *inferior;
23365796c8dcSSimon Schubert 
23375796c8dcSSimon Schubert   inferior = current_inferior ();
2338c50c785cSJohn Marino   inferior->control.stop_soon = STOP_QUIETLY_REMOTE;
23395796c8dcSSimon Schubert 
23405796c8dcSSimon Schubert   /* Always go on waiting for the target, regardless of the mode.  */
23415796c8dcSSimon Schubert   /* FIXME: cagney/1999-09-23: At present it isn't possible to
23425796c8dcSSimon Schubert      indicate to wait_for_inferior that a target should timeout if
23435796c8dcSSimon Schubert      nothing is returned (instead of just blocking).  Because of this,
23445796c8dcSSimon Schubert      targets expecting an immediate response need to, internally, set
23455796c8dcSSimon Schubert      things up so that the target_wait() is forced to eventually
23465796c8dcSSimon Schubert      timeout.  */
23475796c8dcSSimon Schubert   /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
23485796c8dcSSimon Schubert      differentiate to its caller what the state of the target is after
23495796c8dcSSimon Schubert      the initial open has been performed.  Here we're assuming that
23505796c8dcSSimon Schubert      the target has stopped.  It should be possible to eventually have
23515796c8dcSSimon Schubert      target_open() return to the caller an indication that the target
23525796c8dcSSimon Schubert      is currently running and GDB state should be set to the same as
23535796c8dcSSimon Schubert      for an async run.  */
2354a45ae5f8SJohn Marino   wait_for_inferior ();
23555796c8dcSSimon Schubert 
23565796c8dcSSimon Schubert   /* Now that the inferior has stopped, do any bookkeeping like
23575796c8dcSSimon Schubert      loading shared libraries.  We want to do this before normal_stop,
23585796c8dcSSimon Schubert      so that the displayed frame is up to date.  */
23595796c8dcSSimon Schubert   post_create_inferior (&current_target, from_tty);
23605796c8dcSSimon Schubert 
23615796c8dcSSimon Schubert   normal_stop ();
23625796c8dcSSimon Schubert }
23635796c8dcSSimon Schubert 
23645796c8dcSSimon Schubert /* Initialize static vars when a new inferior begins.  */
23655796c8dcSSimon Schubert 
23665796c8dcSSimon Schubert void
init_wait_for_inferior(void)23675796c8dcSSimon Schubert init_wait_for_inferior (void)
23685796c8dcSSimon Schubert {
23695796c8dcSSimon Schubert   /* These are meaningless until the first time through wait_for_inferior.  */
23705796c8dcSSimon Schubert 
23715796c8dcSSimon Schubert   breakpoint_init_inferior (inf_starting);
23725796c8dcSSimon Schubert 
23735796c8dcSSimon Schubert   clear_proceed_status ();
23745796c8dcSSimon Schubert 
23755796c8dcSSimon Schubert   stepping_past_singlestep_breakpoint = 0;
23765796c8dcSSimon Schubert   deferred_step_ptid = null_ptid;
23775796c8dcSSimon Schubert 
23785796c8dcSSimon Schubert   target_last_wait_ptid = minus_one_ptid;
23795796c8dcSSimon Schubert 
2380a45ae5f8SJohn Marino   previous_inferior_ptid = inferior_ptid;
23815796c8dcSSimon Schubert   init_infwait_state ();
23825796c8dcSSimon Schubert 
23835796c8dcSSimon Schubert   /* Discard any skipped inlined frames.  */
23845796c8dcSSimon Schubert   clear_inline_frame_state (minus_one_ptid);
23855796c8dcSSimon Schubert }
23865796c8dcSSimon Schubert 
23875796c8dcSSimon Schubert 
23885796c8dcSSimon Schubert /* This enum encodes possible reasons for doing a target_wait, so that
23895796c8dcSSimon Schubert    wfi can call target_wait in one place.  (Ultimately the call will be
23905796c8dcSSimon Schubert    moved out of the infinite loop entirely.) */
23915796c8dcSSimon Schubert 
23925796c8dcSSimon Schubert enum infwait_states
23935796c8dcSSimon Schubert {
23945796c8dcSSimon Schubert   infwait_normal_state,
23955796c8dcSSimon Schubert   infwait_thread_hop_state,
23965796c8dcSSimon Schubert   infwait_step_watch_state,
23975796c8dcSSimon Schubert   infwait_nonstep_watch_state
23985796c8dcSSimon Schubert };
23995796c8dcSSimon Schubert 
24005796c8dcSSimon Schubert /* The PTID we'll do a target_wait on.*/
24015796c8dcSSimon Schubert ptid_t waiton_ptid;
24025796c8dcSSimon Schubert 
24035796c8dcSSimon Schubert /* Current inferior wait state.  */
2404*ef5ccd6cSJohn Marino static enum infwait_states infwait_state;
24055796c8dcSSimon Schubert 
24065796c8dcSSimon Schubert /* Data to be passed around while handling an event.  This data is
24075796c8dcSSimon Schubert    discarded between events.  */
24085796c8dcSSimon Schubert struct execution_control_state
24095796c8dcSSimon Schubert {
24105796c8dcSSimon Schubert   ptid_t ptid;
24115796c8dcSSimon Schubert   /* The thread that got the event, if this was a thread event; NULL
24125796c8dcSSimon Schubert      otherwise.  */
24135796c8dcSSimon Schubert   struct thread_info *event_thread;
24145796c8dcSSimon Schubert 
24155796c8dcSSimon Schubert   struct target_waitstatus ws;
24165796c8dcSSimon Schubert   int random_signal;
2417a45ae5f8SJohn Marino   int stop_func_filled_in;
24185796c8dcSSimon Schubert   CORE_ADDR stop_func_start;
24195796c8dcSSimon Schubert   CORE_ADDR stop_func_end;
2420*ef5ccd6cSJohn Marino   const char *stop_func_name;
24215796c8dcSSimon Schubert   int wait_some_more;
24225796c8dcSSimon Schubert };
24235796c8dcSSimon Schubert 
24245796c8dcSSimon Schubert static void handle_inferior_event (struct execution_control_state *ecs);
24255796c8dcSSimon Schubert 
24265796c8dcSSimon Schubert static void handle_step_into_function (struct gdbarch *gdbarch,
24275796c8dcSSimon Schubert 				       struct execution_control_state *ecs);
24285796c8dcSSimon Schubert static void handle_step_into_function_backward (struct gdbarch *gdbarch,
24295796c8dcSSimon Schubert 						struct execution_control_state *ecs);
2430c50c785cSJohn Marino static void check_exception_resume (struct execution_control_state *,
2431*ef5ccd6cSJohn Marino 				    struct frame_info *);
24325796c8dcSSimon Schubert 
24335796c8dcSSimon Schubert static void stop_stepping (struct execution_control_state *ecs);
24345796c8dcSSimon Schubert static void prepare_to_wait (struct execution_control_state *ecs);
24355796c8dcSSimon Schubert static void keep_going (struct execution_control_state *ecs);
24365796c8dcSSimon Schubert 
24375796c8dcSSimon Schubert /* Callback for iterate over threads.  If the thread is stopped, but
24385796c8dcSSimon Schubert    the user/frontend doesn't know about that yet, go through
24395796c8dcSSimon Schubert    normal_stop, as if the thread had just stopped now.  ARG points at
24405796c8dcSSimon Schubert    a ptid.  If PTID is MINUS_ONE_PTID, applies to all threads.  If
24415796c8dcSSimon Schubert    ptid_is_pid(PTID) is true, applies to all threads of the process
24425796c8dcSSimon Schubert    pointed at by PTID.  Otherwise, apply only to the thread pointed by
24435796c8dcSSimon Schubert    PTID.  */
24445796c8dcSSimon Schubert 
24455796c8dcSSimon Schubert static int
infrun_thread_stop_requested_callback(struct thread_info * info,void * arg)24465796c8dcSSimon Schubert infrun_thread_stop_requested_callback (struct thread_info *info, void *arg)
24475796c8dcSSimon Schubert {
24485796c8dcSSimon Schubert   ptid_t ptid = * (ptid_t *) arg;
24495796c8dcSSimon Schubert 
24505796c8dcSSimon Schubert   if ((ptid_equal (info->ptid, ptid)
24515796c8dcSSimon Schubert        || ptid_equal (minus_one_ptid, ptid)
24525796c8dcSSimon Schubert        || (ptid_is_pid (ptid)
24535796c8dcSSimon Schubert 	   && ptid_get_pid (ptid) == ptid_get_pid (info->ptid)))
24545796c8dcSSimon Schubert       && is_running (info->ptid)
24555796c8dcSSimon Schubert       && !is_executing (info->ptid))
24565796c8dcSSimon Schubert     {
24575796c8dcSSimon Schubert       struct cleanup *old_chain;
24585796c8dcSSimon Schubert       struct execution_control_state ecss;
24595796c8dcSSimon Schubert       struct execution_control_state *ecs = &ecss;
24605796c8dcSSimon Schubert 
24615796c8dcSSimon Schubert       memset (ecs, 0, sizeof (*ecs));
24625796c8dcSSimon Schubert 
24635796c8dcSSimon Schubert       old_chain = make_cleanup_restore_current_thread ();
24645796c8dcSSimon Schubert 
24655796c8dcSSimon Schubert       /* Go through handle_inferior_event/normal_stop, so we always
24665796c8dcSSimon Schubert 	 have consistent output as if the stop event had been
24675796c8dcSSimon Schubert 	 reported.  */
24685796c8dcSSimon Schubert       ecs->ptid = info->ptid;
24695796c8dcSSimon Schubert       ecs->event_thread = find_thread_ptid (info->ptid);
24705796c8dcSSimon Schubert       ecs->ws.kind = TARGET_WAITKIND_STOPPED;
2471*ef5ccd6cSJohn Marino       ecs->ws.value.sig = GDB_SIGNAL_0;
24725796c8dcSSimon Schubert 
24735796c8dcSSimon Schubert       handle_inferior_event (ecs);
24745796c8dcSSimon Schubert 
24755796c8dcSSimon Schubert       if (!ecs->wait_some_more)
24765796c8dcSSimon Schubert 	{
24775796c8dcSSimon Schubert 	  struct thread_info *tp;
24785796c8dcSSimon Schubert 
24795796c8dcSSimon Schubert 	  normal_stop ();
24805796c8dcSSimon Schubert 
2481a45ae5f8SJohn Marino 	  /* Finish off the continuations.  */
24825796c8dcSSimon Schubert 	  tp = inferior_thread ();
2483a45ae5f8SJohn Marino 	  do_all_intermediate_continuations_thread (tp, 1);
2484a45ae5f8SJohn Marino 	  do_all_continuations_thread (tp, 1);
24855796c8dcSSimon Schubert 	}
24865796c8dcSSimon Schubert 
24875796c8dcSSimon Schubert       do_cleanups (old_chain);
24885796c8dcSSimon Schubert     }
24895796c8dcSSimon Schubert 
24905796c8dcSSimon Schubert   return 0;
24915796c8dcSSimon Schubert }
24925796c8dcSSimon Schubert 
24935796c8dcSSimon Schubert /* This function is attached as a "thread_stop_requested" observer.
24945796c8dcSSimon Schubert    Cleanup local state that assumed the PTID was to be resumed, and
24955796c8dcSSimon Schubert    report the stop to the frontend.  */
24965796c8dcSSimon Schubert 
24975796c8dcSSimon Schubert static void
infrun_thread_stop_requested(ptid_t ptid)24985796c8dcSSimon Schubert infrun_thread_stop_requested (ptid_t ptid)
24995796c8dcSSimon Schubert {
2500cf7f2e2dSJohn Marino   struct displaced_step_inferior_state *displaced;
25015796c8dcSSimon Schubert 
25025796c8dcSSimon Schubert   /* PTID was requested to stop.  Remove it from the displaced
25035796c8dcSSimon Schubert      stepping queue, so we don't try to resume it automatically.  */
25045796c8dcSSimon Schubert 
2505cf7f2e2dSJohn Marino   for (displaced = displaced_step_inferior_states;
2506cf7f2e2dSJohn Marino        displaced;
2507cf7f2e2dSJohn Marino        displaced = displaced->next)
25085796c8dcSSimon Schubert     {
2509cf7f2e2dSJohn Marino       struct displaced_step_request *it, **prev_next_p;
25105796c8dcSSimon Schubert 
2511cf7f2e2dSJohn Marino       it = displaced->step_request_queue;
2512cf7f2e2dSJohn Marino       prev_next_p = &displaced->step_request_queue;
2513cf7f2e2dSJohn Marino       while (it)
2514cf7f2e2dSJohn Marino 	{
2515cf7f2e2dSJohn Marino 	  if (ptid_match (it->ptid, ptid))
2516cf7f2e2dSJohn Marino 	    {
2517cf7f2e2dSJohn Marino 	      *prev_next_p = it->next;
2518cf7f2e2dSJohn Marino 	      it->next = NULL;
25195796c8dcSSimon Schubert 	      xfree (it);
25205796c8dcSSimon Schubert 	    }
25215796c8dcSSimon Schubert 	  else
2522cf7f2e2dSJohn Marino 	    {
2523cf7f2e2dSJohn Marino 	      prev_next_p = &it->next;
2524cf7f2e2dSJohn Marino 	    }
2525cf7f2e2dSJohn Marino 
2526cf7f2e2dSJohn Marino 	  it = *prev_next_p;
2527cf7f2e2dSJohn Marino 	}
25285796c8dcSSimon Schubert     }
25295796c8dcSSimon Schubert 
25305796c8dcSSimon Schubert   iterate_over_threads (infrun_thread_stop_requested_callback, &ptid);
25315796c8dcSSimon Schubert }
25325796c8dcSSimon Schubert 
25335796c8dcSSimon Schubert static void
infrun_thread_thread_exit(struct thread_info * tp,int silent)25345796c8dcSSimon Schubert infrun_thread_thread_exit (struct thread_info *tp, int silent)
25355796c8dcSSimon Schubert {
25365796c8dcSSimon Schubert   if (ptid_equal (target_last_wait_ptid, tp->ptid))
25375796c8dcSSimon Schubert     nullify_last_target_wait_ptid ();
25385796c8dcSSimon Schubert }
25395796c8dcSSimon Schubert 
25405796c8dcSSimon Schubert /* Callback for iterate_over_threads.  */
25415796c8dcSSimon Schubert 
25425796c8dcSSimon Schubert static int
delete_step_resume_breakpoint_callback(struct thread_info * info,void * data)25435796c8dcSSimon Schubert delete_step_resume_breakpoint_callback (struct thread_info *info, void *data)
25445796c8dcSSimon Schubert {
25455796c8dcSSimon Schubert   if (is_exited (info->ptid))
25465796c8dcSSimon Schubert     return 0;
25475796c8dcSSimon Schubert 
25485796c8dcSSimon Schubert   delete_step_resume_breakpoint (info);
2549c50c785cSJohn Marino   delete_exception_resume_breakpoint (info);
25505796c8dcSSimon Schubert   return 0;
25515796c8dcSSimon Schubert }
25525796c8dcSSimon Schubert 
25535796c8dcSSimon Schubert /* In all-stop, delete the step resume breakpoint of any thread that
25545796c8dcSSimon Schubert    had one.  In non-stop, delete the step resume breakpoint of the
25555796c8dcSSimon Schubert    thread that just stopped.  */
25565796c8dcSSimon Schubert 
25575796c8dcSSimon Schubert static void
delete_step_thread_step_resume_breakpoint(void)25585796c8dcSSimon Schubert delete_step_thread_step_resume_breakpoint (void)
25595796c8dcSSimon Schubert {
25605796c8dcSSimon Schubert   if (!target_has_execution
25615796c8dcSSimon Schubert       || ptid_equal (inferior_ptid, null_ptid))
25625796c8dcSSimon Schubert     /* If the inferior has exited, we have already deleted the step
25635796c8dcSSimon Schubert        resume breakpoints out of GDB's lists.  */
25645796c8dcSSimon Schubert     return;
25655796c8dcSSimon Schubert 
25665796c8dcSSimon Schubert   if (non_stop)
25675796c8dcSSimon Schubert     {
25685796c8dcSSimon Schubert       /* If in non-stop mode, only delete the step-resume or
25695796c8dcSSimon Schubert 	 longjmp-resume breakpoint of the thread that just stopped
25705796c8dcSSimon Schubert 	 stepping.  */
25715796c8dcSSimon Schubert       struct thread_info *tp = inferior_thread ();
2572cf7f2e2dSJohn Marino 
25735796c8dcSSimon Schubert       delete_step_resume_breakpoint (tp);
2574c50c785cSJohn Marino       delete_exception_resume_breakpoint (tp);
25755796c8dcSSimon Schubert     }
25765796c8dcSSimon Schubert   else
25775796c8dcSSimon Schubert     /* In all-stop mode, delete all step-resume and longjmp-resume
25785796c8dcSSimon Schubert        breakpoints of any thread that had them.  */
25795796c8dcSSimon Schubert     iterate_over_threads (delete_step_resume_breakpoint_callback, NULL);
25805796c8dcSSimon Schubert }
25815796c8dcSSimon Schubert 
25825796c8dcSSimon Schubert /* A cleanup wrapper.  */
25835796c8dcSSimon Schubert 
25845796c8dcSSimon Schubert static void
delete_step_thread_step_resume_breakpoint_cleanup(void * arg)25855796c8dcSSimon Schubert delete_step_thread_step_resume_breakpoint_cleanup (void *arg)
25865796c8dcSSimon Schubert {
25875796c8dcSSimon Schubert   delete_step_thread_step_resume_breakpoint ();
25885796c8dcSSimon Schubert }
25895796c8dcSSimon Schubert 
25905796c8dcSSimon Schubert /* Pretty print the results of target_wait, for debugging purposes.  */
25915796c8dcSSimon Schubert 
25925796c8dcSSimon Schubert static void
print_target_wait_results(ptid_t waiton_ptid,ptid_t result_ptid,const struct target_waitstatus * ws)25935796c8dcSSimon Schubert print_target_wait_results (ptid_t waiton_ptid, ptid_t result_ptid,
25945796c8dcSSimon Schubert 			   const struct target_waitstatus *ws)
25955796c8dcSSimon Schubert {
25965796c8dcSSimon Schubert   char *status_string = target_waitstatus_to_string (ws);
25975796c8dcSSimon Schubert   struct ui_file *tmp_stream = mem_fileopen ();
25985796c8dcSSimon Schubert   char *text;
25995796c8dcSSimon Schubert 
26005796c8dcSSimon Schubert   /* The text is split over several lines because it was getting too long.
26015796c8dcSSimon Schubert      Call fprintf_unfiltered (gdb_stdlog) once so that the text is still
26025796c8dcSSimon Schubert      output as a unit; we want only one timestamp printed if debug_timestamp
26035796c8dcSSimon Schubert      is set.  */
26045796c8dcSSimon Schubert 
26055796c8dcSSimon Schubert   fprintf_unfiltered (tmp_stream,
26065796c8dcSSimon Schubert 		      "infrun: target_wait (%d", PIDGET (waiton_ptid));
26075796c8dcSSimon Schubert   if (PIDGET (waiton_ptid) != -1)
26085796c8dcSSimon Schubert     fprintf_unfiltered (tmp_stream,
26095796c8dcSSimon Schubert 			" [%s]", target_pid_to_str (waiton_ptid));
26105796c8dcSSimon Schubert   fprintf_unfiltered (tmp_stream, ", status) =\n");
26115796c8dcSSimon Schubert   fprintf_unfiltered (tmp_stream,
26125796c8dcSSimon Schubert 		      "infrun:   %d [%s],\n",
26135796c8dcSSimon Schubert 		      PIDGET (result_ptid), target_pid_to_str (result_ptid));
26145796c8dcSSimon Schubert   fprintf_unfiltered (tmp_stream,
26155796c8dcSSimon Schubert 		      "infrun:   %s\n",
26165796c8dcSSimon Schubert 		      status_string);
26175796c8dcSSimon Schubert 
26185796c8dcSSimon Schubert   text = ui_file_xstrdup (tmp_stream, NULL);
26195796c8dcSSimon Schubert 
26205796c8dcSSimon Schubert   /* This uses %s in part to handle %'s in the text, but also to avoid
26215796c8dcSSimon Schubert      a gcc error: the format attribute requires a string literal.  */
26225796c8dcSSimon Schubert   fprintf_unfiltered (gdb_stdlog, "%s", text);
26235796c8dcSSimon Schubert 
26245796c8dcSSimon Schubert   xfree (status_string);
26255796c8dcSSimon Schubert   xfree (text);
26265796c8dcSSimon Schubert   ui_file_delete (tmp_stream);
26275796c8dcSSimon Schubert }
26285796c8dcSSimon Schubert 
2629cf7f2e2dSJohn Marino /* Prepare and stabilize the inferior for detaching it.  E.g.,
2630cf7f2e2dSJohn Marino    detaching while a thread is displaced stepping is a recipe for
2631cf7f2e2dSJohn Marino    crashing it, as nothing would readjust the PC out of the scratch
2632cf7f2e2dSJohn Marino    pad.  */
2633cf7f2e2dSJohn Marino 
2634cf7f2e2dSJohn Marino void
prepare_for_detach(void)2635cf7f2e2dSJohn Marino prepare_for_detach (void)
2636cf7f2e2dSJohn Marino {
2637cf7f2e2dSJohn Marino   struct inferior *inf = current_inferior ();
2638cf7f2e2dSJohn Marino   ptid_t pid_ptid = pid_to_ptid (inf->pid);
2639cf7f2e2dSJohn Marino   struct cleanup *old_chain_1;
2640cf7f2e2dSJohn Marino   struct displaced_step_inferior_state *displaced;
2641cf7f2e2dSJohn Marino 
2642cf7f2e2dSJohn Marino   displaced = get_displaced_stepping_state (inf->pid);
2643cf7f2e2dSJohn Marino 
2644cf7f2e2dSJohn Marino   /* Is any thread of this process displaced stepping?  If not,
2645cf7f2e2dSJohn Marino      there's nothing else to do.  */
2646cf7f2e2dSJohn Marino   if (displaced == NULL || ptid_equal (displaced->step_ptid, null_ptid))
2647cf7f2e2dSJohn Marino     return;
2648cf7f2e2dSJohn Marino 
2649cf7f2e2dSJohn Marino   if (debug_infrun)
2650cf7f2e2dSJohn Marino     fprintf_unfiltered (gdb_stdlog,
2651cf7f2e2dSJohn Marino 			"displaced-stepping in-process while detaching");
2652cf7f2e2dSJohn Marino 
2653cf7f2e2dSJohn Marino   old_chain_1 = make_cleanup_restore_integer (&inf->detaching);
2654cf7f2e2dSJohn Marino   inf->detaching = 1;
2655cf7f2e2dSJohn Marino 
2656cf7f2e2dSJohn Marino   while (!ptid_equal (displaced->step_ptid, null_ptid))
2657cf7f2e2dSJohn Marino     {
2658cf7f2e2dSJohn Marino       struct cleanup *old_chain_2;
2659cf7f2e2dSJohn Marino       struct execution_control_state ecss;
2660cf7f2e2dSJohn Marino       struct execution_control_state *ecs;
2661cf7f2e2dSJohn Marino 
2662cf7f2e2dSJohn Marino       ecs = &ecss;
2663cf7f2e2dSJohn Marino       memset (ecs, 0, sizeof (*ecs));
2664cf7f2e2dSJohn Marino 
2665cf7f2e2dSJohn Marino       overlay_cache_invalid = 1;
2666cf7f2e2dSJohn Marino 
2667cf7f2e2dSJohn Marino       if (deprecated_target_wait_hook)
2668cf7f2e2dSJohn Marino 	ecs->ptid = deprecated_target_wait_hook (pid_ptid, &ecs->ws, 0);
2669cf7f2e2dSJohn Marino       else
2670cf7f2e2dSJohn Marino 	ecs->ptid = target_wait (pid_ptid, &ecs->ws, 0);
2671cf7f2e2dSJohn Marino 
2672cf7f2e2dSJohn Marino       if (debug_infrun)
2673cf7f2e2dSJohn Marino 	print_target_wait_results (pid_ptid, ecs->ptid, &ecs->ws);
2674cf7f2e2dSJohn Marino 
2675cf7f2e2dSJohn Marino       /* If an error happens while handling the event, propagate GDB's
2676cf7f2e2dSJohn Marino 	 knowledge of the executing state to the frontend/user running
2677cf7f2e2dSJohn Marino 	 state.  */
2678c50c785cSJohn Marino       old_chain_2 = make_cleanup (finish_thread_state_cleanup,
2679c50c785cSJohn Marino 				  &minus_one_ptid);
2680cf7f2e2dSJohn Marino 
2681cf7f2e2dSJohn Marino       /* Now figure out what to do with the result of the result.  */
2682cf7f2e2dSJohn Marino       handle_inferior_event (ecs);
2683cf7f2e2dSJohn Marino 
2684cf7f2e2dSJohn Marino       /* No error, don't finish the state yet.  */
2685cf7f2e2dSJohn Marino       discard_cleanups (old_chain_2);
2686cf7f2e2dSJohn Marino 
2687cf7f2e2dSJohn Marino       /* Breakpoints and watchpoints are not installed on the target
2688cf7f2e2dSJohn Marino 	 at this point, and signals are passed directly to the
2689cf7f2e2dSJohn Marino 	 inferior, so this must mean the process is gone.  */
2690cf7f2e2dSJohn Marino       if (!ecs->wait_some_more)
2691cf7f2e2dSJohn Marino 	{
2692cf7f2e2dSJohn Marino 	  discard_cleanups (old_chain_1);
2693cf7f2e2dSJohn Marino 	  error (_("Program exited while detaching"));
2694cf7f2e2dSJohn Marino 	}
2695cf7f2e2dSJohn Marino     }
2696cf7f2e2dSJohn Marino 
2697cf7f2e2dSJohn Marino   discard_cleanups (old_chain_1);
2698cf7f2e2dSJohn Marino }
2699cf7f2e2dSJohn Marino 
27005796c8dcSSimon Schubert /* Wait for control to return from inferior to debugger.
27015796c8dcSSimon Schubert 
27025796c8dcSSimon Schubert    If inferior gets a signal, we may decide to start it up again
27035796c8dcSSimon Schubert    instead of returning.  That is why there is a loop in this function.
27045796c8dcSSimon Schubert    When this function actually returns it means the inferior
27055796c8dcSSimon Schubert    should be left stopped and GDB should read more commands.  */
27065796c8dcSSimon Schubert 
27075796c8dcSSimon Schubert void
wait_for_inferior(void)2708a45ae5f8SJohn Marino wait_for_inferior (void)
27095796c8dcSSimon Schubert {
27105796c8dcSSimon Schubert   struct cleanup *old_cleanups;
27115796c8dcSSimon Schubert 
27125796c8dcSSimon Schubert   if (debug_infrun)
27135796c8dcSSimon Schubert     fprintf_unfiltered
2714a45ae5f8SJohn Marino       (gdb_stdlog, "infrun: wait_for_inferior ()\n");
27155796c8dcSSimon Schubert 
27165796c8dcSSimon Schubert   old_cleanups =
27175796c8dcSSimon Schubert     make_cleanup (delete_step_thread_step_resume_breakpoint_cleanup, NULL);
27185796c8dcSSimon Schubert 
27195796c8dcSSimon Schubert   while (1)
27205796c8dcSSimon Schubert     {
2721*ef5ccd6cSJohn Marino       struct execution_control_state ecss;
2722*ef5ccd6cSJohn Marino       struct execution_control_state *ecs = &ecss;
27235796c8dcSSimon Schubert       struct cleanup *old_chain;
27245796c8dcSSimon Schubert 
2725*ef5ccd6cSJohn Marino       memset (ecs, 0, sizeof (*ecs));
2726*ef5ccd6cSJohn Marino 
27275796c8dcSSimon Schubert       overlay_cache_invalid = 1;
27285796c8dcSSimon Schubert 
27295796c8dcSSimon Schubert       if (deprecated_target_wait_hook)
27305796c8dcSSimon Schubert 	ecs->ptid = deprecated_target_wait_hook (waiton_ptid, &ecs->ws, 0);
27315796c8dcSSimon Schubert       else
27325796c8dcSSimon Schubert 	ecs->ptid = target_wait (waiton_ptid, &ecs->ws, 0);
27335796c8dcSSimon Schubert 
27345796c8dcSSimon Schubert       if (debug_infrun)
27355796c8dcSSimon Schubert 	print_target_wait_results (waiton_ptid, ecs->ptid, &ecs->ws);
27365796c8dcSSimon Schubert 
27375796c8dcSSimon Schubert       /* If an error happens while handling the event, propagate GDB's
27385796c8dcSSimon Schubert 	 knowledge of the executing state to the frontend/user running
27395796c8dcSSimon Schubert 	 state.  */
27405796c8dcSSimon Schubert       old_chain = make_cleanup (finish_thread_state_cleanup, &minus_one_ptid);
27415796c8dcSSimon Schubert 
27425796c8dcSSimon Schubert       /* Now figure out what to do with the result of the result.  */
27435796c8dcSSimon Schubert       handle_inferior_event (ecs);
27445796c8dcSSimon Schubert 
27455796c8dcSSimon Schubert       /* No error, don't finish the state yet.  */
27465796c8dcSSimon Schubert       discard_cleanups (old_chain);
27475796c8dcSSimon Schubert 
27485796c8dcSSimon Schubert       if (!ecs->wait_some_more)
27495796c8dcSSimon Schubert 	break;
27505796c8dcSSimon Schubert     }
27515796c8dcSSimon Schubert 
27525796c8dcSSimon Schubert   do_cleanups (old_cleanups);
27535796c8dcSSimon Schubert }
27545796c8dcSSimon Schubert 
27555796c8dcSSimon Schubert /* Asynchronous version of wait_for_inferior.  It is called by the
27565796c8dcSSimon Schubert    event loop whenever a change of state is detected on the file
27575796c8dcSSimon Schubert    descriptor corresponding to the target.  It can be called more than
27585796c8dcSSimon Schubert    once to complete a single execution command.  In such cases we need
27595796c8dcSSimon Schubert    to keep the state in a global variable ECSS.  If it is the last time
27605796c8dcSSimon Schubert    that this function is called for a single execution command, then
27615796c8dcSSimon Schubert    report to the user that the inferior has stopped, and do the
27625796c8dcSSimon Schubert    necessary cleanups.  */
27635796c8dcSSimon Schubert 
27645796c8dcSSimon Schubert void
fetch_inferior_event(void * client_data)27655796c8dcSSimon Schubert fetch_inferior_event (void *client_data)
27665796c8dcSSimon Schubert {
27675796c8dcSSimon Schubert   struct execution_control_state ecss;
27685796c8dcSSimon Schubert   struct execution_control_state *ecs = &ecss;
27695796c8dcSSimon Schubert   struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
27705796c8dcSSimon Schubert   struct cleanup *ts_old_chain;
27715796c8dcSSimon Schubert   int was_sync = sync_execution;
2772a45ae5f8SJohn Marino   int cmd_done = 0;
27735796c8dcSSimon Schubert 
27745796c8dcSSimon Schubert   memset (ecs, 0, sizeof (*ecs));
27755796c8dcSSimon Schubert 
2776c50c785cSJohn Marino   /* We're handling a live event, so make sure we're doing live
2777c50c785cSJohn Marino      debugging.  If we're looking at traceframes while the target is
2778c50c785cSJohn Marino      running, we're going to need to get back to that mode after
2779c50c785cSJohn Marino      handling the event.  */
2780c50c785cSJohn Marino   if (non_stop)
2781c50c785cSJohn Marino     {
2782c50c785cSJohn Marino       make_cleanup_restore_current_traceframe ();
2783c50c785cSJohn Marino       set_current_traceframe (-1);
2784c50c785cSJohn Marino     }
2785c50c785cSJohn Marino 
27865796c8dcSSimon Schubert   if (non_stop)
27875796c8dcSSimon Schubert     /* In non-stop mode, the user/frontend should not notice a thread
27885796c8dcSSimon Schubert        switch due to internal events.  Make sure we reverse to the
27895796c8dcSSimon Schubert        user selected thread and frame after handling the event and
27905796c8dcSSimon Schubert        running any breakpoint commands.  */
27915796c8dcSSimon Schubert     make_cleanup_restore_current_thread ();
27925796c8dcSSimon Schubert 
27935796c8dcSSimon Schubert   overlay_cache_invalid = 1;
2794a45ae5f8SJohn Marino 
2795a45ae5f8SJohn Marino   make_cleanup_restore_integer (&execution_direction);
2796a45ae5f8SJohn Marino   execution_direction = target_execution_direction ();
27975796c8dcSSimon Schubert 
27985796c8dcSSimon Schubert   if (deprecated_target_wait_hook)
27995796c8dcSSimon Schubert     ecs->ptid =
28005796c8dcSSimon Schubert       deprecated_target_wait_hook (waiton_ptid, &ecs->ws, TARGET_WNOHANG);
28015796c8dcSSimon Schubert   else
28025796c8dcSSimon Schubert     ecs->ptid = target_wait (waiton_ptid, &ecs->ws, TARGET_WNOHANG);
28035796c8dcSSimon Schubert 
28045796c8dcSSimon Schubert   if (debug_infrun)
28055796c8dcSSimon Schubert     print_target_wait_results (waiton_ptid, ecs->ptid, &ecs->ws);
28065796c8dcSSimon Schubert 
28075796c8dcSSimon Schubert   /* If an error happens while handling the event, propagate GDB's
28085796c8dcSSimon Schubert      knowledge of the executing state to the frontend/user running
28095796c8dcSSimon Schubert      state.  */
28105796c8dcSSimon Schubert   if (!non_stop)
28115796c8dcSSimon Schubert     ts_old_chain = make_cleanup (finish_thread_state_cleanup, &minus_one_ptid);
28125796c8dcSSimon Schubert   else
28135796c8dcSSimon Schubert     ts_old_chain = make_cleanup (finish_thread_state_cleanup, &ecs->ptid);
28145796c8dcSSimon Schubert 
2815a45ae5f8SJohn Marino   /* Get executed before make_cleanup_restore_current_thread above to apply
2816a45ae5f8SJohn Marino      still for the thread which has thrown the exception.  */
2817a45ae5f8SJohn Marino   make_bpstat_clear_actions_cleanup ();
2818a45ae5f8SJohn Marino 
28195796c8dcSSimon Schubert   /* Now figure out what to do with the result of the result.  */
28205796c8dcSSimon Schubert   handle_inferior_event (ecs);
28215796c8dcSSimon Schubert 
28225796c8dcSSimon Schubert   if (!ecs->wait_some_more)
28235796c8dcSSimon Schubert     {
28245796c8dcSSimon Schubert       struct inferior *inf = find_inferior_pid (ptid_get_pid (ecs->ptid));
28255796c8dcSSimon Schubert 
28265796c8dcSSimon Schubert       delete_step_thread_step_resume_breakpoint ();
28275796c8dcSSimon Schubert 
28285796c8dcSSimon Schubert       /* We may not find an inferior if this was a process exit.  */
2829c50c785cSJohn Marino       if (inf == NULL || inf->control.stop_soon == NO_STOP_QUIETLY)
28305796c8dcSSimon Schubert 	normal_stop ();
28315796c8dcSSimon Schubert 
28325796c8dcSSimon Schubert       if (target_has_execution
2833a45ae5f8SJohn Marino 	  && ecs->ws.kind != TARGET_WAITKIND_NO_RESUMED
28345796c8dcSSimon Schubert 	  && ecs->ws.kind != TARGET_WAITKIND_EXITED
28355796c8dcSSimon Schubert 	  && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED
28365796c8dcSSimon Schubert 	  && ecs->event_thread->step_multi
2837c50c785cSJohn Marino 	  && ecs->event_thread->control.stop_step)
28385796c8dcSSimon Schubert 	inferior_event_handler (INF_EXEC_CONTINUE, NULL);
28395796c8dcSSimon Schubert       else
2840a45ae5f8SJohn Marino 	{
28415796c8dcSSimon Schubert 	  inferior_event_handler (INF_EXEC_COMPLETE, NULL);
2842a45ae5f8SJohn Marino 	  cmd_done = 1;
2843a45ae5f8SJohn Marino 	}
28445796c8dcSSimon Schubert     }
28455796c8dcSSimon Schubert 
28465796c8dcSSimon Schubert   /* No error, don't finish the thread states yet.  */
28475796c8dcSSimon Schubert   discard_cleanups (ts_old_chain);
28485796c8dcSSimon Schubert 
28495796c8dcSSimon Schubert   /* Revert thread and frame.  */
28505796c8dcSSimon Schubert   do_cleanups (old_chain);
28515796c8dcSSimon Schubert 
28525796c8dcSSimon Schubert   /* If the inferior was in sync execution mode, and now isn't,
2853a45ae5f8SJohn Marino      restore the prompt (a synchronous execution command has finished,
2854a45ae5f8SJohn Marino      and we're ready for input).  */
2855a45ae5f8SJohn Marino   if (interpreter_async && was_sync && !sync_execution)
28565796c8dcSSimon Schubert     display_gdb_prompt (0);
2857a45ae5f8SJohn Marino 
2858a45ae5f8SJohn Marino   if (cmd_done
2859a45ae5f8SJohn Marino       && !was_sync
2860a45ae5f8SJohn Marino       && exec_done_display_p
2861a45ae5f8SJohn Marino       && (ptid_equal (inferior_ptid, null_ptid)
2862a45ae5f8SJohn Marino 	  || !is_running (inferior_ptid)))
2863a45ae5f8SJohn Marino     printf_unfiltered (_("completed.\n"));
28645796c8dcSSimon Schubert }
28655796c8dcSSimon Schubert 
28665796c8dcSSimon Schubert /* Record the frame and location we're currently stepping through.  */
28675796c8dcSSimon Schubert void
set_step_info(struct frame_info * frame,struct symtab_and_line sal)28685796c8dcSSimon Schubert set_step_info (struct frame_info *frame, struct symtab_and_line sal)
28695796c8dcSSimon Schubert {
28705796c8dcSSimon Schubert   struct thread_info *tp = inferior_thread ();
28715796c8dcSSimon Schubert 
2872c50c785cSJohn Marino   tp->control.step_frame_id = get_frame_id (frame);
2873c50c785cSJohn Marino   tp->control.step_stack_frame_id = get_stack_frame_id (frame);
28745796c8dcSSimon Schubert 
28755796c8dcSSimon Schubert   tp->current_symtab = sal.symtab;
28765796c8dcSSimon Schubert   tp->current_line = sal.line;
28775796c8dcSSimon Schubert }
28785796c8dcSSimon Schubert 
28795796c8dcSSimon Schubert /* Clear context switchable stepping state.  */
28805796c8dcSSimon Schubert 
28815796c8dcSSimon Schubert void
init_thread_stepping_state(struct thread_info * tss)28825796c8dcSSimon Schubert init_thread_stepping_state (struct thread_info *tss)
28835796c8dcSSimon Schubert {
28845796c8dcSSimon Schubert   tss->stepping_over_breakpoint = 0;
28855796c8dcSSimon Schubert   tss->step_after_step_resume_breakpoint = 0;
28865796c8dcSSimon Schubert }
28875796c8dcSSimon Schubert 
28885796c8dcSSimon Schubert /* Return the cached copy of the last pid/waitstatus returned by
28895796c8dcSSimon Schubert    target_wait()/deprecated_target_wait_hook().  The data is actually
28905796c8dcSSimon Schubert    cached by handle_inferior_event(), which gets called immediately
28915796c8dcSSimon Schubert    after target_wait()/deprecated_target_wait_hook().  */
28925796c8dcSSimon Schubert 
28935796c8dcSSimon Schubert void
get_last_target_status(ptid_t * ptidp,struct target_waitstatus * status)28945796c8dcSSimon Schubert get_last_target_status (ptid_t *ptidp, struct target_waitstatus *status)
28955796c8dcSSimon Schubert {
28965796c8dcSSimon Schubert   *ptidp = target_last_wait_ptid;
28975796c8dcSSimon Schubert   *status = target_last_waitstatus;
28985796c8dcSSimon Schubert }
28995796c8dcSSimon Schubert 
29005796c8dcSSimon Schubert void
nullify_last_target_wait_ptid(void)29015796c8dcSSimon Schubert nullify_last_target_wait_ptid (void)
29025796c8dcSSimon Schubert {
29035796c8dcSSimon Schubert   target_last_wait_ptid = minus_one_ptid;
29045796c8dcSSimon Schubert }
29055796c8dcSSimon Schubert 
29065796c8dcSSimon Schubert /* Switch thread contexts.  */
29075796c8dcSSimon Schubert 
29085796c8dcSSimon Schubert static void
context_switch(ptid_t ptid)29095796c8dcSSimon Schubert context_switch (ptid_t ptid)
29105796c8dcSSimon Schubert {
2911a45ae5f8SJohn Marino   if (debug_infrun && !ptid_equal (ptid, inferior_ptid))
29125796c8dcSSimon Schubert     {
29135796c8dcSSimon Schubert       fprintf_unfiltered (gdb_stdlog, "infrun: Switching context from %s ",
29145796c8dcSSimon Schubert 			  target_pid_to_str (inferior_ptid));
29155796c8dcSSimon Schubert       fprintf_unfiltered (gdb_stdlog, "to %s\n",
29165796c8dcSSimon Schubert 			  target_pid_to_str (ptid));
29175796c8dcSSimon Schubert     }
29185796c8dcSSimon Schubert 
29195796c8dcSSimon Schubert   switch_to_thread (ptid);
29205796c8dcSSimon Schubert }
29215796c8dcSSimon Schubert 
29225796c8dcSSimon Schubert static void
adjust_pc_after_break(struct execution_control_state * ecs)29235796c8dcSSimon Schubert adjust_pc_after_break (struct execution_control_state *ecs)
29245796c8dcSSimon Schubert {
29255796c8dcSSimon Schubert   struct regcache *regcache;
29265796c8dcSSimon Schubert   struct gdbarch *gdbarch;
2927cf7f2e2dSJohn Marino   struct address_space *aspace;
29285796c8dcSSimon Schubert   CORE_ADDR breakpoint_pc;
29295796c8dcSSimon Schubert 
29305796c8dcSSimon Schubert   /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP.  If
29315796c8dcSSimon Schubert      we aren't, just return.
29325796c8dcSSimon Schubert 
29335796c8dcSSimon Schubert      We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not
29345796c8dcSSimon Schubert      affected by gdbarch_decr_pc_after_break.  Other waitkinds which are
29355796c8dcSSimon Schubert      implemented by software breakpoints should be handled through the normal
29365796c8dcSSimon Schubert      breakpoint layer.
29375796c8dcSSimon Schubert 
29385796c8dcSSimon Schubert      NOTE drow/2004-01-31: On some targets, breakpoints may generate
29395796c8dcSSimon Schubert      different signals (SIGILL or SIGEMT for instance), but it is less
29405796c8dcSSimon Schubert      clear where the PC is pointing afterwards.  It may not match
29415796c8dcSSimon Schubert      gdbarch_decr_pc_after_break.  I don't know any specific target that
29425796c8dcSSimon Schubert      generates these signals at breakpoints (the code has been in GDB since at
29435796c8dcSSimon Schubert      least 1992) so I can not guess how to handle them here.
29445796c8dcSSimon Schubert 
29455796c8dcSSimon Schubert      In earlier versions of GDB, a target with
29465796c8dcSSimon Schubert      gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a
29475796c8dcSSimon Schubert      watchpoint affected by gdbarch_decr_pc_after_break.  I haven't found any
29485796c8dcSSimon Schubert      target with both of these set in GDB history, and it seems unlikely to be
29495796c8dcSSimon Schubert      correct, so gdbarch_have_nonsteppable_watchpoint is not checked here.  */
29505796c8dcSSimon Schubert 
29515796c8dcSSimon Schubert   if (ecs->ws.kind != TARGET_WAITKIND_STOPPED)
29525796c8dcSSimon Schubert     return;
29535796c8dcSSimon Schubert 
2954*ef5ccd6cSJohn Marino   if (ecs->ws.value.sig != GDB_SIGNAL_TRAP)
29555796c8dcSSimon Schubert     return;
29565796c8dcSSimon Schubert 
29575796c8dcSSimon Schubert   /* In reverse execution, when a breakpoint is hit, the instruction
29585796c8dcSSimon Schubert      under it has already been de-executed.  The reported PC always
29595796c8dcSSimon Schubert      points at the breakpoint address, so adjusting it further would
29605796c8dcSSimon Schubert      be wrong.  E.g., consider this case on a decr_pc_after_break == 1
29615796c8dcSSimon Schubert      architecture:
29625796c8dcSSimon Schubert 
29635796c8dcSSimon Schubert        B1         0x08000000 :   INSN1
29645796c8dcSSimon Schubert        B2         0x08000001 :   INSN2
29655796c8dcSSimon Schubert 		  0x08000002 :   INSN3
29665796c8dcSSimon Schubert 	    PC -> 0x08000003 :   INSN4
29675796c8dcSSimon Schubert 
29685796c8dcSSimon Schubert      Say you're stopped at 0x08000003 as above.  Reverse continuing
29695796c8dcSSimon Schubert      from that point should hit B2 as below.  Reading the PC when the
29705796c8dcSSimon Schubert      SIGTRAP is reported should read 0x08000001 and INSN2 should have
29715796c8dcSSimon Schubert      been de-executed already.
29725796c8dcSSimon Schubert 
29735796c8dcSSimon Schubert        B1         0x08000000 :   INSN1
29745796c8dcSSimon Schubert        B2   PC -> 0x08000001 :   INSN2
29755796c8dcSSimon Schubert 		  0x08000002 :   INSN3
29765796c8dcSSimon Schubert 		  0x08000003 :   INSN4
29775796c8dcSSimon Schubert 
29785796c8dcSSimon Schubert      We can't apply the same logic as for forward execution, because
29795796c8dcSSimon Schubert      we would wrongly adjust the PC to 0x08000000, since there's a
29805796c8dcSSimon Schubert      breakpoint at PC - 1.  We'd then report a hit on B1, although
29815796c8dcSSimon Schubert      INSN1 hadn't been de-executed yet.  Doing nothing is the correct
29825796c8dcSSimon Schubert      behaviour.  */
29835796c8dcSSimon Schubert   if (execution_direction == EXEC_REVERSE)
29845796c8dcSSimon Schubert     return;
29855796c8dcSSimon Schubert 
29865796c8dcSSimon Schubert   /* If this target does not decrement the PC after breakpoints, then
29875796c8dcSSimon Schubert      we have nothing to do.  */
29885796c8dcSSimon Schubert   regcache = get_thread_regcache (ecs->ptid);
29895796c8dcSSimon Schubert   gdbarch = get_regcache_arch (regcache);
29905796c8dcSSimon Schubert   if (gdbarch_decr_pc_after_break (gdbarch) == 0)
29915796c8dcSSimon Schubert     return;
29925796c8dcSSimon Schubert 
2993cf7f2e2dSJohn Marino   aspace = get_regcache_aspace (regcache);
2994cf7f2e2dSJohn Marino 
29955796c8dcSSimon Schubert   /* Find the location where (if we've hit a breakpoint) the
29965796c8dcSSimon Schubert      breakpoint would be.  */
29975796c8dcSSimon Schubert   breakpoint_pc = regcache_read_pc (regcache)
29985796c8dcSSimon Schubert 		  - gdbarch_decr_pc_after_break (gdbarch);
29995796c8dcSSimon Schubert 
30005796c8dcSSimon Schubert   /* Check whether there actually is a software breakpoint inserted at
30015796c8dcSSimon Schubert      that location.
30025796c8dcSSimon Schubert 
30035796c8dcSSimon Schubert      If in non-stop mode, a race condition is possible where we've
30045796c8dcSSimon Schubert      removed a breakpoint, but stop events for that breakpoint were
30055796c8dcSSimon Schubert      already queued and arrive later.  To suppress those spurious
30065796c8dcSSimon Schubert      SIGTRAPs, we keep a list of such breakpoint locations for a bit,
30075796c8dcSSimon Schubert      and retire them after a number of stop events are reported.  */
3008cf7f2e2dSJohn Marino   if (software_breakpoint_inserted_here_p (aspace, breakpoint_pc)
3009cf7f2e2dSJohn Marino       || (non_stop && moribund_breakpoint_here_p (aspace, breakpoint_pc)))
30105796c8dcSSimon Schubert     {
30115796c8dcSSimon Schubert       struct cleanup *old_cleanups = NULL;
3012cf7f2e2dSJohn Marino 
30135796c8dcSSimon Schubert       if (RECORD_IS_USED)
3014*ef5ccd6cSJohn Marino 	old_cleanups = record_full_gdb_operation_disable_set ();
30155796c8dcSSimon Schubert 
30165796c8dcSSimon Schubert       /* When using hardware single-step, a SIGTRAP is reported for both
30175796c8dcSSimon Schubert 	 a completed single-step and a software breakpoint.  Need to
30185796c8dcSSimon Schubert 	 differentiate between the two, as the latter needs adjusting
30195796c8dcSSimon Schubert 	 but the former does not.
30205796c8dcSSimon Schubert 
30215796c8dcSSimon Schubert 	 The SIGTRAP can be due to a completed hardware single-step only if
30225796c8dcSSimon Schubert 	  - we didn't insert software single-step breakpoints
30235796c8dcSSimon Schubert 	  - the thread to be examined is still the current thread
30245796c8dcSSimon Schubert 	  - this thread is currently being stepped
30255796c8dcSSimon Schubert 
30265796c8dcSSimon Schubert 	 If any of these events did not occur, we must have stopped due
30275796c8dcSSimon Schubert 	 to hitting a software breakpoint, and have to back up to the
30285796c8dcSSimon Schubert 	 breakpoint address.
30295796c8dcSSimon Schubert 
30305796c8dcSSimon Schubert 	 As a special case, we could have hardware single-stepped a
30315796c8dcSSimon Schubert 	 software breakpoint.  In this case (prev_pc == breakpoint_pc),
30325796c8dcSSimon Schubert 	 we also need to back up to the breakpoint address.  */
30335796c8dcSSimon Schubert 
30345796c8dcSSimon Schubert       if (singlestep_breakpoints_inserted_p
30355796c8dcSSimon Schubert 	  || !ptid_equal (ecs->ptid, inferior_ptid)
30365796c8dcSSimon Schubert 	  || !currently_stepping (ecs->event_thread)
30375796c8dcSSimon Schubert 	  || ecs->event_thread->prev_pc == breakpoint_pc)
30385796c8dcSSimon Schubert 	regcache_write_pc (regcache, breakpoint_pc);
30395796c8dcSSimon Schubert 
30405796c8dcSSimon Schubert       if (RECORD_IS_USED)
30415796c8dcSSimon Schubert 	do_cleanups (old_cleanups);
30425796c8dcSSimon Schubert     }
30435796c8dcSSimon Schubert }
30445796c8dcSSimon Schubert 
3045*ef5ccd6cSJohn Marino static void
init_infwait_state(void)30465796c8dcSSimon Schubert init_infwait_state (void)
30475796c8dcSSimon Schubert {
30485796c8dcSSimon Schubert   waiton_ptid = pid_to_ptid (-1);
30495796c8dcSSimon Schubert   infwait_state = infwait_normal_state;
30505796c8dcSSimon Schubert }
30515796c8dcSSimon Schubert 
30525796c8dcSSimon Schubert static int
stepped_in_from(struct frame_info * frame,struct frame_id step_frame_id)30535796c8dcSSimon Schubert stepped_in_from (struct frame_info *frame, struct frame_id step_frame_id)
30545796c8dcSSimon Schubert {
30555796c8dcSSimon Schubert   for (frame = get_prev_frame (frame);
30565796c8dcSSimon Schubert        frame != NULL;
30575796c8dcSSimon Schubert        frame = get_prev_frame (frame))
30585796c8dcSSimon Schubert     {
30595796c8dcSSimon Schubert       if (frame_id_eq (get_frame_id (frame), step_frame_id))
30605796c8dcSSimon Schubert 	return 1;
30615796c8dcSSimon Schubert       if (get_frame_type (frame) != INLINE_FRAME)
30625796c8dcSSimon Schubert 	break;
30635796c8dcSSimon Schubert     }
30645796c8dcSSimon Schubert 
30655796c8dcSSimon Schubert   return 0;
30665796c8dcSSimon Schubert }
30675796c8dcSSimon Schubert 
30685796c8dcSSimon Schubert /* Auxiliary function that handles syscall entry/return events.
30695796c8dcSSimon Schubert    It returns 1 if the inferior should keep going (and GDB
30705796c8dcSSimon Schubert    should ignore the event), or 0 if the event deserves to be
30715796c8dcSSimon Schubert    processed.  */
3072cf7f2e2dSJohn Marino 
30735796c8dcSSimon Schubert static int
handle_syscall_event(struct execution_control_state * ecs)3074cf7f2e2dSJohn Marino handle_syscall_event (struct execution_control_state *ecs)
30755796c8dcSSimon Schubert {
3076cf7f2e2dSJohn Marino   struct regcache *regcache;
3077cf7f2e2dSJohn Marino   int syscall_number;
3078cf7f2e2dSJohn Marino 
3079cf7f2e2dSJohn Marino   if (!ptid_equal (ecs->ptid, inferior_ptid))
3080cf7f2e2dSJohn Marino     context_switch (ecs->ptid);
3081cf7f2e2dSJohn Marino 
3082cf7f2e2dSJohn Marino   regcache = get_thread_regcache (ecs->ptid);
3083*ef5ccd6cSJohn Marino   syscall_number = ecs->ws.value.syscall_number;
3084cf7f2e2dSJohn Marino   stop_pc = regcache_read_pc (regcache);
3085cf7f2e2dSJohn Marino 
30865796c8dcSSimon Schubert   if (catch_syscall_enabled () > 0
30875796c8dcSSimon Schubert       && catching_syscall_number (syscall_number) > 0)
30885796c8dcSSimon Schubert     {
3089*ef5ccd6cSJohn Marino       enum bpstat_signal_value sval;
3090*ef5ccd6cSJohn Marino 
30915796c8dcSSimon Schubert       if (debug_infrun)
30925796c8dcSSimon Schubert         fprintf_unfiltered (gdb_stdlog, "infrun: syscall number = '%d'\n",
30935796c8dcSSimon Schubert                             syscall_number);
30945796c8dcSSimon Schubert 
3095c50c785cSJohn Marino       ecs->event_thread->control.stop_bpstat
3096cf7f2e2dSJohn Marino 	= bpstat_stop_status (get_regcache_aspace (regcache),
3097*ef5ccd6cSJohn Marino 			      stop_pc, ecs->ptid, &ecs->ws);
3098*ef5ccd6cSJohn Marino 
3099*ef5ccd6cSJohn Marino       sval = bpstat_explains_signal (ecs->event_thread->control.stop_bpstat,
3100*ef5ccd6cSJohn Marino 				     GDB_SIGNAL_TRAP);
3101*ef5ccd6cSJohn Marino       ecs->random_signal = sval == BPSTAT_SIGNAL_NO;
31025796c8dcSSimon Schubert 
3103cf7f2e2dSJohn Marino       if (!ecs->random_signal)
31045796c8dcSSimon Schubert 	{
3105cf7f2e2dSJohn Marino 	  /* Catchpoint hit.  */
3106*ef5ccd6cSJohn Marino 	  ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_TRAP;
3107cf7f2e2dSJohn Marino 	  return 0;
3108cf7f2e2dSJohn Marino 	}
3109cf7f2e2dSJohn Marino     }
3110cf7f2e2dSJohn Marino 
3111cf7f2e2dSJohn Marino   /* If no catchpoint triggered for this, then keep going.  */
3112*ef5ccd6cSJohn Marino   ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0;
31135796c8dcSSimon Schubert   keep_going (ecs);
31145796c8dcSSimon Schubert   return 1;
31155796c8dcSSimon Schubert }
31165796c8dcSSimon Schubert 
3117a45ae5f8SJohn Marino /* Clear the supplied execution_control_state's stop_func_* fields.  */
3118a45ae5f8SJohn Marino 
3119a45ae5f8SJohn Marino static void
clear_stop_func(struct execution_control_state * ecs)3120a45ae5f8SJohn Marino clear_stop_func (struct execution_control_state *ecs)
3121a45ae5f8SJohn Marino {
3122a45ae5f8SJohn Marino   ecs->stop_func_filled_in = 0;
3123a45ae5f8SJohn Marino   ecs->stop_func_start = 0;
3124a45ae5f8SJohn Marino   ecs->stop_func_end = 0;
3125a45ae5f8SJohn Marino   ecs->stop_func_name = NULL;
3126a45ae5f8SJohn Marino }
3127a45ae5f8SJohn Marino 
3128a45ae5f8SJohn Marino /* Lazily fill in the execution_control_state's stop_func_* fields.  */
3129a45ae5f8SJohn Marino 
3130a45ae5f8SJohn Marino static void
fill_in_stop_func(struct gdbarch * gdbarch,struct execution_control_state * ecs)3131a45ae5f8SJohn Marino fill_in_stop_func (struct gdbarch *gdbarch,
3132a45ae5f8SJohn Marino 		   struct execution_control_state *ecs)
3133a45ae5f8SJohn Marino {
3134a45ae5f8SJohn Marino   if (!ecs->stop_func_filled_in)
3135a45ae5f8SJohn Marino     {
3136a45ae5f8SJohn Marino       /* Don't care about return value; stop_func_start and stop_func_name
3137a45ae5f8SJohn Marino 	 will both be 0 if it doesn't work.  */
3138a45ae5f8SJohn Marino       find_pc_partial_function (stop_pc, &ecs->stop_func_name,
3139a45ae5f8SJohn Marino 				&ecs->stop_func_start, &ecs->stop_func_end);
3140a45ae5f8SJohn Marino       ecs->stop_func_start
3141a45ae5f8SJohn Marino 	+= gdbarch_deprecated_function_start_offset (gdbarch);
3142a45ae5f8SJohn Marino 
3143a45ae5f8SJohn Marino       ecs->stop_func_filled_in = 1;
3144a45ae5f8SJohn Marino     }
3145a45ae5f8SJohn Marino }
3146a45ae5f8SJohn Marino 
31475796c8dcSSimon Schubert /* Given an execution control state that has been freshly filled in
31485796c8dcSSimon Schubert    by an event from the inferior, figure out what it means and take
31495796c8dcSSimon Schubert    appropriate action.  */
31505796c8dcSSimon Schubert 
31515796c8dcSSimon Schubert static void
handle_inferior_event(struct execution_control_state * ecs)31525796c8dcSSimon Schubert handle_inferior_event (struct execution_control_state *ecs)
31535796c8dcSSimon Schubert {
31545796c8dcSSimon Schubert   struct frame_info *frame;
31555796c8dcSSimon Schubert   struct gdbarch *gdbarch;
31565796c8dcSSimon Schubert   int stopped_by_watchpoint;
31575796c8dcSSimon Schubert   int stepped_after_stopped_by_watchpoint = 0;
31585796c8dcSSimon Schubert   struct symtab_and_line stop_pc_sal;
31595796c8dcSSimon Schubert   enum stop_kind stop_soon;
31605796c8dcSSimon Schubert 
3161cf7f2e2dSJohn Marino   if (ecs->ws.kind == TARGET_WAITKIND_IGNORE)
3162cf7f2e2dSJohn Marino     {
3163cf7f2e2dSJohn Marino       /* We had an event in the inferior, but we are not interested in
3164cf7f2e2dSJohn Marino 	 handling it at this level.  The lower layers have already
3165cf7f2e2dSJohn Marino 	 done what needs to be done, if anything.
3166cf7f2e2dSJohn Marino 
3167cf7f2e2dSJohn Marino 	 One of the possible circumstances for this is when the
3168cf7f2e2dSJohn Marino 	 inferior produces output for the console.  The inferior has
3169cf7f2e2dSJohn Marino 	 not stopped, and we are ignoring the event.  Another possible
3170cf7f2e2dSJohn Marino 	 circumstance is any event which the lower level knows will be
3171cf7f2e2dSJohn Marino 	 reported multiple times without an intervening resume.  */
3172cf7f2e2dSJohn Marino       if (debug_infrun)
3173cf7f2e2dSJohn Marino 	fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_IGNORE\n");
3174cf7f2e2dSJohn Marino       prepare_to_wait (ecs);
3175cf7f2e2dSJohn Marino       return;
3176cf7f2e2dSJohn Marino     }
3177cf7f2e2dSJohn Marino 
3178a45ae5f8SJohn Marino   if (ecs->ws.kind == TARGET_WAITKIND_NO_RESUMED
3179a45ae5f8SJohn Marino       && target_can_async_p () && !sync_execution)
3180a45ae5f8SJohn Marino     {
3181a45ae5f8SJohn Marino       /* There were no unwaited-for children left in the target, but,
3182a45ae5f8SJohn Marino 	 we're not synchronously waiting for events either.  Just
3183a45ae5f8SJohn Marino 	 ignore.  Otherwise, if we were running a synchronous
3184a45ae5f8SJohn Marino 	 execution command, we need to cancel it and give the user
3185a45ae5f8SJohn Marino 	 back the terminal.  */
3186a45ae5f8SJohn Marino       if (debug_infrun)
3187a45ae5f8SJohn Marino 	fprintf_unfiltered (gdb_stdlog,
3188a45ae5f8SJohn Marino 			    "infrun: TARGET_WAITKIND_NO_RESUMED (ignoring)\n");
3189a45ae5f8SJohn Marino       prepare_to_wait (ecs);
3190a45ae5f8SJohn Marino       return;
3191a45ae5f8SJohn Marino     }
3192a45ae5f8SJohn Marino 
31935796c8dcSSimon Schubert   if (ecs->ws.kind != TARGET_WAITKIND_EXITED
3194a45ae5f8SJohn Marino       && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED
3195a45ae5f8SJohn Marino       && ecs->ws.kind != TARGET_WAITKIND_NO_RESUMED)
31965796c8dcSSimon Schubert     {
31975796c8dcSSimon Schubert       struct inferior *inf = find_inferior_pid (ptid_get_pid (ecs->ptid));
3198cf7f2e2dSJohn Marino 
31995796c8dcSSimon Schubert       gdb_assert (inf);
3200c50c785cSJohn Marino       stop_soon = inf->control.stop_soon;
32015796c8dcSSimon Schubert     }
32025796c8dcSSimon Schubert   else
32035796c8dcSSimon Schubert     stop_soon = NO_STOP_QUIETLY;
32045796c8dcSSimon Schubert 
32055796c8dcSSimon Schubert   /* Cache the last pid/waitstatus.  */
32065796c8dcSSimon Schubert   target_last_wait_ptid = ecs->ptid;
32075796c8dcSSimon Schubert   target_last_waitstatus = ecs->ws;
32085796c8dcSSimon Schubert 
32095796c8dcSSimon Schubert   /* Always clear state belonging to the previous time we stopped.  */
3210cf7f2e2dSJohn Marino   stop_stack_dummy = STOP_NONE;
32115796c8dcSSimon Schubert 
3212a45ae5f8SJohn Marino   if (ecs->ws.kind == TARGET_WAITKIND_NO_RESUMED)
3213a45ae5f8SJohn Marino     {
3214a45ae5f8SJohn Marino       /* No unwaited-for children left.  IOW, all resumed children
3215a45ae5f8SJohn Marino 	 have exited.  */
3216a45ae5f8SJohn Marino       if (debug_infrun)
3217a45ae5f8SJohn Marino 	fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_NO_RESUMED\n");
3218a45ae5f8SJohn Marino 
3219a45ae5f8SJohn Marino       stop_print_frame = 0;
3220a45ae5f8SJohn Marino       stop_stepping (ecs);
3221a45ae5f8SJohn Marino       return;
3222a45ae5f8SJohn Marino     }
3223a45ae5f8SJohn Marino 
32245796c8dcSSimon Schubert   if (ecs->ws.kind != TARGET_WAITKIND_EXITED
3225*ef5ccd6cSJohn Marino       && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED)
3226*ef5ccd6cSJohn Marino     {
32275796c8dcSSimon Schubert       ecs->event_thread = find_thread_ptid (ecs->ptid);
3228*ef5ccd6cSJohn Marino       /* If it's a new thread, add it to the thread database.  */
3229*ef5ccd6cSJohn Marino       if (ecs->event_thread == NULL)
3230*ef5ccd6cSJohn Marino 	ecs->event_thread = add_thread (ecs->ptid);
3231*ef5ccd6cSJohn Marino     }
32325796c8dcSSimon Schubert 
32335796c8dcSSimon Schubert   /* Dependent on valid ECS->EVENT_THREAD.  */
32345796c8dcSSimon Schubert   adjust_pc_after_break (ecs);
32355796c8dcSSimon Schubert 
32365796c8dcSSimon Schubert   /* Dependent on the current PC value modified by adjust_pc_after_break.  */
32375796c8dcSSimon Schubert   reinit_frame_cache ();
32385796c8dcSSimon Schubert 
32395796c8dcSSimon Schubert   breakpoint_retire_moribund ();
32405796c8dcSSimon Schubert 
3241cf7f2e2dSJohn Marino   /* First, distinguish signals caused by the debugger from signals
3242cf7f2e2dSJohn Marino      that have to do with the program's own actions.  Note that
3243cf7f2e2dSJohn Marino      breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending
3244cf7f2e2dSJohn Marino      on the operating system version.  Here we detect when a SIGILL or
3245cf7f2e2dSJohn Marino      SIGEMT is really a breakpoint and change it to SIGTRAP.  We do
3246cf7f2e2dSJohn Marino      something similar for SIGSEGV, since a SIGSEGV will be generated
3247cf7f2e2dSJohn Marino      when we're trying to execute a breakpoint instruction on a
3248cf7f2e2dSJohn Marino      non-executable stack.  This happens for call dummy breakpoints
3249cf7f2e2dSJohn Marino      for architectures like SPARC that place call dummies on the
3250cf7f2e2dSJohn Marino      stack.  */
3251cf7f2e2dSJohn Marino   if (ecs->ws.kind == TARGET_WAITKIND_STOPPED
3252*ef5ccd6cSJohn Marino       && (ecs->ws.value.sig == GDB_SIGNAL_ILL
3253*ef5ccd6cSJohn Marino 	  || ecs->ws.value.sig == GDB_SIGNAL_SEGV
3254*ef5ccd6cSJohn Marino 	  || ecs->ws.value.sig == GDB_SIGNAL_EMT))
3255cf7f2e2dSJohn Marino     {
3256cf7f2e2dSJohn Marino       struct regcache *regcache = get_thread_regcache (ecs->ptid);
3257cf7f2e2dSJohn Marino 
3258cf7f2e2dSJohn Marino       if (breakpoint_inserted_here_p (get_regcache_aspace (regcache),
3259cf7f2e2dSJohn Marino 				      regcache_read_pc (regcache)))
3260cf7f2e2dSJohn Marino 	{
3261cf7f2e2dSJohn Marino 	  if (debug_infrun)
3262cf7f2e2dSJohn Marino 	    fprintf_unfiltered (gdb_stdlog,
3263cf7f2e2dSJohn Marino 				"infrun: Treating signal as SIGTRAP\n");
3264*ef5ccd6cSJohn Marino 	  ecs->ws.value.sig = GDB_SIGNAL_TRAP;
3265cf7f2e2dSJohn Marino 	}
3266cf7f2e2dSJohn Marino     }
3267cf7f2e2dSJohn Marino 
32685796c8dcSSimon Schubert   /* Mark the non-executing threads accordingly.  In all-stop, all
32695796c8dcSSimon Schubert      threads of all processes are stopped when we get any event
32705796c8dcSSimon Schubert      reported.  In non-stop mode, only the event thread stops.  If
3271cf7f2e2dSJohn Marino      we're handling a process exit in non-stop mode, there's nothing
3272cf7f2e2dSJohn Marino      to do, as threads of the dead process are gone, and threads of
3273cf7f2e2dSJohn Marino      any other process were left running.  */
32745796c8dcSSimon Schubert   if (!non_stop)
32755796c8dcSSimon Schubert     set_executing (minus_one_ptid, 0);
32765796c8dcSSimon Schubert   else if (ecs->ws.kind != TARGET_WAITKIND_SIGNALLED
32775796c8dcSSimon Schubert 	   && ecs->ws.kind != TARGET_WAITKIND_EXITED)
3278a45ae5f8SJohn Marino     set_executing (ecs->ptid, 0);
32795796c8dcSSimon Schubert 
32805796c8dcSSimon Schubert   switch (infwait_state)
32815796c8dcSSimon Schubert     {
32825796c8dcSSimon Schubert     case infwait_thread_hop_state:
32835796c8dcSSimon Schubert       if (debug_infrun)
32845796c8dcSSimon Schubert         fprintf_unfiltered (gdb_stdlog, "infrun: infwait_thread_hop_state\n");
32855796c8dcSSimon Schubert       break;
32865796c8dcSSimon Schubert 
32875796c8dcSSimon Schubert     case infwait_normal_state:
32885796c8dcSSimon Schubert       if (debug_infrun)
32895796c8dcSSimon Schubert         fprintf_unfiltered (gdb_stdlog, "infrun: infwait_normal_state\n");
32905796c8dcSSimon Schubert       break;
32915796c8dcSSimon Schubert 
32925796c8dcSSimon Schubert     case infwait_step_watch_state:
32935796c8dcSSimon Schubert       if (debug_infrun)
32945796c8dcSSimon Schubert         fprintf_unfiltered (gdb_stdlog,
32955796c8dcSSimon Schubert 			    "infrun: infwait_step_watch_state\n");
32965796c8dcSSimon Schubert 
32975796c8dcSSimon Schubert       stepped_after_stopped_by_watchpoint = 1;
32985796c8dcSSimon Schubert       break;
32995796c8dcSSimon Schubert 
33005796c8dcSSimon Schubert     case infwait_nonstep_watch_state:
33015796c8dcSSimon Schubert       if (debug_infrun)
33025796c8dcSSimon Schubert         fprintf_unfiltered (gdb_stdlog,
33035796c8dcSSimon Schubert 			    "infrun: infwait_nonstep_watch_state\n");
33045796c8dcSSimon Schubert       insert_breakpoints ();
33055796c8dcSSimon Schubert 
33065796c8dcSSimon Schubert       /* FIXME-maybe: is this cleaner than setting a flag?  Does it
33075796c8dcSSimon Schubert          handle things like signals arriving and other things happening
33085796c8dcSSimon Schubert          in combination correctly?  */
33095796c8dcSSimon Schubert       stepped_after_stopped_by_watchpoint = 1;
33105796c8dcSSimon Schubert       break;
33115796c8dcSSimon Schubert 
33125796c8dcSSimon Schubert     default:
33135796c8dcSSimon Schubert       internal_error (__FILE__, __LINE__, _("bad switch"));
33145796c8dcSSimon Schubert     }
33155796c8dcSSimon Schubert 
33165796c8dcSSimon Schubert   infwait_state = infwait_normal_state;
33175796c8dcSSimon Schubert   waiton_ptid = pid_to_ptid (-1);
33185796c8dcSSimon Schubert 
33195796c8dcSSimon Schubert   switch (ecs->ws.kind)
33205796c8dcSSimon Schubert     {
33215796c8dcSSimon Schubert     case TARGET_WAITKIND_LOADED:
33225796c8dcSSimon Schubert       if (debug_infrun)
33235796c8dcSSimon Schubert         fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_LOADED\n");
33245796c8dcSSimon Schubert       /* Ignore gracefully during startup of the inferior, as it might
33255796c8dcSSimon Schubert          be the shell which has just loaded some objects, otherwise
33265796c8dcSSimon Schubert          add the symbols for the newly loaded objects.  Also ignore at
33275796c8dcSSimon Schubert          the beginning of an attach or remote session; we will query
33285796c8dcSSimon Schubert          the full list of libraries once the connection is
33295796c8dcSSimon Schubert          established.  */
33305796c8dcSSimon Schubert       if (stop_soon == NO_STOP_QUIETLY)
33315796c8dcSSimon Schubert 	{
3332*ef5ccd6cSJohn Marino 	  struct regcache *regcache;
3333*ef5ccd6cSJohn Marino 	  enum bpstat_signal_value sval;
3334*ef5ccd6cSJohn Marino 
3335*ef5ccd6cSJohn Marino 	  if (!ptid_equal (ecs->ptid, inferior_ptid))
3336*ef5ccd6cSJohn Marino 	    context_switch (ecs->ptid);
3337*ef5ccd6cSJohn Marino 	  regcache = get_thread_regcache (ecs->ptid);
3338*ef5ccd6cSJohn Marino 
3339*ef5ccd6cSJohn Marino 	  handle_solib_event ();
3340*ef5ccd6cSJohn Marino 
3341*ef5ccd6cSJohn Marino 	  ecs->event_thread->control.stop_bpstat
3342*ef5ccd6cSJohn Marino 	    = bpstat_stop_status (get_regcache_aspace (regcache),
3343*ef5ccd6cSJohn Marino 				  stop_pc, ecs->ptid, &ecs->ws);
3344*ef5ccd6cSJohn Marino 
3345*ef5ccd6cSJohn Marino 	  sval
3346*ef5ccd6cSJohn Marino 	    = bpstat_explains_signal (ecs->event_thread->control.stop_bpstat,
3347*ef5ccd6cSJohn Marino 				      GDB_SIGNAL_TRAP);
3348*ef5ccd6cSJohn Marino 	  ecs->random_signal = sval == BPSTAT_SIGNAL_NO;
3349*ef5ccd6cSJohn Marino 
3350*ef5ccd6cSJohn Marino 	  if (!ecs->random_signal)
3351*ef5ccd6cSJohn Marino 	    {
3352*ef5ccd6cSJohn Marino 	      /* A catchpoint triggered.  */
3353*ef5ccd6cSJohn Marino 	      ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_TRAP;
3354*ef5ccd6cSJohn Marino 	      goto process_event_stop_test;
3355*ef5ccd6cSJohn Marino 	    }
33565796c8dcSSimon Schubert 
33575796c8dcSSimon Schubert 	  /* If requested, stop when the dynamic linker notifies
33585796c8dcSSimon Schubert 	     gdb of events.  This allows the user to get control
33595796c8dcSSimon Schubert 	     and place breakpoints in initializer routines for
33605796c8dcSSimon Schubert 	     dynamically loaded objects (among other things).  */
3361*ef5ccd6cSJohn Marino 	  ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0;
33625796c8dcSSimon Schubert 	  if (stop_on_solib_events)
33635796c8dcSSimon Schubert 	    {
3364cf7f2e2dSJohn Marino 	      /* Make sure we print "Stopped due to solib-event" in
3365cf7f2e2dSJohn Marino 		 normal_stop.  */
3366cf7f2e2dSJohn Marino 	      stop_print_frame = 1;
3367cf7f2e2dSJohn Marino 
33685796c8dcSSimon Schubert 	      stop_stepping (ecs);
33695796c8dcSSimon Schubert 	      return;
33705796c8dcSSimon Schubert 	    }
33715796c8dcSSimon Schubert 	}
33725796c8dcSSimon Schubert 
33735796c8dcSSimon Schubert       /* If we are skipping through a shell, or through shared library
33745796c8dcSSimon Schubert 	 loading that we aren't interested in, resume the program.  If
33755796c8dcSSimon Schubert 	 we're running the program normally, also resume.  But stop if
33765796c8dcSSimon Schubert 	 we're attaching or setting up a remote connection.  */
33775796c8dcSSimon Schubert       if (stop_soon == STOP_QUIETLY || stop_soon == NO_STOP_QUIETLY)
33785796c8dcSSimon Schubert 	{
3379*ef5ccd6cSJohn Marino 	  if (!ptid_equal (ecs->ptid, inferior_ptid))
3380*ef5ccd6cSJohn Marino 	    context_switch (ecs->ptid);
3381*ef5ccd6cSJohn Marino 
33825796c8dcSSimon Schubert 	  /* Loading of shared libraries might have changed breakpoint
33835796c8dcSSimon Schubert 	     addresses.  Make sure new breakpoints are inserted.  */
33845796c8dcSSimon Schubert 	  if (stop_soon == NO_STOP_QUIETLY
33855796c8dcSSimon Schubert 	      && !breakpoints_always_inserted_mode ())
33865796c8dcSSimon Schubert 	    insert_breakpoints ();
3387*ef5ccd6cSJohn Marino 	  resume (0, GDB_SIGNAL_0);
33885796c8dcSSimon Schubert 	  prepare_to_wait (ecs);
33895796c8dcSSimon Schubert 	  return;
33905796c8dcSSimon Schubert 	}
33915796c8dcSSimon Schubert 
33925796c8dcSSimon Schubert       break;
33935796c8dcSSimon Schubert 
33945796c8dcSSimon Schubert     case TARGET_WAITKIND_SPURIOUS:
33955796c8dcSSimon Schubert       if (debug_infrun)
33965796c8dcSSimon Schubert         fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SPURIOUS\n");
3397*ef5ccd6cSJohn Marino       if (!ptid_equal (ecs->ptid, inferior_ptid))
3398*ef5ccd6cSJohn Marino 	context_switch (ecs->ptid);
3399*ef5ccd6cSJohn Marino       resume (0, GDB_SIGNAL_0);
34005796c8dcSSimon Schubert       prepare_to_wait (ecs);
34015796c8dcSSimon Schubert       return;
34025796c8dcSSimon Schubert 
34035796c8dcSSimon Schubert     case TARGET_WAITKIND_EXITED:
3404*ef5ccd6cSJohn Marino     case TARGET_WAITKIND_SIGNALLED:
34055796c8dcSSimon Schubert       if (debug_infrun)
3406*ef5ccd6cSJohn Marino 	{
3407*ef5ccd6cSJohn Marino 	  if (ecs->ws.kind == TARGET_WAITKIND_EXITED)
3408*ef5ccd6cSJohn Marino 	    fprintf_unfiltered (gdb_stdlog,
3409*ef5ccd6cSJohn Marino 				"infrun: TARGET_WAITKIND_EXITED\n");
3410*ef5ccd6cSJohn Marino 	  else
3411*ef5ccd6cSJohn Marino 	    fprintf_unfiltered (gdb_stdlog,
3412*ef5ccd6cSJohn Marino 				"infrun: TARGET_WAITKIND_SIGNALLED\n");
3413*ef5ccd6cSJohn Marino 	}
3414*ef5ccd6cSJohn Marino 
34155796c8dcSSimon Schubert       inferior_ptid = ecs->ptid;
3416cf7f2e2dSJohn Marino       set_current_inferior (find_inferior_pid (ptid_get_pid (ecs->ptid)));
3417cf7f2e2dSJohn Marino       set_current_program_space (current_inferior ()->pspace);
3418cf7f2e2dSJohn Marino       handle_vfork_child_exec_or_exit (0);
3419c50c785cSJohn Marino       target_terminal_ours ();	/* Must do this before mourn anyway.  */
34205796c8dcSSimon Schubert 
3421*ef5ccd6cSJohn Marino       if (ecs->ws.kind == TARGET_WAITKIND_EXITED)
3422*ef5ccd6cSJohn Marino 	{
34235796c8dcSSimon Schubert 	  /* Record the exit code in the convenience variable $_exitcode, so
34245796c8dcSSimon Schubert 	     that the user can inspect this again later.  */
34255796c8dcSSimon Schubert 	  set_internalvar_integer (lookup_internalvar ("_exitcode"),
34265796c8dcSSimon Schubert 				   (LONGEST) ecs->ws.value.integer);
3427c50c785cSJohn Marino 
3428c50c785cSJohn Marino 	  /* Also record this in the inferior itself.  */
3429c50c785cSJohn Marino 	  current_inferior ()->has_exit_code = 1;
3430c50c785cSJohn Marino 	  current_inferior ()->exit_code = (LONGEST) ecs->ws.value.integer;
3431c50c785cSJohn Marino 
3432*ef5ccd6cSJohn Marino 	  print_exited_reason (ecs->ws.value.integer);
3433*ef5ccd6cSJohn Marino 	}
3434*ef5ccd6cSJohn Marino       else
3435*ef5ccd6cSJohn Marino 	print_signal_exited_reason (ecs->ws.value.sig);
3436*ef5ccd6cSJohn Marino 
34375796c8dcSSimon Schubert       gdb_flush (gdb_stdout);
34385796c8dcSSimon Schubert       target_mourn_inferior ();
34395796c8dcSSimon Schubert       singlestep_breakpoints_inserted_p = 0;
3440cf7f2e2dSJohn Marino       cancel_single_step_breakpoints ();
34415796c8dcSSimon Schubert       stop_print_frame = 0;
34425796c8dcSSimon Schubert       stop_stepping (ecs);
34435796c8dcSSimon Schubert       return;
34445796c8dcSSimon Schubert 
34455796c8dcSSimon Schubert       /* The following are the only cases in which we keep going;
34465796c8dcSSimon Schubert          the above cases end in a continue or goto.  */
34475796c8dcSSimon Schubert     case TARGET_WAITKIND_FORKED:
34485796c8dcSSimon Schubert     case TARGET_WAITKIND_VFORKED:
34495796c8dcSSimon Schubert       if (debug_infrun)
3450*ef5ccd6cSJohn Marino 	{
3451*ef5ccd6cSJohn Marino 	  if (ecs->ws.kind == TARGET_WAITKIND_FORKED)
34525796c8dcSSimon Schubert 	    fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_FORKED\n");
3453*ef5ccd6cSJohn Marino 	  else
3454*ef5ccd6cSJohn Marino 	    fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_VFORKED\n");
3455*ef5ccd6cSJohn Marino 	}
34565796c8dcSSimon Schubert 
3457a45ae5f8SJohn Marino       /* Check whether the inferior is displaced stepping.  */
3458a45ae5f8SJohn Marino       {
3459a45ae5f8SJohn Marino 	struct regcache *regcache = get_thread_regcache (ecs->ptid);
3460a45ae5f8SJohn Marino 	struct gdbarch *gdbarch = get_regcache_arch (regcache);
3461a45ae5f8SJohn Marino 	struct displaced_step_inferior_state *displaced
3462a45ae5f8SJohn Marino 	  = get_displaced_stepping_state (ptid_get_pid (ecs->ptid));
3463a45ae5f8SJohn Marino 
3464a45ae5f8SJohn Marino 	/* If checking displaced stepping is supported, and thread
3465a45ae5f8SJohn Marino 	   ecs->ptid is displaced stepping.  */
3466a45ae5f8SJohn Marino 	if (displaced && ptid_equal (displaced->step_ptid, ecs->ptid))
3467a45ae5f8SJohn Marino 	  {
3468a45ae5f8SJohn Marino 	    struct inferior *parent_inf
3469a45ae5f8SJohn Marino 	      = find_inferior_pid (ptid_get_pid (ecs->ptid));
3470a45ae5f8SJohn Marino 	    struct regcache *child_regcache;
3471a45ae5f8SJohn Marino 	    CORE_ADDR parent_pc;
3472a45ae5f8SJohn Marino 
3473a45ae5f8SJohn Marino 	    /* GDB has got TARGET_WAITKIND_FORKED or TARGET_WAITKIND_VFORKED,
3474a45ae5f8SJohn Marino 	       indicating that the displaced stepping of syscall instruction
3475a45ae5f8SJohn Marino 	       has been done.  Perform cleanup for parent process here.  Note
3476a45ae5f8SJohn Marino 	       that this operation also cleans up the child process for vfork,
3477a45ae5f8SJohn Marino 	       because their pages are shared.  */
3478*ef5ccd6cSJohn Marino 	    displaced_step_fixup (ecs->ptid, GDB_SIGNAL_TRAP);
3479a45ae5f8SJohn Marino 
3480a45ae5f8SJohn Marino 	    if (ecs->ws.kind == TARGET_WAITKIND_FORKED)
3481a45ae5f8SJohn Marino 	      {
3482a45ae5f8SJohn Marino 		/* Restore scratch pad for child process.  */
3483a45ae5f8SJohn Marino 		displaced_step_restore (displaced, ecs->ws.value.related_pid);
3484a45ae5f8SJohn Marino 	      }
3485a45ae5f8SJohn Marino 
3486a45ae5f8SJohn Marino 	    /* Since the vfork/fork syscall instruction was executed in the scratchpad,
3487a45ae5f8SJohn Marino 	       the child's PC is also within the scratchpad.  Set the child's PC
3488a45ae5f8SJohn Marino 	       to the parent's PC value, which has already been fixed up.
3489a45ae5f8SJohn Marino 	       FIXME: we use the parent's aspace here, although we're touching
3490a45ae5f8SJohn Marino 	       the child, because the child hasn't been added to the inferior
3491a45ae5f8SJohn Marino 	       list yet at this point.  */
3492a45ae5f8SJohn Marino 
3493a45ae5f8SJohn Marino 	    child_regcache
3494a45ae5f8SJohn Marino 	      = get_thread_arch_aspace_regcache (ecs->ws.value.related_pid,
3495a45ae5f8SJohn Marino 						 gdbarch,
3496a45ae5f8SJohn Marino 						 parent_inf->aspace);
3497a45ae5f8SJohn Marino 	    /* Read PC value of parent process.  */
3498a45ae5f8SJohn Marino 	    parent_pc = regcache_read_pc (regcache);
3499a45ae5f8SJohn Marino 
3500a45ae5f8SJohn Marino 	    if (debug_displaced)
3501a45ae5f8SJohn Marino 	      fprintf_unfiltered (gdb_stdlog,
3502a45ae5f8SJohn Marino 				  "displaced: write child pc from %s to %s\n",
3503a45ae5f8SJohn Marino 				  paddress (gdbarch,
3504a45ae5f8SJohn Marino 					    regcache_read_pc (child_regcache)),
3505a45ae5f8SJohn Marino 				  paddress (gdbarch, parent_pc));
3506a45ae5f8SJohn Marino 
3507a45ae5f8SJohn Marino 	    regcache_write_pc (child_regcache, parent_pc);
3508a45ae5f8SJohn Marino 	  }
3509a45ae5f8SJohn Marino       }
3510a45ae5f8SJohn Marino 
35115796c8dcSSimon Schubert       if (!ptid_equal (ecs->ptid, inferior_ptid))
35125796c8dcSSimon Schubert 	context_switch (ecs->ptid);
35135796c8dcSSimon Schubert 
35145796c8dcSSimon Schubert       /* Immediately detach breakpoints from the child before there's
35155796c8dcSSimon Schubert 	 any chance of letting the user delete breakpoints from the
35165796c8dcSSimon Schubert 	 breakpoint lists.  If we don't do this early, it's easy to
35175796c8dcSSimon Schubert 	 leave left over traps in the child, vis: "break foo; catch
35185796c8dcSSimon Schubert 	 fork; c; <fork>; del; c; <child calls foo>".  We only follow
35195796c8dcSSimon Schubert 	 the fork on the last `continue', and by that time the
35205796c8dcSSimon Schubert 	 breakpoint at "foo" is long gone from the breakpoint table.
35215796c8dcSSimon Schubert 	 If we vforked, then we don't need to unpatch here, since both
35225796c8dcSSimon Schubert 	 parent and child are sharing the same memory pages; we'll
35235796c8dcSSimon Schubert 	 need to unpatch at follow/detach time instead to be certain
35245796c8dcSSimon Schubert 	 that new breakpoints added between catchpoint hit time and
35255796c8dcSSimon Schubert 	 vfork follow are detached.  */
35265796c8dcSSimon Schubert       if (ecs->ws.kind != TARGET_WAITKIND_VFORKED)
35275796c8dcSSimon Schubert 	{
35285796c8dcSSimon Schubert 	  /* This won't actually modify the breakpoint list, but will
35295796c8dcSSimon Schubert 	     physically remove the breakpoints from the child.  */
3530*ef5ccd6cSJohn Marino 	  detach_breakpoints (ecs->ws.value.related_pid);
35315796c8dcSSimon Schubert 	}
35325796c8dcSSimon Schubert 
3533cf7f2e2dSJohn Marino       if (singlestep_breakpoints_inserted_p)
3534cf7f2e2dSJohn Marino 	{
3535cf7f2e2dSJohn Marino 	  /* Pull the single step breakpoints out of the target.  */
3536cf7f2e2dSJohn Marino 	  remove_single_step_breakpoints ();
3537cf7f2e2dSJohn Marino 	  singlestep_breakpoints_inserted_p = 0;
3538cf7f2e2dSJohn Marino 	}
3539cf7f2e2dSJohn Marino 
35405796c8dcSSimon Schubert       /* In case the event is caught by a catchpoint, remember that
35415796c8dcSSimon Schubert 	 the event is to be followed at the next resume of the thread,
35425796c8dcSSimon Schubert 	 and not immediately.  */
35435796c8dcSSimon Schubert       ecs->event_thread->pending_follow = ecs->ws;
35445796c8dcSSimon Schubert 
35455796c8dcSSimon Schubert       stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
35465796c8dcSSimon Schubert 
3547c50c785cSJohn Marino       ecs->event_thread->control.stop_bpstat
3548cf7f2e2dSJohn Marino 	= bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
3549*ef5ccd6cSJohn Marino 			      stop_pc, ecs->ptid, &ecs->ws);
35505796c8dcSSimon Schubert 
3551cf7f2e2dSJohn Marino       /* Note that we're interested in knowing the bpstat actually
3552cf7f2e2dSJohn Marino 	 causes a stop, not just if it may explain the signal.
3553cf7f2e2dSJohn Marino 	 Software watchpoints, for example, always appear in the
3554cf7f2e2dSJohn Marino 	 bpstat.  */
3555c50c785cSJohn Marino       ecs->random_signal
3556c50c785cSJohn Marino 	= !bpstat_causes_stop (ecs->event_thread->control.stop_bpstat);
35575796c8dcSSimon Schubert 
35585796c8dcSSimon Schubert       /* If no catchpoint triggered for this, then keep going.  */
35595796c8dcSSimon Schubert       if (ecs->random_signal)
35605796c8dcSSimon Schubert 	{
3561cf7f2e2dSJohn Marino 	  ptid_t parent;
3562cf7f2e2dSJohn Marino 	  ptid_t child;
35635796c8dcSSimon Schubert 	  int should_resume;
3564c50c785cSJohn Marino 	  int follow_child
3565c50c785cSJohn Marino 	    = (follow_fork_mode_string == follow_fork_mode_child);
35665796c8dcSSimon Schubert 
3567*ef5ccd6cSJohn Marino 	  ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0;
35685796c8dcSSimon Schubert 
35695796c8dcSSimon Schubert 	  should_resume = follow_fork ();
35705796c8dcSSimon Schubert 
3571cf7f2e2dSJohn Marino 	  parent = ecs->ptid;
3572cf7f2e2dSJohn Marino 	  child = ecs->ws.value.related_pid;
3573cf7f2e2dSJohn Marino 
3574cf7f2e2dSJohn Marino 	  /* In non-stop mode, also resume the other branch.  */
3575cf7f2e2dSJohn Marino 	  if (non_stop && !detach_fork)
3576cf7f2e2dSJohn Marino 	    {
3577cf7f2e2dSJohn Marino 	      if (follow_child)
3578cf7f2e2dSJohn Marino 		switch_to_thread (parent);
3579cf7f2e2dSJohn Marino 	      else
3580cf7f2e2dSJohn Marino 		switch_to_thread (child);
3581cf7f2e2dSJohn Marino 
3582cf7f2e2dSJohn Marino 	      ecs->event_thread = inferior_thread ();
3583cf7f2e2dSJohn Marino 	      ecs->ptid = inferior_ptid;
3584cf7f2e2dSJohn Marino 	      keep_going (ecs);
3585cf7f2e2dSJohn Marino 	    }
3586cf7f2e2dSJohn Marino 
3587cf7f2e2dSJohn Marino 	  if (follow_child)
3588cf7f2e2dSJohn Marino 	    switch_to_thread (child);
3589cf7f2e2dSJohn Marino 	  else
3590cf7f2e2dSJohn Marino 	    switch_to_thread (parent);
3591cf7f2e2dSJohn Marino 
35925796c8dcSSimon Schubert 	  ecs->event_thread = inferior_thread ();
35935796c8dcSSimon Schubert 	  ecs->ptid = inferior_ptid;
35945796c8dcSSimon Schubert 
35955796c8dcSSimon Schubert 	  if (should_resume)
35965796c8dcSSimon Schubert 	    keep_going (ecs);
35975796c8dcSSimon Schubert 	  else
35985796c8dcSSimon Schubert 	    stop_stepping (ecs);
35995796c8dcSSimon Schubert 	  return;
36005796c8dcSSimon Schubert 	}
3601*ef5ccd6cSJohn Marino       ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_TRAP;
36025796c8dcSSimon Schubert       goto process_event_stop_test;
36035796c8dcSSimon Schubert 
3604cf7f2e2dSJohn Marino     case TARGET_WAITKIND_VFORK_DONE:
3605cf7f2e2dSJohn Marino       /* Done with the shared memory region.  Re-insert breakpoints in
3606cf7f2e2dSJohn Marino 	 the parent, and keep going.  */
3607cf7f2e2dSJohn Marino 
3608cf7f2e2dSJohn Marino       if (debug_infrun)
3609c50c785cSJohn Marino 	fprintf_unfiltered (gdb_stdlog,
3610c50c785cSJohn Marino 			    "infrun: TARGET_WAITKIND_VFORK_DONE\n");
3611cf7f2e2dSJohn Marino 
3612cf7f2e2dSJohn Marino       if (!ptid_equal (ecs->ptid, inferior_ptid))
3613cf7f2e2dSJohn Marino 	context_switch (ecs->ptid);
3614cf7f2e2dSJohn Marino 
3615cf7f2e2dSJohn Marino       current_inferior ()->waiting_for_vfork_done = 0;
3616cf7f2e2dSJohn Marino       current_inferior ()->pspace->breakpoints_not_allowed = 0;
3617cf7f2e2dSJohn Marino       /* This also takes care of reinserting breakpoints in the
3618cf7f2e2dSJohn Marino 	 previously locked inferior.  */
3619cf7f2e2dSJohn Marino       keep_going (ecs);
3620cf7f2e2dSJohn Marino       return;
3621cf7f2e2dSJohn Marino 
36225796c8dcSSimon Schubert     case TARGET_WAITKIND_EXECD:
36235796c8dcSSimon Schubert       if (debug_infrun)
36245796c8dcSSimon Schubert         fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_EXECD\n");
36255796c8dcSSimon Schubert 
36265796c8dcSSimon Schubert       if (!ptid_equal (ecs->ptid, inferior_ptid))
36275796c8dcSSimon Schubert 	context_switch (ecs->ptid);
36285796c8dcSSimon Schubert 
3629cf7f2e2dSJohn Marino       singlestep_breakpoints_inserted_p = 0;
3630cf7f2e2dSJohn Marino       cancel_single_step_breakpoints ();
3631cf7f2e2dSJohn Marino 
36325796c8dcSSimon Schubert       stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
36335796c8dcSSimon Schubert 
3634cf7f2e2dSJohn Marino       /* Do whatever is necessary to the parent branch of the vfork.  */
3635cf7f2e2dSJohn Marino       handle_vfork_child_exec_or_exit (1);
3636cf7f2e2dSJohn Marino 
36375796c8dcSSimon Schubert       /* This causes the eventpoints and symbol table to be reset.
36385796c8dcSSimon Schubert          Must do this now, before trying to determine whether to
36395796c8dcSSimon Schubert          stop.  */
36405796c8dcSSimon Schubert       follow_exec (inferior_ptid, ecs->ws.value.execd_pathname);
36415796c8dcSSimon Schubert 
3642c50c785cSJohn Marino       ecs->event_thread->control.stop_bpstat
3643cf7f2e2dSJohn Marino 	= bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
3644*ef5ccd6cSJohn Marino 			      stop_pc, ecs->ptid, &ecs->ws);
3645c50c785cSJohn Marino       ecs->random_signal
3646*ef5ccd6cSJohn Marino 	= (bpstat_explains_signal (ecs->event_thread->control.stop_bpstat,
3647*ef5ccd6cSJohn Marino 				   GDB_SIGNAL_TRAP)
3648*ef5ccd6cSJohn Marino 	   == BPSTAT_SIGNAL_NO);
36495796c8dcSSimon Schubert 
36505796c8dcSSimon Schubert       /* Note that this may be referenced from inside
36515796c8dcSSimon Schubert 	 bpstat_stop_status above, through inferior_has_execd.  */
36525796c8dcSSimon Schubert       xfree (ecs->ws.value.execd_pathname);
36535796c8dcSSimon Schubert       ecs->ws.value.execd_pathname = NULL;
36545796c8dcSSimon Schubert 
36555796c8dcSSimon Schubert       /* If no catchpoint triggered for this, then keep going.  */
36565796c8dcSSimon Schubert       if (ecs->random_signal)
36575796c8dcSSimon Schubert 	{
3658*ef5ccd6cSJohn Marino 	  ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0;
36595796c8dcSSimon Schubert 	  keep_going (ecs);
36605796c8dcSSimon Schubert 	  return;
36615796c8dcSSimon Schubert 	}
3662*ef5ccd6cSJohn Marino       ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_TRAP;
36635796c8dcSSimon Schubert       goto process_event_stop_test;
36645796c8dcSSimon Schubert 
36655796c8dcSSimon Schubert       /* Be careful not to try to gather much state about a thread
36665796c8dcSSimon Schubert          that's in a syscall.  It's frequently a losing proposition.  */
36675796c8dcSSimon Schubert     case TARGET_WAITKIND_SYSCALL_ENTRY:
36685796c8dcSSimon Schubert       if (debug_infrun)
3669c50c785cSJohn Marino         fprintf_unfiltered (gdb_stdlog,
3670c50c785cSJohn Marino 			    "infrun: TARGET_WAITKIND_SYSCALL_ENTRY\n");
3671c50c785cSJohn Marino       /* Getting the current syscall number.  */
3672cf7f2e2dSJohn Marino       if (handle_syscall_event (ecs) != 0)
36735796c8dcSSimon Schubert         return;
36745796c8dcSSimon Schubert       goto process_event_stop_test;
36755796c8dcSSimon Schubert 
36765796c8dcSSimon Schubert       /* Before examining the threads further, step this thread to
36775796c8dcSSimon Schubert          get it entirely out of the syscall.  (We get notice of the
36785796c8dcSSimon Schubert          event when the thread is just on the verge of exiting a
36795796c8dcSSimon Schubert          syscall.  Stepping one instruction seems to get it back
36805796c8dcSSimon Schubert          into user code.)  */
36815796c8dcSSimon Schubert     case TARGET_WAITKIND_SYSCALL_RETURN:
36825796c8dcSSimon Schubert       if (debug_infrun)
3683c50c785cSJohn Marino         fprintf_unfiltered (gdb_stdlog,
3684c50c785cSJohn Marino 			    "infrun: TARGET_WAITKIND_SYSCALL_RETURN\n");
3685cf7f2e2dSJohn Marino       if (handle_syscall_event (ecs) != 0)
36865796c8dcSSimon Schubert         return;
36875796c8dcSSimon Schubert       goto process_event_stop_test;
36885796c8dcSSimon Schubert 
36895796c8dcSSimon Schubert     case TARGET_WAITKIND_STOPPED:
36905796c8dcSSimon Schubert       if (debug_infrun)
36915796c8dcSSimon Schubert         fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_STOPPED\n");
3692c50c785cSJohn Marino       ecs->event_thread->suspend.stop_signal = ecs->ws.value.sig;
36935796c8dcSSimon Schubert       break;
36945796c8dcSSimon Schubert 
36955796c8dcSSimon Schubert     case TARGET_WAITKIND_NO_HISTORY:
3696a45ae5f8SJohn Marino       if (debug_infrun)
3697a45ae5f8SJohn Marino         fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_NO_HISTORY\n");
36985796c8dcSSimon Schubert       /* Reverse execution: target ran out of history info.  */
3699*ef5ccd6cSJohn Marino 
3700*ef5ccd6cSJohn Marino       /* Pull the single step breakpoints out of the target.  */
3701*ef5ccd6cSJohn Marino       if (singlestep_breakpoints_inserted_p)
3702*ef5ccd6cSJohn Marino 	{
3703*ef5ccd6cSJohn Marino 	  if (!ptid_equal (ecs->ptid, inferior_ptid))
3704*ef5ccd6cSJohn Marino 	    context_switch (ecs->ptid);
3705*ef5ccd6cSJohn Marino 	  remove_single_step_breakpoints ();
3706*ef5ccd6cSJohn Marino 	  singlestep_breakpoints_inserted_p = 0;
3707*ef5ccd6cSJohn Marino 	}
37085796c8dcSSimon Schubert       stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
3709c50c785cSJohn Marino       print_no_history_reason ();
37105796c8dcSSimon Schubert       stop_stepping (ecs);
37115796c8dcSSimon Schubert       return;
37125796c8dcSSimon Schubert     }
37135796c8dcSSimon Schubert 
37145796c8dcSSimon Schubert   if (ecs->ws.kind == TARGET_WAITKIND_STOPPED)
37155796c8dcSSimon Schubert     {
37165796c8dcSSimon Schubert       /* Do we need to clean up the state of a thread that has
37175796c8dcSSimon Schubert 	 completed a displaced single-step?  (Doing so usually affects
37185796c8dcSSimon Schubert 	 the PC, so do it here, before we set stop_pc.)  */
3719c50c785cSJohn Marino       displaced_step_fixup (ecs->ptid,
3720c50c785cSJohn Marino 			    ecs->event_thread->suspend.stop_signal);
37215796c8dcSSimon Schubert 
37225796c8dcSSimon Schubert       /* If we either finished a single-step or hit a breakpoint, but
37235796c8dcSSimon Schubert 	 the user wanted this thread to be stopped, pretend we got a
37245796c8dcSSimon Schubert 	 SIG0 (generic unsignaled stop).  */
37255796c8dcSSimon Schubert 
37265796c8dcSSimon Schubert       if (ecs->event_thread->stop_requested
3727*ef5ccd6cSJohn Marino 	  && ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP)
3728*ef5ccd6cSJohn Marino 	ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0;
37295796c8dcSSimon Schubert     }
37305796c8dcSSimon Schubert 
37315796c8dcSSimon Schubert   stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
37325796c8dcSSimon Schubert 
37335796c8dcSSimon Schubert   if (debug_infrun)
37345796c8dcSSimon Schubert     {
37355796c8dcSSimon Schubert       struct regcache *regcache = get_thread_regcache (ecs->ptid);
37365796c8dcSSimon Schubert       struct gdbarch *gdbarch = get_regcache_arch (regcache);
3737cf7f2e2dSJohn Marino       struct cleanup *old_chain = save_inferior_ptid ();
3738cf7f2e2dSJohn Marino 
3739cf7f2e2dSJohn Marino       inferior_ptid = ecs->ptid;
37405796c8dcSSimon Schubert 
37415796c8dcSSimon Schubert       fprintf_unfiltered (gdb_stdlog, "infrun: stop_pc = %s\n",
37425796c8dcSSimon Schubert                           paddress (gdbarch, stop_pc));
37435796c8dcSSimon Schubert       if (target_stopped_by_watchpoint ())
37445796c8dcSSimon Schubert 	{
37455796c8dcSSimon Schubert           CORE_ADDR addr;
3746cf7f2e2dSJohn Marino 
37475796c8dcSSimon Schubert 	  fprintf_unfiltered (gdb_stdlog, "infrun: stopped by watchpoint\n");
37485796c8dcSSimon Schubert 
37495796c8dcSSimon Schubert           if (target_stopped_data_address (&current_target, &addr))
37505796c8dcSSimon Schubert             fprintf_unfiltered (gdb_stdlog,
37515796c8dcSSimon Schubert                                 "infrun: stopped data address = %s\n",
37525796c8dcSSimon Schubert                                 paddress (gdbarch, addr));
37535796c8dcSSimon Schubert           else
37545796c8dcSSimon Schubert             fprintf_unfiltered (gdb_stdlog,
37555796c8dcSSimon Schubert                                 "infrun: (no data address available)\n");
37565796c8dcSSimon Schubert 	}
3757cf7f2e2dSJohn Marino 
3758cf7f2e2dSJohn Marino       do_cleanups (old_chain);
37595796c8dcSSimon Schubert     }
37605796c8dcSSimon Schubert 
37615796c8dcSSimon Schubert   if (stepping_past_singlestep_breakpoint)
37625796c8dcSSimon Schubert     {
37635796c8dcSSimon Schubert       gdb_assert (singlestep_breakpoints_inserted_p);
37645796c8dcSSimon Schubert       gdb_assert (ptid_equal (singlestep_ptid, ecs->ptid));
37655796c8dcSSimon Schubert       gdb_assert (!ptid_equal (singlestep_ptid, saved_singlestep_ptid));
37665796c8dcSSimon Schubert 
37675796c8dcSSimon Schubert       stepping_past_singlestep_breakpoint = 0;
37685796c8dcSSimon Schubert 
37695796c8dcSSimon Schubert       /* We've either finished single-stepping past the single-step
37705796c8dcSSimon Schubert          breakpoint, or stopped for some other reason.  It would be nice if
37715796c8dcSSimon Schubert          we could tell, but we can't reliably.  */
3772*ef5ccd6cSJohn Marino       if (ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP)
37735796c8dcSSimon Schubert 	{
37745796c8dcSSimon Schubert 	  if (debug_infrun)
3775c50c785cSJohn Marino 	    fprintf_unfiltered (gdb_stdlog,
3776c50c785cSJohn Marino 				"infrun: stepping_past_"
3777c50c785cSJohn Marino 				"singlestep_breakpoint\n");
37785796c8dcSSimon Schubert 	  /* Pull the single step breakpoints out of the target.  */
3779*ef5ccd6cSJohn Marino 	  if (!ptid_equal (ecs->ptid, inferior_ptid))
3780*ef5ccd6cSJohn Marino 	    context_switch (ecs->ptid);
37815796c8dcSSimon Schubert 	  remove_single_step_breakpoints ();
37825796c8dcSSimon Schubert 	  singlestep_breakpoints_inserted_p = 0;
37835796c8dcSSimon Schubert 
37845796c8dcSSimon Schubert 	  ecs->random_signal = 0;
3785c50c785cSJohn Marino 	  ecs->event_thread->control.trap_expected = 0;
37865796c8dcSSimon Schubert 
37875796c8dcSSimon Schubert 	  context_switch (saved_singlestep_ptid);
37885796c8dcSSimon Schubert 	  if (deprecated_context_hook)
3789*ef5ccd6cSJohn Marino 	    deprecated_context_hook (pid_to_thread_id (saved_singlestep_ptid));
37905796c8dcSSimon Schubert 
3791*ef5ccd6cSJohn Marino 	  resume (1, GDB_SIGNAL_0);
37925796c8dcSSimon Schubert 	  prepare_to_wait (ecs);
37935796c8dcSSimon Schubert 	  return;
37945796c8dcSSimon Schubert 	}
37955796c8dcSSimon Schubert     }
37965796c8dcSSimon Schubert 
37975796c8dcSSimon Schubert   if (!ptid_equal (deferred_step_ptid, null_ptid))
37985796c8dcSSimon Schubert     {
37995796c8dcSSimon Schubert       /* In non-stop mode, there's never a deferred_step_ptid set.  */
38005796c8dcSSimon Schubert       gdb_assert (!non_stop);
38015796c8dcSSimon Schubert 
38025796c8dcSSimon Schubert       /* If we stopped for some other reason than single-stepping, ignore
38035796c8dcSSimon Schubert 	 the fact that we were supposed to switch back.  */
3804*ef5ccd6cSJohn Marino       if (ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP)
38055796c8dcSSimon Schubert 	{
38065796c8dcSSimon Schubert 	  if (debug_infrun)
38075796c8dcSSimon Schubert 	    fprintf_unfiltered (gdb_stdlog,
38085796c8dcSSimon Schubert 				"infrun: handling deferred step\n");
38095796c8dcSSimon Schubert 
38105796c8dcSSimon Schubert 	  /* Pull the single step breakpoints out of the target.  */
38115796c8dcSSimon Schubert 	  if (singlestep_breakpoints_inserted_p)
38125796c8dcSSimon Schubert 	    {
3813*ef5ccd6cSJohn Marino 	      if (!ptid_equal (ecs->ptid, inferior_ptid))
3814*ef5ccd6cSJohn Marino 		context_switch (ecs->ptid);
38155796c8dcSSimon Schubert 	      remove_single_step_breakpoints ();
38165796c8dcSSimon Schubert 	      singlestep_breakpoints_inserted_p = 0;
38175796c8dcSSimon Schubert 	    }
38185796c8dcSSimon Schubert 
3819a45ae5f8SJohn Marino 	  ecs->event_thread->control.trap_expected = 0;
3820a45ae5f8SJohn Marino 
3821*ef5ccd6cSJohn Marino 	  context_switch (deferred_step_ptid);
38225796c8dcSSimon Schubert 	  deferred_step_ptid = null_ptid;
38235796c8dcSSimon Schubert 	  /* Suppress spurious "Switching to ..." message.  */
38245796c8dcSSimon Schubert 	  previous_inferior_ptid = inferior_ptid;
38255796c8dcSSimon Schubert 
3826*ef5ccd6cSJohn Marino 	  resume (1, GDB_SIGNAL_0);
38275796c8dcSSimon Schubert 	  prepare_to_wait (ecs);
38285796c8dcSSimon Schubert 	  return;
38295796c8dcSSimon Schubert 	}
38305796c8dcSSimon Schubert 
38315796c8dcSSimon Schubert       deferred_step_ptid = null_ptid;
38325796c8dcSSimon Schubert     }
38335796c8dcSSimon Schubert 
38345796c8dcSSimon Schubert   /* See if a thread hit a thread-specific breakpoint that was meant for
38355796c8dcSSimon Schubert      another thread.  If so, then step that thread past the breakpoint,
38365796c8dcSSimon Schubert      and continue it.  */
38375796c8dcSSimon Schubert 
3838*ef5ccd6cSJohn Marino   if (ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP)
38395796c8dcSSimon Schubert     {
38405796c8dcSSimon Schubert       int thread_hop_needed = 0;
3841cf7f2e2dSJohn Marino       struct address_space *aspace =
3842cf7f2e2dSJohn Marino 	get_regcache_aspace (get_thread_regcache (ecs->ptid));
38435796c8dcSSimon Schubert 
38445796c8dcSSimon Schubert       /* Check if a regular breakpoint has been hit before checking
38455796c8dcSSimon Schubert          for a potential single step breakpoint.  Otherwise, GDB will
38465796c8dcSSimon Schubert          not see this breakpoint hit when stepping onto breakpoints.  */
3847cf7f2e2dSJohn Marino       if (regular_breakpoint_inserted_here_p (aspace, stop_pc))
38485796c8dcSSimon Schubert 	{
38495796c8dcSSimon Schubert 	  ecs->random_signal = 0;
3850cf7f2e2dSJohn Marino 	  if (!breakpoint_thread_match (aspace, stop_pc, ecs->ptid))
38515796c8dcSSimon Schubert 	    thread_hop_needed = 1;
38525796c8dcSSimon Schubert 	}
38535796c8dcSSimon Schubert       else if (singlestep_breakpoints_inserted_p)
38545796c8dcSSimon Schubert 	{
38555796c8dcSSimon Schubert 	  /* We have not context switched yet, so this should be true
38565796c8dcSSimon Schubert 	     no matter which thread hit the singlestep breakpoint.  */
38575796c8dcSSimon Schubert 	  gdb_assert (ptid_equal (inferior_ptid, singlestep_ptid));
38585796c8dcSSimon Schubert 	  if (debug_infrun)
38595796c8dcSSimon Schubert 	    fprintf_unfiltered (gdb_stdlog, "infrun: software single step "
38605796c8dcSSimon Schubert 				"trap for %s\n",
38615796c8dcSSimon Schubert 				target_pid_to_str (ecs->ptid));
38625796c8dcSSimon Schubert 
38635796c8dcSSimon Schubert 	  ecs->random_signal = 0;
38645796c8dcSSimon Schubert 	  /* The call to in_thread_list is necessary because PTIDs sometimes
38655796c8dcSSimon Schubert 	     change when we go from single-threaded to multi-threaded.  If
38665796c8dcSSimon Schubert 	     the singlestep_ptid is still in the list, assume that it is
38675796c8dcSSimon Schubert 	     really different from ecs->ptid.  */
38685796c8dcSSimon Schubert 	  if (!ptid_equal (singlestep_ptid, ecs->ptid)
38695796c8dcSSimon Schubert 	      && in_thread_list (singlestep_ptid))
38705796c8dcSSimon Schubert 	    {
38715796c8dcSSimon Schubert 	      /* If the PC of the thread we were trying to single-step
38725796c8dcSSimon Schubert 		 has changed, discard this event (which we were going
38735796c8dcSSimon Schubert 		 to ignore anyway), and pretend we saw that thread
38745796c8dcSSimon Schubert 		 trap.  This prevents us continuously moving the
38755796c8dcSSimon Schubert 		 single-step breakpoint forward, one instruction at a
38765796c8dcSSimon Schubert 		 time.  If the PC has changed, then the thread we were
38775796c8dcSSimon Schubert 		 trying to single-step has trapped or been signalled,
38785796c8dcSSimon Schubert 		 but the event has not been reported to GDB yet.
38795796c8dcSSimon Schubert 
38805796c8dcSSimon Schubert 		 There might be some cases where this loses signal
38815796c8dcSSimon Schubert 		 information, if a signal has arrived at exactly the
38825796c8dcSSimon Schubert 		 same time that the PC changed, but this is the best
38835796c8dcSSimon Schubert 		 we can do with the information available.  Perhaps we
38845796c8dcSSimon Schubert 		 should arrange to report all events for all threads
38855796c8dcSSimon Schubert 		 when they stop, or to re-poll the remote looking for
38865796c8dcSSimon Schubert 		 this particular thread (i.e. temporarily enable
38875796c8dcSSimon Schubert 		 schedlock).  */
38885796c8dcSSimon Schubert 
38895796c8dcSSimon Schubert 	     CORE_ADDR new_singlestep_pc
38905796c8dcSSimon Schubert 	       = regcache_read_pc (get_thread_regcache (singlestep_ptid));
38915796c8dcSSimon Schubert 
38925796c8dcSSimon Schubert 	     if (new_singlestep_pc != singlestep_pc)
38935796c8dcSSimon Schubert 	       {
3894*ef5ccd6cSJohn Marino 		 enum gdb_signal stop_signal;
38955796c8dcSSimon Schubert 
38965796c8dcSSimon Schubert 		 if (debug_infrun)
38975796c8dcSSimon Schubert 		   fprintf_unfiltered (gdb_stdlog, "infrun: unexpected thread,"
38985796c8dcSSimon Schubert 				       " but expected thread advanced also\n");
38995796c8dcSSimon Schubert 
39005796c8dcSSimon Schubert 		 /* The current context still belongs to
39015796c8dcSSimon Schubert 		    singlestep_ptid.  Don't swap here, since that's
39025796c8dcSSimon Schubert 		    the context we want to use.  Just fudge our
39035796c8dcSSimon Schubert 		    state and continue.  */
3904c50c785cSJohn Marino                  stop_signal = ecs->event_thread->suspend.stop_signal;
3905*ef5ccd6cSJohn Marino                  ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0;
39065796c8dcSSimon Schubert                  ecs->ptid = singlestep_ptid;
39075796c8dcSSimon Schubert                  ecs->event_thread = find_thread_ptid (ecs->ptid);
3908c50c785cSJohn Marino                  ecs->event_thread->suspend.stop_signal = stop_signal;
39095796c8dcSSimon Schubert                  stop_pc = new_singlestep_pc;
39105796c8dcSSimon Schubert                }
39115796c8dcSSimon Schubert              else
39125796c8dcSSimon Schubert 	       {
39135796c8dcSSimon Schubert 		 if (debug_infrun)
39145796c8dcSSimon Schubert 		   fprintf_unfiltered (gdb_stdlog,
39155796c8dcSSimon Schubert 				       "infrun: unexpected thread\n");
39165796c8dcSSimon Schubert 
39175796c8dcSSimon Schubert 		 thread_hop_needed = 1;
39185796c8dcSSimon Schubert 		 stepping_past_singlestep_breakpoint = 1;
39195796c8dcSSimon Schubert 		 saved_singlestep_ptid = singlestep_ptid;
39205796c8dcSSimon Schubert 	       }
39215796c8dcSSimon Schubert 	    }
39225796c8dcSSimon Schubert 	}
39235796c8dcSSimon Schubert 
39245796c8dcSSimon Schubert       if (thread_hop_needed)
39255796c8dcSSimon Schubert 	{
39265796c8dcSSimon Schubert 	  struct regcache *thread_regcache;
39275796c8dcSSimon Schubert 	  int remove_status = 0;
39285796c8dcSSimon Schubert 
39295796c8dcSSimon Schubert 	  if (debug_infrun)
39305796c8dcSSimon Schubert 	    fprintf_unfiltered (gdb_stdlog, "infrun: thread_hop_needed\n");
39315796c8dcSSimon Schubert 
39325796c8dcSSimon Schubert 	  /* Switch context before touching inferior memory, the
39335796c8dcSSimon Schubert 	     previous thread may have exited.  */
39345796c8dcSSimon Schubert 	  if (!ptid_equal (inferior_ptid, ecs->ptid))
39355796c8dcSSimon Schubert 	    context_switch (ecs->ptid);
39365796c8dcSSimon Schubert 
39375796c8dcSSimon Schubert 	  /* Saw a breakpoint, but it was hit by the wrong thread.
39385796c8dcSSimon Schubert 	     Just continue.  */
39395796c8dcSSimon Schubert 
39405796c8dcSSimon Schubert 	  if (singlestep_breakpoints_inserted_p)
39415796c8dcSSimon Schubert 	    {
39425796c8dcSSimon Schubert 	      /* Pull the single step breakpoints out of the target.  */
39435796c8dcSSimon Schubert 	      remove_single_step_breakpoints ();
39445796c8dcSSimon Schubert 	      singlestep_breakpoints_inserted_p = 0;
39455796c8dcSSimon Schubert 	    }
39465796c8dcSSimon Schubert 
39475796c8dcSSimon Schubert 	  /* If the arch can displace step, don't remove the
39485796c8dcSSimon Schubert 	     breakpoints.  */
39495796c8dcSSimon Schubert 	  thread_regcache = get_thread_regcache (ecs->ptid);
39505796c8dcSSimon Schubert 	  if (!use_displaced_stepping (get_regcache_arch (thread_regcache)))
39515796c8dcSSimon Schubert 	    remove_status = remove_breakpoints ();
39525796c8dcSSimon Schubert 
39535796c8dcSSimon Schubert 	  /* Did we fail to remove breakpoints?  If so, try
39545796c8dcSSimon Schubert 	     to set the PC past the bp.  (There's at least
39555796c8dcSSimon Schubert 	     one situation in which we can fail to remove
39565796c8dcSSimon Schubert 	     the bp's: On HP-UX's that use ttrace, we can't
39575796c8dcSSimon Schubert 	     change the address space of a vforking child
39585796c8dcSSimon Schubert 	     process until the child exits (well, okay, not
39595796c8dcSSimon Schubert 	     then either :-) or execs.  */
39605796c8dcSSimon Schubert 	  if (remove_status != 0)
39615796c8dcSSimon Schubert 	    error (_("Cannot step over breakpoint hit in wrong thread"));
39625796c8dcSSimon Schubert 	  else
39635796c8dcSSimon Schubert 	    {			/* Single step */
39645796c8dcSSimon Schubert 	      if (!non_stop)
39655796c8dcSSimon Schubert 		{
39665796c8dcSSimon Schubert 		  /* Only need to require the next event from this
39675796c8dcSSimon Schubert 		     thread in all-stop mode.  */
39685796c8dcSSimon Schubert 		  waiton_ptid = ecs->ptid;
39695796c8dcSSimon Schubert 		  infwait_state = infwait_thread_hop_state;
39705796c8dcSSimon Schubert 		}
39715796c8dcSSimon Schubert 
39725796c8dcSSimon Schubert 	      ecs->event_thread->stepping_over_breakpoint = 1;
39735796c8dcSSimon Schubert 	      keep_going (ecs);
39745796c8dcSSimon Schubert 	      return;
39755796c8dcSSimon Schubert 	    }
39765796c8dcSSimon Schubert 	}
39775796c8dcSSimon Schubert       else if (singlestep_breakpoints_inserted_p)
39785796c8dcSSimon Schubert 	{
39795796c8dcSSimon Schubert 	  ecs->random_signal = 0;
39805796c8dcSSimon Schubert 	}
39815796c8dcSSimon Schubert     }
39825796c8dcSSimon Schubert   else
39835796c8dcSSimon Schubert     ecs->random_signal = 1;
39845796c8dcSSimon Schubert 
39855796c8dcSSimon Schubert   /* See if something interesting happened to the non-current thread.  If
39865796c8dcSSimon Schubert      so, then switch to that thread.  */
39875796c8dcSSimon Schubert   if (!ptid_equal (ecs->ptid, inferior_ptid))
39885796c8dcSSimon Schubert     {
39895796c8dcSSimon Schubert       if (debug_infrun)
39905796c8dcSSimon Schubert 	fprintf_unfiltered (gdb_stdlog, "infrun: context switch\n");
39915796c8dcSSimon Schubert 
39925796c8dcSSimon Schubert       context_switch (ecs->ptid);
39935796c8dcSSimon Schubert 
39945796c8dcSSimon Schubert       if (deprecated_context_hook)
39955796c8dcSSimon Schubert 	deprecated_context_hook (pid_to_thread_id (ecs->ptid));
39965796c8dcSSimon Schubert     }
39975796c8dcSSimon Schubert 
39985796c8dcSSimon Schubert   /* At this point, get hold of the now-current thread's frame.  */
39995796c8dcSSimon Schubert   frame = get_current_frame ();
40005796c8dcSSimon Schubert   gdbarch = get_frame_arch (frame);
40015796c8dcSSimon Schubert 
40025796c8dcSSimon Schubert   if (singlestep_breakpoints_inserted_p)
40035796c8dcSSimon Schubert     {
40045796c8dcSSimon Schubert       /* Pull the single step breakpoints out of the target.  */
40055796c8dcSSimon Schubert       remove_single_step_breakpoints ();
40065796c8dcSSimon Schubert       singlestep_breakpoints_inserted_p = 0;
40075796c8dcSSimon Schubert     }
40085796c8dcSSimon Schubert 
40095796c8dcSSimon Schubert   if (stepped_after_stopped_by_watchpoint)
40105796c8dcSSimon Schubert     stopped_by_watchpoint = 0;
40115796c8dcSSimon Schubert   else
40125796c8dcSSimon Schubert     stopped_by_watchpoint = watchpoints_triggered (&ecs->ws);
40135796c8dcSSimon Schubert 
40145796c8dcSSimon Schubert   /* If necessary, step over this watchpoint.  We'll be back to display
40155796c8dcSSimon Schubert      it in a moment.  */
40165796c8dcSSimon Schubert   if (stopped_by_watchpoint
40175796c8dcSSimon Schubert       && (target_have_steppable_watchpoint
40185796c8dcSSimon Schubert 	  || gdbarch_have_nonsteppable_watchpoint (gdbarch)))
40195796c8dcSSimon Schubert     {
40205796c8dcSSimon Schubert       /* At this point, we are stopped at an instruction which has
40215796c8dcSSimon Schubert          attempted to write to a piece of memory under control of
40225796c8dcSSimon Schubert          a watchpoint.  The instruction hasn't actually executed
40235796c8dcSSimon Schubert          yet.  If we were to evaluate the watchpoint expression
40245796c8dcSSimon Schubert          now, we would get the old value, and therefore no change
40255796c8dcSSimon Schubert          would seem to have occurred.
40265796c8dcSSimon Schubert 
40275796c8dcSSimon Schubert          In order to make watchpoints work `right', we really need
40285796c8dcSSimon Schubert          to complete the memory write, and then evaluate the
40295796c8dcSSimon Schubert          watchpoint expression.  We do this by single-stepping the
40305796c8dcSSimon Schubert 	 target.
40315796c8dcSSimon Schubert 
40325796c8dcSSimon Schubert 	 It may not be necessary to disable the watchpoint to stop over
40335796c8dcSSimon Schubert 	 it.  For example, the PA can (with some kernel cooperation)
40345796c8dcSSimon Schubert 	 single step over a watchpoint without disabling the watchpoint.
40355796c8dcSSimon Schubert 
40365796c8dcSSimon Schubert 	 It is far more common to need to disable a watchpoint to step
40375796c8dcSSimon Schubert 	 the inferior over it.  If we have non-steppable watchpoints,
40385796c8dcSSimon Schubert 	 we must disable the current watchpoint; it's simplest to
40395796c8dcSSimon Schubert 	 disable all watchpoints and breakpoints.  */
40405796c8dcSSimon Schubert       int hw_step = 1;
40415796c8dcSSimon Schubert 
40425796c8dcSSimon Schubert       if (!target_have_steppable_watchpoint)
4043a45ae5f8SJohn Marino 	{
40445796c8dcSSimon Schubert 	  remove_breakpoints ();
4045a45ae5f8SJohn Marino 	  /* See comment in resume why we need to stop bypassing signals
4046a45ae5f8SJohn Marino 	     while breakpoints have been removed.  */
4047a45ae5f8SJohn Marino 	  target_pass_signals (0, NULL);
4048a45ae5f8SJohn Marino 	}
40495796c8dcSSimon Schubert 	/* Single step */
40505796c8dcSSimon Schubert       hw_step = maybe_software_singlestep (gdbarch, stop_pc);
4051*ef5ccd6cSJohn Marino       target_resume (ecs->ptid, hw_step, GDB_SIGNAL_0);
40525796c8dcSSimon Schubert       waiton_ptid = ecs->ptid;
40535796c8dcSSimon Schubert       if (target_have_steppable_watchpoint)
40545796c8dcSSimon Schubert 	infwait_state = infwait_step_watch_state;
40555796c8dcSSimon Schubert       else
40565796c8dcSSimon Schubert 	infwait_state = infwait_nonstep_watch_state;
40575796c8dcSSimon Schubert       prepare_to_wait (ecs);
40585796c8dcSSimon Schubert       return;
40595796c8dcSSimon Schubert     }
40605796c8dcSSimon Schubert 
4061a45ae5f8SJohn Marino   clear_stop_func (ecs);
40625796c8dcSSimon Schubert   ecs->event_thread->stepping_over_breakpoint = 0;
4063c50c785cSJohn Marino   bpstat_clear (&ecs->event_thread->control.stop_bpstat);
4064c50c785cSJohn Marino   ecs->event_thread->control.stop_step = 0;
40655796c8dcSSimon Schubert   stop_print_frame = 1;
40665796c8dcSSimon Schubert   ecs->random_signal = 0;
40675796c8dcSSimon Schubert   stopped_by_random_signal = 0;
40685796c8dcSSimon Schubert 
40695796c8dcSSimon Schubert   /* Hide inlined functions starting here, unless we just performed stepi or
40705796c8dcSSimon Schubert      nexti.  After stepi and nexti, always show the innermost frame (not any
40715796c8dcSSimon Schubert      inline function call sites).  */
4072c50c785cSJohn Marino   if (ecs->event_thread->control.step_range_end != 1)
4073a45ae5f8SJohn Marino     {
4074a45ae5f8SJohn Marino       struct address_space *aspace =
4075a45ae5f8SJohn Marino 	get_regcache_aspace (get_thread_regcache (ecs->ptid));
4076a45ae5f8SJohn Marino 
4077a45ae5f8SJohn Marino       /* skip_inline_frames is expensive, so we avoid it if we can
4078a45ae5f8SJohn Marino 	 determine that the address is one where functions cannot have
4079a45ae5f8SJohn Marino 	 been inlined.  This improves performance with inferiors that
4080a45ae5f8SJohn Marino 	 load a lot of shared libraries, because the solib event
4081a45ae5f8SJohn Marino 	 breakpoint is defined as the address of a function (i.e. not
4082a45ae5f8SJohn Marino 	 inline).  Note that we have to check the previous PC as well
4083a45ae5f8SJohn Marino 	 as the current one to catch cases when we have just
4084a45ae5f8SJohn Marino 	 single-stepped off a breakpoint prior to reinstating it.
4085a45ae5f8SJohn Marino 	 Note that we're assuming that the code we single-step to is
4086a45ae5f8SJohn Marino 	 not inline, but that's not definitive: there's nothing
4087a45ae5f8SJohn Marino 	 preventing the event breakpoint function from containing
4088a45ae5f8SJohn Marino 	 inlined code, and the single-step ending up there.  If the
4089a45ae5f8SJohn Marino 	 user had set a breakpoint on that inlined code, the missing
4090a45ae5f8SJohn Marino 	 skip_inline_frames call would break things.  Fortunately
4091a45ae5f8SJohn Marino 	 that's an extremely unlikely scenario.  */
4092*ef5ccd6cSJohn Marino       if (!pc_at_non_inline_function (aspace, stop_pc, &ecs->ws)
4093*ef5ccd6cSJohn Marino 	  && !(ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP
4094a45ae5f8SJohn Marino 	       && ecs->event_thread->control.trap_expected
4095a45ae5f8SJohn Marino 	       && pc_at_non_inline_function (aspace,
4096*ef5ccd6cSJohn Marino 					     ecs->event_thread->prev_pc,
4097*ef5ccd6cSJohn Marino 					     &ecs->ws)))
4098*ef5ccd6cSJohn Marino 	{
40995796c8dcSSimon Schubert 	  skip_inline_frames (ecs->ptid);
4100*ef5ccd6cSJohn Marino 
4101*ef5ccd6cSJohn Marino 	  /* Re-fetch current thread's frame in case that invalidated
4102*ef5ccd6cSJohn Marino 	     the frame cache.  */
4103*ef5ccd6cSJohn Marino 	  frame = get_current_frame ();
4104*ef5ccd6cSJohn Marino 	  gdbarch = get_frame_arch (frame);
4105*ef5ccd6cSJohn Marino 	}
4106a45ae5f8SJohn Marino     }
41075796c8dcSSimon Schubert 
4108*ef5ccd6cSJohn Marino   if (ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP
4109c50c785cSJohn Marino       && ecs->event_thread->control.trap_expected
41105796c8dcSSimon Schubert       && gdbarch_single_step_through_delay_p (gdbarch)
41115796c8dcSSimon Schubert       && currently_stepping (ecs->event_thread))
41125796c8dcSSimon Schubert     {
41135796c8dcSSimon Schubert       /* We're trying to step off a breakpoint.  Turns out that we're
41145796c8dcSSimon Schubert 	 also on an instruction that needs to be stepped multiple
41155796c8dcSSimon Schubert 	 times before it's been fully executing.  E.g., architectures
41165796c8dcSSimon Schubert 	 with a delay slot.  It needs to be stepped twice, once for
41175796c8dcSSimon Schubert 	 the instruction and once for the delay slot.  */
41185796c8dcSSimon Schubert       int step_through_delay
41195796c8dcSSimon Schubert 	= gdbarch_single_step_through_delay (gdbarch, frame);
4120cf7f2e2dSJohn Marino 
41215796c8dcSSimon Schubert       if (debug_infrun && step_through_delay)
41225796c8dcSSimon Schubert 	fprintf_unfiltered (gdb_stdlog, "infrun: step through delay\n");
4123c50c785cSJohn Marino       if (ecs->event_thread->control.step_range_end == 0
4124c50c785cSJohn Marino 	  && step_through_delay)
41255796c8dcSSimon Schubert 	{
41265796c8dcSSimon Schubert 	  /* The user issued a continue when stopped at a breakpoint.
41275796c8dcSSimon Schubert 	     Set up for another trap and get out of here.  */
41285796c8dcSSimon Schubert          ecs->event_thread->stepping_over_breakpoint = 1;
41295796c8dcSSimon Schubert          keep_going (ecs);
41305796c8dcSSimon Schubert          return;
41315796c8dcSSimon Schubert 	}
41325796c8dcSSimon Schubert       else if (step_through_delay)
41335796c8dcSSimon Schubert 	{
41345796c8dcSSimon Schubert 	  /* The user issued a step when stopped at a breakpoint.
41355796c8dcSSimon Schubert 	     Maybe we should stop, maybe we should not - the delay
41365796c8dcSSimon Schubert 	     slot *might* correspond to a line of source.  In any
41375796c8dcSSimon Schubert 	     case, don't decide that here, just set
41385796c8dcSSimon Schubert 	     ecs->stepping_over_breakpoint, making sure we
41395796c8dcSSimon Schubert 	     single-step again before breakpoints are re-inserted.  */
41405796c8dcSSimon Schubert 	  ecs->event_thread->stepping_over_breakpoint = 1;
41415796c8dcSSimon Schubert 	}
41425796c8dcSSimon Schubert     }
41435796c8dcSSimon Schubert 
41445796c8dcSSimon Schubert   /* Look at the cause of the stop, and decide what to do.
41455796c8dcSSimon Schubert      The alternatives are:
41465796c8dcSSimon Schubert      1) stop_stepping and return; to really stop and return to the debugger,
41475796c8dcSSimon Schubert      2) keep_going and return to start up again
41485796c8dcSSimon Schubert      (set ecs->event_thread->stepping_over_breakpoint to 1 to single step once)
41495796c8dcSSimon Schubert      3) set ecs->random_signal to 1, and the decision between 1 and 2
41505796c8dcSSimon Schubert      will be made according to the signal handling tables.  */
41515796c8dcSSimon Schubert 
4152*ef5ccd6cSJohn Marino   if (ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP
4153c50c785cSJohn Marino       && stop_after_trap)
41545796c8dcSSimon Schubert     {
41555796c8dcSSimon Schubert       if (debug_infrun)
41565796c8dcSSimon Schubert 	fprintf_unfiltered (gdb_stdlog, "infrun: stopped\n");
41575796c8dcSSimon Schubert       stop_print_frame = 0;
41585796c8dcSSimon Schubert       stop_stepping (ecs);
41595796c8dcSSimon Schubert       return;
41605796c8dcSSimon Schubert     }
41615796c8dcSSimon Schubert 
41625796c8dcSSimon Schubert   /* This is originated from start_remote(), start_inferior() and
41635796c8dcSSimon Schubert      shared libraries hook functions.  */
41645796c8dcSSimon Schubert   if (stop_soon == STOP_QUIETLY || stop_soon == STOP_QUIETLY_REMOTE)
41655796c8dcSSimon Schubert     {
41665796c8dcSSimon Schubert       if (debug_infrun)
41675796c8dcSSimon Schubert 	fprintf_unfiltered (gdb_stdlog, "infrun: quietly stopped\n");
41685796c8dcSSimon Schubert       stop_stepping (ecs);
41695796c8dcSSimon Schubert       return;
41705796c8dcSSimon Schubert     }
41715796c8dcSSimon Schubert 
41725796c8dcSSimon Schubert   /* This originates from attach_command().  We need to overwrite
41735796c8dcSSimon Schubert      the stop_signal here, because some kernels don't ignore a
41745796c8dcSSimon Schubert      SIGSTOP in a subsequent ptrace(PTRACE_CONT,SIGSTOP) call.
41755796c8dcSSimon Schubert      See more comments in inferior.h.  On the other hand, if we
41765796c8dcSSimon Schubert      get a non-SIGSTOP, report it to the user - assume the backend
41775796c8dcSSimon Schubert      will handle the SIGSTOP if it should show up later.
41785796c8dcSSimon Schubert 
41795796c8dcSSimon Schubert      Also consider that the attach is complete when we see a
41805796c8dcSSimon Schubert      SIGTRAP.  Some systems (e.g. Windows), and stubs supporting
41815796c8dcSSimon Schubert      target extended-remote report it instead of a SIGSTOP
41825796c8dcSSimon Schubert      (e.g. gdbserver).  We already rely on SIGTRAP being our
41835796c8dcSSimon Schubert      signal, so this is no exception.
41845796c8dcSSimon Schubert 
41855796c8dcSSimon Schubert      Also consider that the attach is complete when we see a
4186*ef5ccd6cSJohn Marino      GDB_SIGNAL_0.  In non-stop mode, GDB will explicitly tell
41875796c8dcSSimon Schubert      the target to stop all threads of the inferior, in case the
41885796c8dcSSimon Schubert      low level attach operation doesn't stop them implicitly.  If
41895796c8dcSSimon Schubert      they weren't stopped implicitly, then the stub will report a
4190*ef5ccd6cSJohn Marino      GDB_SIGNAL_0, meaning: stopped for no particular reason
41915796c8dcSSimon Schubert      other than GDB's request.  */
41925796c8dcSSimon Schubert   if (stop_soon == STOP_QUIETLY_NO_SIGSTOP
4193*ef5ccd6cSJohn Marino       && (ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_STOP
4194*ef5ccd6cSJohn Marino 	  || ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP
4195*ef5ccd6cSJohn Marino 	  || ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_0))
41965796c8dcSSimon Schubert     {
41975796c8dcSSimon Schubert       stop_stepping (ecs);
4198*ef5ccd6cSJohn Marino       ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0;
41995796c8dcSSimon Schubert       return;
42005796c8dcSSimon Schubert     }
42015796c8dcSSimon Schubert 
4202*ef5ccd6cSJohn Marino   /* See if there is a breakpoint/watchpoint/catchpoint/etc. that
4203*ef5ccd6cSJohn Marino      handles this event.  */
4204c50c785cSJohn Marino   ecs->event_thread->control.stop_bpstat
4205cf7f2e2dSJohn Marino     = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
4206*ef5ccd6cSJohn Marino 			  stop_pc, ecs->ptid, &ecs->ws);
42075796c8dcSSimon Schubert 
42085796c8dcSSimon Schubert   /* Following in case break condition called a
42095796c8dcSSimon Schubert      function.  */
42105796c8dcSSimon Schubert   stop_print_frame = 1;
42115796c8dcSSimon Schubert 
4212cf7f2e2dSJohn Marino   /* This is where we handle "moribund" watchpoints.  Unlike
4213cf7f2e2dSJohn Marino      software breakpoints traps, hardware watchpoint traps are
4214cf7f2e2dSJohn Marino      always distinguishable from random traps.  If no high-level
4215cf7f2e2dSJohn Marino      watchpoint is associated with the reported stop data address
4216cf7f2e2dSJohn Marino      anymore, then the bpstat does not explain the signal ---
4217cf7f2e2dSJohn Marino      simply make sure to ignore it if `stopped_by_watchpoint' is
4218cf7f2e2dSJohn Marino      set.  */
4219cf7f2e2dSJohn Marino 
4220cf7f2e2dSJohn Marino   if (debug_infrun
4221*ef5ccd6cSJohn Marino       && ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP
4222*ef5ccd6cSJohn Marino       && (bpstat_explains_signal (ecs->event_thread->control.stop_bpstat,
4223*ef5ccd6cSJohn Marino 				  GDB_SIGNAL_TRAP)
4224*ef5ccd6cSJohn Marino 	  == BPSTAT_SIGNAL_NO)
4225cf7f2e2dSJohn Marino       && stopped_by_watchpoint)
4226c50c785cSJohn Marino     fprintf_unfiltered (gdb_stdlog,
4227c50c785cSJohn Marino 			"infrun: no user watchpoint explains "
4228c50c785cSJohn Marino 			"watchpoint SIGTRAP, ignoring\n");
4229cf7f2e2dSJohn Marino 
42305796c8dcSSimon Schubert   /* NOTE: cagney/2003-03-29: These two checks for a random signal
42315796c8dcSSimon Schubert      at one stage in the past included checks for an inferior
42325796c8dcSSimon Schubert      function call's call dummy's return breakpoint.  The original
42335796c8dcSSimon Schubert      comment, that went with the test, read:
42345796c8dcSSimon Schubert 
42355796c8dcSSimon Schubert      ``End of a stack dummy.  Some systems (e.g. Sony news) give
42365796c8dcSSimon Schubert      another signal besides SIGTRAP, so check here as well as
42375796c8dcSSimon Schubert      above.''
42385796c8dcSSimon Schubert 
42395796c8dcSSimon Schubert      If someone ever tries to get call dummys on a
42405796c8dcSSimon Schubert      non-executable stack to work (where the target would stop
42415796c8dcSSimon Schubert      with something like a SIGSEGV), then those tests might need
42425796c8dcSSimon Schubert      to be re-instated.  Given, however, that the tests were only
42435796c8dcSSimon Schubert      enabled when momentary breakpoints were not being used, I
42445796c8dcSSimon Schubert      suspect that it won't be the case.
42455796c8dcSSimon Schubert 
42465796c8dcSSimon Schubert      NOTE: kettenis/2004-02-05: Indeed such checks don't seem to
42475796c8dcSSimon Schubert      be necessary for call dummies on a non-executable stack on
42485796c8dcSSimon Schubert      SPARC.  */
42495796c8dcSSimon Schubert 
4250*ef5ccd6cSJohn Marino   if (ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP)
42515796c8dcSSimon Schubert     ecs->random_signal
4252*ef5ccd6cSJohn Marino       = !((bpstat_explains_signal (ecs->event_thread->control.stop_bpstat,
4253*ef5ccd6cSJohn Marino 				   GDB_SIGNAL_TRAP)
4254*ef5ccd6cSJohn Marino 	   != BPSTAT_SIGNAL_NO)
4255cf7f2e2dSJohn Marino 	  || stopped_by_watchpoint
4256c50c785cSJohn Marino 	  || ecs->event_thread->control.trap_expected
4257c50c785cSJohn Marino 	  || (ecs->event_thread->control.step_range_end
4258c50c785cSJohn Marino 	      && (ecs->event_thread->control.step_resume_breakpoint
4259c50c785cSJohn Marino 		  == NULL)));
42605796c8dcSSimon Schubert   else
42615796c8dcSSimon Schubert     {
4262*ef5ccd6cSJohn Marino       enum bpstat_signal_value sval;
42635796c8dcSSimon Schubert 
4264*ef5ccd6cSJohn Marino       sval = bpstat_explains_signal (ecs->event_thread->control.stop_bpstat,
4265*ef5ccd6cSJohn Marino 				     ecs->event_thread->suspend.stop_signal);
4266*ef5ccd6cSJohn Marino       ecs->random_signal = (sval == BPSTAT_SIGNAL_NO);
42675796c8dcSSimon Schubert 
4268*ef5ccd6cSJohn Marino       if (sval == BPSTAT_SIGNAL_HIDE)
4269*ef5ccd6cSJohn Marino 	ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_TRAP;
4270*ef5ccd6cSJohn Marino     }
42715796c8dcSSimon Schubert 
42725796c8dcSSimon Schubert process_event_stop_test:
42735796c8dcSSimon Schubert 
42745796c8dcSSimon Schubert   /* Re-fetch current thread's frame in case we did a
42755796c8dcSSimon Schubert      "goto process_event_stop_test" above.  */
42765796c8dcSSimon Schubert   frame = get_current_frame ();
42775796c8dcSSimon Schubert   gdbarch = get_frame_arch (frame);
42785796c8dcSSimon Schubert 
42795796c8dcSSimon Schubert   /* For the program's own signals, act according to
42805796c8dcSSimon Schubert      the signal handling tables.  */
42815796c8dcSSimon Schubert 
42825796c8dcSSimon Schubert   if (ecs->random_signal)
42835796c8dcSSimon Schubert     {
42845796c8dcSSimon Schubert       /* Signal not for debugging purposes.  */
42855796c8dcSSimon Schubert       int printed = 0;
4286cf7f2e2dSJohn Marino       struct inferior *inf = find_inferior_pid (ptid_get_pid (ecs->ptid));
42875796c8dcSSimon Schubert 
42885796c8dcSSimon Schubert       if (debug_infrun)
42895796c8dcSSimon Schubert 	 fprintf_unfiltered (gdb_stdlog, "infrun: random signal %d\n",
4290c50c785cSJohn Marino 			     ecs->event_thread->suspend.stop_signal);
42915796c8dcSSimon Schubert 
42925796c8dcSSimon Schubert       stopped_by_random_signal = 1;
42935796c8dcSSimon Schubert 
4294c50c785cSJohn Marino       if (signal_print[ecs->event_thread->suspend.stop_signal])
42955796c8dcSSimon Schubert 	{
42965796c8dcSSimon Schubert 	  printed = 1;
42975796c8dcSSimon Schubert 	  target_terminal_ours_for_output ();
4298c50c785cSJohn Marino 	  print_signal_received_reason
4299c50c785cSJohn Marino 				     (ecs->event_thread->suspend.stop_signal);
43005796c8dcSSimon Schubert 	}
43015796c8dcSSimon Schubert       /* Always stop on signals if we're either just gaining control
43025796c8dcSSimon Schubert 	 of the program, or the user explicitly requested this thread
43035796c8dcSSimon Schubert 	 to remain stopped.  */
43045796c8dcSSimon Schubert       if (stop_soon != NO_STOP_QUIETLY
43055796c8dcSSimon Schubert 	  || ecs->event_thread->stop_requested
4306cf7f2e2dSJohn Marino 	  || (!inf->detaching
4307c50c785cSJohn Marino 	      && signal_stop_state (ecs->event_thread->suspend.stop_signal)))
43085796c8dcSSimon Schubert 	{
43095796c8dcSSimon Schubert 	  stop_stepping (ecs);
43105796c8dcSSimon Schubert 	  return;
43115796c8dcSSimon Schubert 	}
43125796c8dcSSimon Schubert       /* If not going to stop, give terminal back
43135796c8dcSSimon Schubert          if we took it away.  */
43145796c8dcSSimon Schubert       else if (printed)
43155796c8dcSSimon Schubert 	target_terminal_inferior ();
43165796c8dcSSimon Schubert 
43175796c8dcSSimon Schubert       /* Clear the signal if it should not be passed.  */
4318c50c785cSJohn Marino       if (signal_program[ecs->event_thread->suspend.stop_signal] == 0)
4319*ef5ccd6cSJohn Marino 	ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0;
43205796c8dcSSimon Schubert 
43215796c8dcSSimon Schubert       if (ecs->event_thread->prev_pc == stop_pc
4322c50c785cSJohn Marino 	  && ecs->event_thread->control.trap_expected
4323c50c785cSJohn Marino 	  && ecs->event_thread->control.step_resume_breakpoint == NULL)
43245796c8dcSSimon Schubert 	{
43255796c8dcSSimon Schubert 	  /* We were just starting a new sequence, attempting to
43265796c8dcSSimon Schubert 	     single-step off of a breakpoint and expecting a SIGTRAP.
43275796c8dcSSimon Schubert 	     Instead this signal arrives.  This signal will take us out
43285796c8dcSSimon Schubert 	     of the stepping range so GDB needs to remember to, when
43295796c8dcSSimon Schubert 	     the signal handler returns, resume stepping off that
43305796c8dcSSimon Schubert 	     breakpoint.  */
43315796c8dcSSimon Schubert 	  /* To simplify things, "continue" is forced to use the same
43325796c8dcSSimon Schubert 	     code paths as single-step - set a breakpoint at the
43335796c8dcSSimon Schubert 	     signal return address and then, once hit, step off that
43345796c8dcSSimon Schubert 	     breakpoint.  */
43355796c8dcSSimon Schubert           if (debug_infrun)
43365796c8dcSSimon Schubert             fprintf_unfiltered (gdb_stdlog,
43375796c8dcSSimon Schubert                                 "infrun: signal arrived while stepping over "
43385796c8dcSSimon Schubert                                 "breakpoint\n");
43395796c8dcSSimon Schubert 
4340a45ae5f8SJohn Marino 	  insert_hp_step_resume_breakpoint_at_frame (frame);
43415796c8dcSSimon Schubert 	  ecs->event_thread->step_after_step_resume_breakpoint = 1;
4342a45ae5f8SJohn Marino 	  /* Reset trap_expected to ensure breakpoints are re-inserted.  */
4343a45ae5f8SJohn Marino 	  ecs->event_thread->control.trap_expected = 0;
43445796c8dcSSimon Schubert 	  keep_going (ecs);
43455796c8dcSSimon Schubert 	  return;
43465796c8dcSSimon Schubert 	}
43475796c8dcSSimon Schubert 
4348c50c785cSJohn Marino       if (ecs->event_thread->control.step_range_end != 0
4349*ef5ccd6cSJohn Marino 	  && ecs->event_thread->suspend.stop_signal != GDB_SIGNAL_0
4350c50c785cSJohn Marino 	  && (ecs->event_thread->control.step_range_start <= stop_pc
4351c50c785cSJohn Marino 	      && stop_pc < ecs->event_thread->control.step_range_end)
43525796c8dcSSimon Schubert 	  && frame_id_eq (get_stack_frame_id (frame),
4353c50c785cSJohn Marino 			  ecs->event_thread->control.step_stack_frame_id)
4354c50c785cSJohn Marino 	  && ecs->event_thread->control.step_resume_breakpoint == NULL)
43555796c8dcSSimon Schubert 	{
43565796c8dcSSimon Schubert 	  /* The inferior is about to take a signal that will take it
43575796c8dcSSimon Schubert 	     out of the single step range.  Set a breakpoint at the
43585796c8dcSSimon Schubert 	     current PC (which is presumably where the signal handler
43595796c8dcSSimon Schubert 	     will eventually return) and then allow the inferior to
43605796c8dcSSimon Schubert 	     run free.
43615796c8dcSSimon Schubert 
43625796c8dcSSimon Schubert 	     Note that this is only needed for a signal delivered
43635796c8dcSSimon Schubert 	     while in the single-step range.  Nested signals aren't a
43645796c8dcSSimon Schubert 	     problem as they eventually all return.  */
43655796c8dcSSimon Schubert           if (debug_infrun)
43665796c8dcSSimon Schubert             fprintf_unfiltered (gdb_stdlog,
43675796c8dcSSimon Schubert                                 "infrun: signal may take us out of "
43685796c8dcSSimon Schubert                                 "single-step range\n");
43695796c8dcSSimon Schubert 
4370a45ae5f8SJohn Marino 	  insert_hp_step_resume_breakpoint_at_frame (frame);
4371a45ae5f8SJohn Marino 	  /* Reset trap_expected to ensure breakpoints are re-inserted.  */
4372a45ae5f8SJohn Marino 	  ecs->event_thread->control.trap_expected = 0;
43735796c8dcSSimon Schubert 	  keep_going (ecs);
43745796c8dcSSimon Schubert 	  return;
43755796c8dcSSimon Schubert 	}
43765796c8dcSSimon Schubert 
43775796c8dcSSimon Schubert       /* Note: step_resume_breakpoint may be non-NULL.  This occures
43785796c8dcSSimon Schubert 	 when either there's a nested signal, or when there's a
43795796c8dcSSimon Schubert 	 pending signal enabled just as the signal handler returns
43805796c8dcSSimon Schubert 	 (leaving the inferior at the step-resume-breakpoint without
43815796c8dcSSimon Schubert 	 actually executing it).  Either way continue until the
43825796c8dcSSimon Schubert 	 breakpoint is really hit.  */
43835796c8dcSSimon Schubert     }
4384*ef5ccd6cSJohn Marino   else
43855796c8dcSSimon Schubert     {
4386*ef5ccd6cSJohn Marino       /* Handle cases caused by hitting a breakpoint.  */
4387*ef5ccd6cSJohn Marino 
43885796c8dcSSimon Schubert       CORE_ADDR jmp_buf_pc;
43895796c8dcSSimon Schubert       struct bpstat_what what;
43905796c8dcSSimon Schubert 
4391c50c785cSJohn Marino       what = bpstat_what (ecs->event_thread->control.stop_bpstat);
43925796c8dcSSimon Schubert 
43935796c8dcSSimon Schubert       if (what.call_dummy)
43945796c8dcSSimon Schubert 	{
4395cf7f2e2dSJohn Marino 	  stop_stack_dummy = what.call_dummy;
43965796c8dcSSimon Schubert 	}
43975796c8dcSSimon Schubert 
4398cf7f2e2dSJohn Marino       /* If we hit an internal event that triggers symbol changes, the
4399*ef5ccd6cSJohn Marino 	 current frame will be invalidated within bpstat_what (e.g.,
4400*ef5ccd6cSJohn Marino 	 if we hit an internal solib event).  Re-fetch it.  */
4401cf7f2e2dSJohn Marino       frame = get_current_frame ();
4402cf7f2e2dSJohn Marino       gdbarch = get_frame_arch (frame);
4403cf7f2e2dSJohn Marino 
44045796c8dcSSimon Schubert       switch (what.main_action)
44055796c8dcSSimon Schubert 	{
44065796c8dcSSimon Schubert 	case BPSTAT_WHAT_SET_LONGJMP_RESUME:
44075796c8dcSSimon Schubert 	  /* If we hit the breakpoint at longjmp while stepping, we
44085796c8dcSSimon Schubert 	     install a momentary breakpoint at the target of the
44095796c8dcSSimon Schubert 	     jmp_buf.  */
44105796c8dcSSimon Schubert 
44115796c8dcSSimon Schubert 	  if (debug_infrun)
44125796c8dcSSimon Schubert 	    fprintf_unfiltered (gdb_stdlog,
44135796c8dcSSimon Schubert 				"infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME\n");
44145796c8dcSSimon Schubert 
44155796c8dcSSimon Schubert 	  ecs->event_thread->stepping_over_breakpoint = 1;
44165796c8dcSSimon Schubert 
4417c50c785cSJohn Marino 	  if (what.is_longjmp)
4418c50c785cSJohn Marino 	    {
4419*ef5ccd6cSJohn Marino 	      struct value *arg_value;
4420*ef5ccd6cSJohn Marino 
4421*ef5ccd6cSJohn Marino 	      /* If we set the longjmp breakpoint via a SystemTap
4422*ef5ccd6cSJohn Marino 		 probe, then use it to extract the arguments.  The
4423*ef5ccd6cSJohn Marino 		 destination PC is the third argument to the
4424*ef5ccd6cSJohn Marino 		 probe.  */
4425*ef5ccd6cSJohn Marino 	      arg_value = probe_safe_evaluate_at_pc (frame, 2);
4426*ef5ccd6cSJohn Marino 	      if (arg_value)
4427*ef5ccd6cSJohn Marino 		jmp_buf_pc = value_as_address (arg_value);
4428*ef5ccd6cSJohn Marino 	      else if (!gdbarch_get_longjmp_target_p (gdbarch)
4429c50c785cSJohn Marino 		       || !gdbarch_get_longjmp_target (gdbarch,
4430c50c785cSJohn Marino 						       frame, &jmp_buf_pc))
44315796c8dcSSimon Schubert 		{
44325796c8dcSSimon Schubert 		  if (debug_infrun)
4433c50c785cSJohn Marino 		    fprintf_unfiltered (gdb_stdlog,
4434c50c785cSJohn Marino 					"infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME "
4435c50c785cSJohn Marino 					"(!gdbarch_get_longjmp_target)\n");
44365796c8dcSSimon Schubert 		  keep_going (ecs);
44375796c8dcSSimon Schubert 		  return;
44385796c8dcSSimon Schubert 		}
44395796c8dcSSimon Schubert 
44405796c8dcSSimon Schubert 	      /* Insert a breakpoint at resume address.  */
44415796c8dcSSimon Schubert 	      insert_longjmp_resume_breakpoint (gdbarch, jmp_buf_pc);
4442c50c785cSJohn Marino 	    }
4443c50c785cSJohn Marino 	  else
4444*ef5ccd6cSJohn Marino 	    check_exception_resume (ecs, frame);
44455796c8dcSSimon Schubert 	  keep_going (ecs);
44465796c8dcSSimon Schubert 	  return;
44475796c8dcSSimon Schubert 
44485796c8dcSSimon Schubert 	case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME:
4449*ef5ccd6cSJohn Marino 	  {
4450*ef5ccd6cSJohn Marino 	    struct frame_info *init_frame;
4451*ef5ccd6cSJohn Marino 
4452*ef5ccd6cSJohn Marino 	    /* There are several cases to consider.
4453*ef5ccd6cSJohn Marino 
4454*ef5ccd6cSJohn Marino 	       1. The initiating frame no longer exists.  In this case
4455*ef5ccd6cSJohn Marino 	       we must stop, because the exception or longjmp has gone
4456*ef5ccd6cSJohn Marino 	       too far.
4457*ef5ccd6cSJohn Marino 
4458*ef5ccd6cSJohn Marino 	       2. The initiating frame exists, and is the same as the
4459*ef5ccd6cSJohn Marino 	       current frame.  We stop, because the exception or
4460*ef5ccd6cSJohn Marino 	       longjmp has been caught.
4461*ef5ccd6cSJohn Marino 
4462*ef5ccd6cSJohn Marino 	       3. The initiating frame exists and is different from
4463*ef5ccd6cSJohn Marino 	       the current frame.  This means the exception or longjmp
4464*ef5ccd6cSJohn Marino 	       has been caught beneath the initiating frame, so keep
4465*ef5ccd6cSJohn Marino 	       going.
4466*ef5ccd6cSJohn Marino 
4467*ef5ccd6cSJohn Marino 	       4. longjmp breakpoint has been placed just to protect
4468*ef5ccd6cSJohn Marino 	       against stale dummy frames and user is not interested
4469*ef5ccd6cSJohn Marino 	       in stopping around longjmps.  */
4470*ef5ccd6cSJohn Marino 
44715796c8dcSSimon Schubert 	    if (debug_infrun)
44725796c8dcSSimon Schubert 	      fprintf_unfiltered (gdb_stdlog,
44735796c8dcSSimon Schubert 				  "infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME\n");
44745796c8dcSSimon Schubert 
4475c50c785cSJohn Marino 	    gdb_assert (ecs->event_thread->control.exception_resume_breakpoint
4476c50c785cSJohn Marino 			!= NULL);
4477c50c785cSJohn Marino 	    delete_exception_resume_breakpoint (ecs->event_thread);
4478c50c785cSJohn Marino 
4479*ef5ccd6cSJohn Marino 	    if (what.is_longjmp)
4480*ef5ccd6cSJohn Marino 	      {
4481*ef5ccd6cSJohn Marino 		check_longjmp_breakpoint_for_call_dummy (ecs->event_thread->num);
4482*ef5ccd6cSJohn Marino 
4483*ef5ccd6cSJohn Marino 		if (!frame_id_p (ecs->event_thread->initiating_frame))
4484*ef5ccd6cSJohn Marino 		  {
4485*ef5ccd6cSJohn Marino 		    /* Case 4.  */
4486*ef5ccd6cSJohn Marino 		    keep_going (ecs);
4487*ef5ccd6cSJohn Marino 		    return;
4488*ef5ccd6cSJohn Marino 		  }
4489*ef5ccd6cSJohn Marino 	      }
4490*ef5ccd6cSJohn Marino 
4491*ef5ccd6cSJohn Marino 	    init_frame = frame_find_by_id (ecs->event_thread->initiating_frame);
4492*ef5ccd6cSJohn Marino 
4493c50c785cSJohn Marino 	    if (init_frame)
4494c50c785cSJohn Marino 	      {
4495c50c785cSJohn Marino 		struct frame_id current_id
4496c50c785cSJohn Marino 		  = get_frame_id (get_current_frame ());
4497c50c785cSJohn Marino 		if (frame_id_eq (current_id,
4498c50c785cSJohn Marino 				 ecs->event_thread->initiating_frame))
4499c50c785cSJohn Marino 		  {
4500c50c785cSJohn Marino 		    /* Case 2.  Fall through.  */
4501c50c785cSJohn Marino 		  }
4502c50c785cSJohn Marino 		else
4503c50c785cSJohn Marino 		  {
4504c50c785cSJohn Marino 		    /* Case 3.  */
4505c50c785cSJohn Marino 		    keep_going (ecs);
4506c50c785cSJohn Marino 		    return;
4507c50c785cSJohn Marino 		  }
4508c50c785cSJohn Marino 	      }
4509c50c785cSJohn Marino 
4510c50c785cSJohn Marino 	    /* For Cases 1 and 2, remove the step-resume breakpoint,
4511c50c785cSJohn Marino 	       if it exists.  */
4512c50c785cSJohn Marino 	    delete_step_resume_breakpoint (ecs->event_thread);
4513c50c785cSJohn Marino 
4514c50c785cSJohn Marino 	    ecs->event_thread->control.stop_step = 1;
4515c50c785cSJohn Marino 	    print_end_stepping_range_reason ();
45165796c8dcSSimon Schubert 	    stop_stepping (ecs);
4517*ef5ccd6cSJohn Marino 	  }
45185796c8dcSSimon Schubert 	  return;
45195796c8dcSSimon Schubert 
45205796c8dcSSimon Schubert 	case BPSTAT_WHAT_SINGLE:
45215796c8dcSSimon Schubert 	  if (debug_infrun)
45225796c8dcSSimon Schubert 	    fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_SINGLE\n");
45235796c8dcSSimon Schubert 	  ecs->event_thread->stepping_over_breakpoint = 1;
4524*ef5ccd6cSJohn Marino 	  /* Still need to check other stuff, at least the case where
4525*ef5ccd6cSJohn Marino 	     we are stepping and step out of the right range.  */
45265796c8dcSSimon Schubert 	  break;
45275796c8dcSSimon Schubert 
4528a45ae5f8SJohn Marino 	case BPSTAT_WHAT_STEP_RESUME:
4529a45ae5f8SJohn Marino 	  if (debug_infrun)
4530a45ae5f8SJohn Marino 	    fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STEP_RESUME\n");
4531a45ae5f8SJohn Marino 
4532a45ae5f8SJohn Marino 	  delete_step_resume_breakpoint (ecs->event_thread);
4533a45ae5f8SJohn Marino 	  if (ecs->event_thread->control.proceed_to_finish
4534a45ae5f8SJohn Marino 	      && execution_direction == EXEC_REVERSE)
4535a45ae5f8SJohn Marino 	    {
4536a45ae5f8SJohn Marino 	      struct thread_info *tp = ecs->event_thread;
4537a45ae5f8SJohn Marino 
4538a45ae5f8SJohn Marino 	      /* We are finishing a function in reverse, and just hit
4539*ef5ccd6cSJohn Marino 		 the step-resume breakpoint at the start address of
4540*ef5ccd6cSJohn Marino 		 the function, and we're almost there -- just need to
4541*ef5ccd6cSJohn Marino 		 back up by one more single-step, which should take us
4542*ef5ccd6cSJohn Marino 		 back to the function call.  */
4543a45ae5f8SJohn Marino 	      tp->control.step_range_start = tp->control.step_range_end = 1;
4544a45ae5f8SJohn Marino 	      keep_going (ecs);
4545a45ae5f8SJohn Marino 	      return;
4546a45ae5f8SJohn Marino 	    }
4547a45ae5f8SJohn Marino 	  fill_in_stop_func (gdbarch, ecs);
4548a45ae5f8SJohn Marino 	  if (stop_pc == ecs->stop_func_start
4549a45ae5f8SJohn Marino 	      && execution_direction == EXEC_REVERSE)
4550a45ae5f8SJohn Marino 	    {
4551a45ae5f8SJohn Marino 	      /* We are stepping over a function call in reverse, and
4552a45ae5f8SJohn Marino 		 just hit the step-resume breakpoint at the start
4553a45ae5f8SJohn Marino 		 address of the function.  Go back to single-stepping,
4554a45ae5f8SJohn Marino 		 which should take us back to the function call.  */
4555a45ae5f8SJohn Marino 	      ecs->event_thread->stepping_over_breakpoint = 1;
4556a45ae5f8SJohn Marino 	      keep_going (ecs);
4557a45ae5f8SJohn Marino 	      return;
4558a45ae5f8SJohn Marino 	    }
4559a45ae5f8SJohn Marino 	  break;
4560a45ae5f8SJohn Marino 
45615796c8dcSSimon Schubert 	case BPSTAT_WHAT_STOP_NOISY:
45625796c8dcSSimon Schubert 	  if (debug_infrun)
45635796c8dcSSimon Schubert 	    fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STOP_NOISY\n");
45645796c8dcSSimon Schubert 	  stop_print_frame = 1;
45655796c8dcSSimon Schubert 
45665796c8dcSSimon Schubert 	  /* We are about to nuke the step_resume_breakpointt via the
45675796c8dcSSimon Schubert 	     cleanup chain, so no need to worry about it here.  */
45685796c8dcSSimon Schubert 
45695796c8dcSSimon Schubert 	  stop_stepping (ecs);
45705796c8dcSSimon Schubert 	  return;
45715796c8dcSSimon Schubert 
45725796c8dcSSimon Schubert 	case BPSTAT_WHAT_STOP_SILENT:
45735796c8dcSSimon Schubert 	  if (debug_infrun)
45745796c8dcSSimon Schubert 	    fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STOP_SILENT\n");
45755796c8dcSSimon Schubert 	  stop_print_frame = 0;
45765796c8dcSSimon Schubert 
45775796c8dcSSimon Schubert 	  /* We are about to nuke the step_resume_breakpoin via the
45785796c8dcSSimon Schubert 	     cleanup chain, so no need to worry about it here.  */
45795796c8dcSSimon Schubert 
45805796c8dcSSimon Schubert 	  stop_stepping (ecs);
45815796c8dcSSimon Schubert 	  return;
45825796c8dcSSimon Schubert 
4583a45ae5f8SJohn Marino 	case BPSTAT_WHAT_HP_STEP_RESUME:
45845796c8dcSSimon Schubert 	  if (debug_infrun)
4585a45ae5f8SJohn Marino 	    fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_HP_STEP_RESUME\n");
45865796c8dcSSimon Schubert 
45875796c8dcSSimon Schubert 	  delete_step_resume_breakpoint (ecs->event_thread);
45885796c8dcSSimon Schubert 	  if (ecs->event_thread->step_after_step_resume_breakpoint)
45895796c8dcSSimon Schubert 	    {
45905796c8dcSSimon Schubert 	      /* Back when the step-resume breakpoint was inserted, we
45915796c8dcSSimon Schubert 		 were trying to single-step off a breakpoint.  Go back
45925796c8dcSSimon Schubert 		 to doing that.  */
45935796c8dcSSimon Schubert 	      ecs->event_thread->step_after_step_resume_breakpoint = 0;
45945796c8dcSSimon Schubert 	      ecs->event_thread->stepping_over_breakpoint = 1;
45955796c8dcSSimon Schubert 	      keep_going (ecs);
45965796c8dcSSimon Schubert 	      return;
45975796c8dcSSimon Schubert 	    }
45985796c8dcSSimon Schubert 	  break;
45995796c8dcSSimon Schubert 
46005796c8dcSSimon Schubert 	case BPSTAT_WHAT_KEEP_CHECKING:
46015796c8dcSSimon Schubert 	  break;
46025796c8dcSSimon Schubert 	}
46035796c8dcSSimon Schubert     }
46045796c8dcSSimon Schubert 
46055796c8dcSSimon Schubert   /* We come here if we hit a breakpoint but should not
46065796c8dcSSimon Schubert      stop for it.  Possibly we also were stepping
46075796c8dcSSimon Schubert      and should stop for that.  So fall through and
46085796c8dcSSimon Schubert      test for stepping.  But, if not stepping,
46095796c8dcSSimon Schubert      do not stop.  */
46105796c8dcSSimon Schubert 
46115796c8dcSSimon Schubert   /* In all-stop mode, if we're currently stepping but have stopped in
46125796c8dcSSimon Schubert      some other thread, we need to switch back to the stepped thread.  */
46135796c8dcSSimon Schubert   if (!non_stop)
46145796c8dcSSimon Schubert     {
46155796c8dcSSimon Schubert       struct thread_info *tp;
4616cf7f2e2dSJohn Marino 
46175796c8dcSSimon Schubert       tp = iterate_over_threads (currently_stepping_or_nexting_callback,
46185796c8dcSSimon Schubert 				 ecs->event_thread);
46195796c8dcSSimon Schubert       if (tp)
46205796c8dcSSimon Schubert 	{
46215796c8dcSSimon Schubert 	  /* However, if the current thread is blocked on some internal
46225796c8dcSSimon Schubert 	     breakpoint, and we simply need to step over that breakpoint
46235796c8dcSSimon Schubert 	     to get it going again, do that first.  */
4624c50c785cSJohn Marino 	  if ((ecs->event_thread->control.trap_expected
4625*ef5ccd6cSJohn Marino 	       && ecs->event_thread->suspend.stop_signal != GDB_SIGNAL_TRAP)
46265796c8dcSSimon Schubert 	      || ecs->event_thread->stepping_over_breakpoint)
46275796c8dcSSimon Schubert 	    {
46285796c8dcSSimon Schubert 	      keep_going (ecs);
46295796c8dcSSimon Schubert 	      return;
46305796c8dcSSimon Schubert 	    }
46315796c8dcSSimon Schubert 
46325796c8dcSSimon Schubert 	  /* If the stepping thread exited, then don't try to switch
46335796c8dcSSimon Schubert 	     back and resume it, which could fail in several different
46345796c8dcSSimon Schubert 	     ways depending on the target.  Instead, just keep going.
46355796c8dcSSimon Schubert 
46365796c8dcSSimon Schubert 	     We can find a stepping dead thread in the thread list in
46375796c8dcSSimon Schubert 	     two cases:
46385796c8dcSSimon Schubert 
46395796c8dcSSimon Schubert 	     - The target supports thread exit events, and when the
46405796c8dcSSimon Schubert 	     target tries to delete the thread from the thread list,
46415796c8dcSSimon Schubert 	     inferior_ptid pointed at the exiting thread.  In such
46425796c8dcSSimon Schubert 	     case, calling delete_thread does not really remove the
46435796c8dcSSimon Schubert 	     thread from the list; instead, the thread is left listed,
46445796c8dcSSimon Schubert 	     with 'exited' state.
46455796c8dcSSimon Schubert 
46465796c8dcSSimon Schubert 	     - The target's debug interface does not support thread
46475796c8dcSSimon Schubert 	     exit events, and so we have no idea whatsoever if the
46485796c8dcSSimon Schubert 	     previously stepping thread is still alive.  For that
46495796c8dcSSimon Schubert 	     reason, we need to synchronously query the target
46505796c8dcSSimon Schubert 	     now.  */
46515796c8dcSSimon Schubert 	  if (is_exited (tp->ptid)
46525796c8dcSSimon Schubert 	      || !target_thread_alive (tp->ptid))
46535796c8dcSSimon Schubert 	    {
46545796c8dcSSimon Schubert 	      if (debug_infrun)
4655c50c785cSJohn Marino 		fprintf_unfiltered (gdb_stdlog,
4656c50c785cSJohn Marino 				    "infrun: not switching back to "
4657c50c785cSJohn Marino 				    "stepped thread, it has vanished\n");
46585796c8dcSSimon Schubert 
46595796c8dcSSimon Schubert 	      delete_thread (tp->ptid);
46605796c8dcSSimon Schubert 	      keep_going (ecs);
46615796c8dcSSimon Schubert 	      return;
46625796c8dcSSimon Schubert 	    }
46635796c8dcSSimon Schubert 
46645796c8dcSSimon Schubert 	  /* Otherwise, we no longer expect a trap in the current thread.
46655796c8dcSSimon Schubert 	     Clear the trap_expected flag before switching back -- this is
46665796c8dcSSimon Schubert 	     what keep_going would do as well, if we called it.  */
4667c50c785cSJohn Marino 	  ecs->event_thread->control.trap_expected = 0;
46685796c8dcSSimon Schubert 
46695796c8dcSSimon Schubert 	  if (debug_infrun)
46705796c8dcSSimon Schubert 	    fprintf_unfiltered (gdb_stdlog,
46715796c8dcSSimon Schubert 				"infrun: switching back to stepped thread\n");
46725796c8dcSSimon Schubert 
46735796c8dcSSimon Schubert 	  ecs->event_thread = tp;
46745796c8dcSSimon Schubert 	  ecs->ptid = tp->ptid;
46755796c8dcSSimon Schubert 	  context_switch (ecs->ptid);
46765796c8dcSSimon Schubert 	  keep_going (ecs);
46775796c8dcSSimon Schubert 	  return;
46785796c8dcSSimon Schubert 	}
46795796c8dcSSimon Schubert     }
46805796c8dcSSimon Schubert 
4681c50c785cSJohn Marino   if (ecs->event_thread->control.step_resume_breakpoint)
46825796c8dcSSimon Schubert     {
46835796c8dcSSimon Schubert       if (debug_infrun)
46845796c8dcSSimon Schubert 	 fprintf_unfiltered (gdb_stdlog,
46855796c8dcSSimon Schubert 			     "infrun: step-resume breakpoint is inserted\n");
46865796c8dcSSimon Schubert 
46875796c8dcSSimon Schubert       /* Having a step-resume breakpoint overrides anything
46885796c8dcSSimon Schubert          else having to do with stepping commands until
46895796c8dcSSimon Schubert          that breakpoint is reached.  */
46905796c8dcSSimon Schubert       keep_going (ecs);
46915796c8dcSSimon Schubert       return;
46925796c8dcSSimon Schubert     }
46935796c8dcSSimon Schubert 
4694c50c785cSJohn Marino   if (ecs->event_thread->control.step_range_end == 0)
46955796c8dcSSimon Schubert     {
46965796c8dcSSimon Schubert       if (debug_infrun)
46975796c8dcSSimon Schubert 	 fprintf_unfiltered (gdb_stdlog, "infrun: no stepping, continue\n");
46985796c8dcSSimon Schubert       /* Likewise if we aren't even stepping.  */
46995796c8dcSSimon Schubert       keep_going (ecs);
47005796c8dcSSimon Schubert       return;
47015796c8dcSSimon Schubert     }
47025796c8dcSSimon Schubert 
4703cf7f2e2dSJohn Marino   /* Re-fetch current thread's frame in case the code above caused
4704cf7f2e2dSJohn Marino      the frame cache to be re-initialized, making our FRAME variable
4705cf7f2e2dSJohn Marino      a dangling pointer.  */
4706cf7f2e2dSJohn Marino   frame = get_current_frame ();
4707cf7f2e2dSJohn Marino   gdbarch = get_frame_arch (frame);
4708a45ae5f8SJohn Marino   fill_in_stop_func (gdbarch, ecs);
4709cf7f2e2dSJohn Marino 
47105796c8dcSSimon Schubert   /* If stepping through a line, keep going if still within it.
47115796c8dcSSimon Schubert 
47125796c8dcSSimon Schubert      Note that step_range_end is the address of the first instruction
47135796c8dcSSimon Schubert      beyond the step range, and NOT the address of the last instruction
47145796c8dcSSimon Schubert      within it!
47155796c8dcSSimon Schubert 
47165796c8dcSSimon Schubert      Note also that during reverse execution, we may be stepping
47175796c8dcSSimon Schubert      through a function epilogue and therefore must detect when
47185796c8dcSSimon Schubert      the current-frame changes in the middle of a line.  */
47195796c8dcSSimon Schubert 
4720c50c785cSJohn Marino   if (stop_pc >= ecs->event_thread->control.step_range_start
4721c50c785cSJohn Marino       && stop_pc < ecs->event_thread->control.step_range_end
47225796c8dcSSimon Schubert       && (execution_direction != EXEC_REVERSE
47235796c8dcSSimon Schubert 	  || frame_id_eq (get_frame_id (frame),
4724c50c785cSJohn Marino 			  ecs->event_thread->control.step_frame_id)))
47255796c8dcSSimon Schubert     {
47265796c8dcSSimon Schubert       if (debug_infrun)
47275796c8dcSSimon Schubert 	fprintf_unfiltered
47285796c8dcSSimon Schubert 	  (gdb_stdlog, "infrun: stepping inside range [%s-%s]\n",
4729c50c785cSJohn Marino 	   paddress (gdbarch, ecs->event_thread->control.step_range_start),
4730c50c785cSJohn Marino 	   paddress (gdbarch, ecs->event_thread->control.step_range_end));
47315796c8dcSSimon Schubert 
47325796c8dcSSimon Schubert       /* When stepping backward, stop at beginning of line range
47335796c8dcSSimon Schubert 	 (unless it's the function entry point, in which case
47345796c8dcSSimon Schubert 	 keep going back to the call point).  */
4735c50c785cSJohn Marino       if (stop_pc == ecs->event_thread->control.step_range_start
47365796c8dcSSimon Schubert 	  && stop_pc != ecs->stop_func_start
47375796c8dcSSimon Schubert 	  && execution_direction == EXEC_REVERSE)
47385796c8dcSSimon Schubert 	{
4739c50c785cSJohn Marino 	  ecs->event_thread->control.stop_step = 1;
4740c50c785cSJohn Marino 	  print_end_stepping_range_reason ();
47415796c8dcSSimon Schubert 	  stop_stepping (ecs);
47425796c8dcSSimon Schubert 	}
47435796c8dcSSimon Schubert       else
47445796c8dcSSimon Schubert 	keep_going (ecs);
47455796c8dcSSimon Schubert 
47465796c8dcSSimon Schubert       return;
47475796c8dcSSimon Schubert     }
47485796c8dcSSimon Schubert 
47495796c8dcSSimon Schubert   /* We stepped out of the stepping range.  */
47505796c8dcSSimon Schubert 
47515796c8dcSSimon Schubert   /* If we are stepping at the source level and entered the runtime
47525796c8dcSSimon Schubert      loader dynamic symbol resolution code...
47535796c8dcSSimon Schubert 
47545796c8dcSSimon Schubert      EXEC_FORWARD: we keep on single stepping until we exit the run
47555796c8dcSSimon Schubert      time loader code and reach the callee's address.
47565796c8dcSSimon Schubert 
47575796c8dcSSimon Schubert      EXEC_REVERSE: we've already executed the callee (backward), and
47585796c8dcSSimon Schubert      the runtime loader code is handled just like any other
47595796c8dcSSimon Schubert      undebuggable function call.  Now we need only keep stepping
47605796c8dcSSimon Schubert      backward through the trampoline code, and that's handled further
47615796c8dcSSimon Schubert      down, so there is nothing for us to do here.  */
47625796c8dcSSimon Schubert 
47635796c8dcSSimon Schubert   if (execution_direction != EXEC_REVERSE
4764c50c785cSJohn Marino       && ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE
47655796c8dcSSimon Schubert       && in_solib_dynsym_resolve_code (stop_pc))
47665796c8dcSSimon Schubert     {
47675796c8dcSSimon Schubert       CORE_ADDR pc_after_resolver =
47685796c8dcSSimon Schubert 	gdbarch_skip_solib_resolver (gdbarch, stop_pc);
47695796c8dcSSimon Schubert 
47705796c8dcSSimon Schubert       if (debug_infrun)
4771c50c785cSJohn Marino 	 fprintf_unfiltered (gdb_stdlog,
4772c50c785cSJohn Marino 			     "infrun: stepped into dynsym resolve code\n");
47735796c8dcSSimon Schubert 
47745796c8dcSSimon Schubert       if (pc_after_resolver)
47755796c8dcSSimon Schubert 	{
47765796c8dcSSimon Schubert 	  /* Set up a step-resume breakpoint at the address
47775796c8dcSSimon Schubert 	     indicated by SKIP_SOLIB_RESOLVER.  */
47785796c8dcSSimon Schubert 	  struct symtab_and_line sr_sal;
4779cf7f2e2dSJohn Marino 
47805796c8dcSSimon Schubert 	  init_sal (&sr_sal);
47815796c8dcSSimon Schubert 	  sr_sal.pc = pc_after_resolver;
4782cf7f2e2dSJohn Marino 	  sr_sal.pspace = get_frame_program_space (frame);
47835796c8dcSSimon Schubert 
47845796c8dcSSimon Schubert 	  insert_step_resume_breakpoint_at_sal (gdbarch,
47855796c8dcSSimon Schubert 						sr_sal, null_frame_id);
47865796c8dcSSimon Schubert 	}
47875796c8dcSSimon Schubert 
47885796c8dcSSimon Schubert       keep_going (ecs);
47895796c8dcSSimon Schubert       return;
47905796c8dcSSimon Schubert     }
47915796c8dcSSimon Schubert 
4792c50c785cSJohn Marino   if (ecs->event_thread->control.step_range_end != 1
4793c50c785cSJohn Marino       && (ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE
4794c50c785cSJohn Marino 	  || ecs->event_thread->control.step_over_calls == STEP_OVER_ALL)
47955796c8dcSSimon Schubert       && get_frame_type (frame) == SIGTRAMP_FRAME)
47965796c8dcSSimon Schubert     {
47975796c8dcSSimon Schubert       if (debug_infrun)
4798c50c785cSJohn Marino 	 fprintf_unfiltered (gdb_stdlog,
4799c50c785cSJohn Marino 			     "infrun: stepped into signal trampoline\n");
48005796c8dcSSimon Schubert       /* The inferior, while doing a "step" or "next", has ended up in
48015796c8dcSSimon Schubert          a signal trampoline (either by a signal being delivered or by
48025796c8dcSSimon Schubert          the signal handler returning).  Just single-step until the
48035796c8dcSSimon Schubert          inferior leaves the trampoline (either by calling the handler
48045796c8dcSSimon Schubert          or returning).  */
48055796c8dcSSimon Schubert       keep_going (ecs);
48065796c8dcSSimon Schubert       return;
48075796c8dcSSimon Schubert     }
48085796c8dcSSimon Schubert 
4809*ef5ccd6cSJohn Marino   /* If we're in the return path from a shared library trampoline,
4810*ef5ccd6cSJohn Marino      we want to proceed through the trampoline when stepping.  */
4811*ef5ccd6cSJohn Marino   /* macro/2012-04-25: This needs to come before the subroutine
4812*ef5ccd6cSJohn Marino      call check below as on some targets return trampolines look
4813*ef5ccd6cSJohn Marino      like subroutine calls (MIPS16 return thunks).  */
4814*ef5ccd6cSJohn Marino   if (gdbarch_in_solib_return_trampoline (gdbarch,
4815*ef5ccd6cSJohn Marino 					  stop_pc, ecs->stop_func_name)
4816*ef5ccd6cSJohn Marino       && ecs->event_thread->control.step_over_calls != STEP_OVER_NONE)
4817*ef5ccd6cSJohn Marino     {
4818*ef5ccd6cSJohn Marino       /* Determine where this trampoline returns.  */
4819*ef5ccd6cSJohn Marino       CORE_ADDR real_stop_pc;
4820*ef5ccd6cSJohn Marino 
4821*ef5ccd6cSJohn Marino       real_stop_pc = gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc);
4822*ef5ccd6cSJohn Marino 
4823*ef5ccd6cSJohn Marino       if (debug_infrun)
4824*ef5ccd6cSJohn Marino 	 fprintf_unfiltered (gdb_stdlog,
4825*ef5ccd6cSJohn Marino 			     "infrun: stepped into solib return tramp\n");
4826*ef5ccd6cSJohn Marino 
4827*ef5ccd6cSJohn Marino       /* Only proceed through if we know where it's going.  */
4828*ef5ccd6cSJohn Marino       if (real_stop_pc)
4829*ef5ccd6cSJohn Marino 	{
4830*ef5ccd6cSJohn Marino 	  /* And put the step-breakpoint there and go until there.  */
4831*ef5ccd6cSJohn Marino 	  struct symtab_and_line sr_sal;
4832*ef5ccd6cSJohn Marino 
4833*ef5ccd6cSJohn Marino 	  init_sal (&sr_sal);	/* initialize to zeroes */
4834*ef5ccd6cSJohn Marino 	  sr_sal.pc = real_stop_pc;
4835*ef5ccd6cSJohn Marino 	  sr_sal.section = find_pc_overlay (sr_sal.pc);
4836*ef5ccd6cSJohn Marino 	  sr_sal.pspace = get_frame_program_space (frame);
4837*ef5ccd6cSJohn Marino 
4838*ef5ccd6cSJohn Marino 	  /* Do not specify what the fp should be when we stop since
4839*ef5ccd6cSJohn Marino 	     on some machines the prologue is where the new fp value
4840*ef5ccd6cSJohn Marino 	     is established.  */
4841*ef5ccd6cSJohn Marino 	  insert_step_resume_breakpoint_at_sal (gdbarch,
4842*ef5ccd6cSJohn Marino 						sr_sal, null_frame_id);
4843*ef5ccd6cSJohn Marino 
4844*ef5ccd6cSJohn Marino 	  /* Restart without fiddling with the step ranges or
4845*ef5ccd6cSJohn Marino 	     other state.  */
4846*ef5ccd6cSJohn Marino 	  keep_going (ecs);
4847*ef5ccd6cSJohn Marino 	  return;
4848*ef5ccd6cSJohn Marino 	}
4849*ef5ccd6cSJohn Marino     }
4850*ef5ccd6cSJohn Marino 
48515796c8dcSSimon Schubert   /* Check for subroutine calls.  The check for the current frame
48525796c8dcSSimon Schubert      equalling the step ID is not necessary - the check of the
48535796c8dcSSimon Schubert      previous frame's ID is sufficient - but it is a common case and
48545796c8dcSSimon Schubert      cheaper than checking the previous frame's ID.
48555796c8dcSSimon Schubert 
48565796c8dcSSimon Schubert      NOTE: frame_id_eq will never report two invalid frame IDs as
48575796c8dcSSimon Schubert      being equal, so to get into this block, both the current and
48585796c8dcSSimon Schubert      previous frame must have valid frame IDs.  */
48595796c8dcSSimon Schubert   /* The outer_frame_id check is a heuristic to detect stepping
48605796c8dcSSimon Schubert      through startup code.  If we step over an instruction which
48615796c8dcSSimon Schubert      sets the stack pointer from an invalid value to a valid value,
48625796c8dcSSimon Schubert      we may detect that as a subroutine call from the mythical
48635796c8dcSSimon Schubert      "outermost" function.  This could be fixed by marking
48645796c8dcSSimon Schubert      outermost frames as !stack_p,code_p,special_p.  Then the
48655796c8dcSSimon Schubert      initial outermost frame, before sp was valid, would
4866cf7f2e2dSJohn Marino      have code_addr == &_start.  See the comment in frame_id_eq
48675796c8dcSSimon Schubert      for more.  */
48685796c8dcSSimon Schubert   if (!frame_id_eq (get_stack_frame_id (frame),
4869c50c785cSJohn Marino 		    ecs->event_thread->control.step_stack_frame_id)
48705796c8dcSSimon Schubert       && (frame_id_eq (frame_unwind_caller_id (get_current_frame ()),
4871c50c785cSJohn Marino 		       ecs->event_thread->control.step_stack_frame_id)
4872c50c785cSJohn Marino 	  && (!frame_id_eq (ecs->event_thread->control.step_stack_frame_id,
48735796c8dcSSimon Schubert 			    outer_frame_id)
48745796c8dcSSimon Schubert 	      || step_start_function != find_pc_function (stop_pc))))
48755796c8dcSSimon Schubert     {
48765796c8dcSSimon Schubert       CORE_ADDR real_stop_pc;
48775796c8dcSSimon Schubert 
48785796c8dcSSimon Schubert       if (debug_infrun)
48795796c8dcSSimon Schubert 	 fprintf_unfiltered (gdb_stdlog, "infrun: stepped into subroutine\n");
48805796c8dcSSimon Schubert 
4881c50c785cSJohn Marino       if ((ecs->event_thread->control.step_over_calls == STEP_OVER_NONE)
4882c50c785cSJohn Marino 	  || ((ecs->event_thread->control.step_range_end == 1)
48835796c8dcSSimon Schubert 	      && in_prologue (gdbarch, ecs->event_thread->prev_pc,
48845796c8dcSSimon Schubert 			      ecs->stop_func_start)))
48855796c8dcSSimon Schubert 	{
48865796c8dcSSimon Schubert 	  /* I presume that step_over_calls is only 0 when we're
48875796c8dcSSimon Schubert 	     supposed to be stepping at the assembly language level
48885796c8dcSSimon Schubert 	     ("stepi").  Just stop.  */
48895796c8dcSSimon Schubert 	  /* Also, maybe we just did a "nexti" inside a prolog, so we
48905796c8dcSSimon Schubert 	     thought it was a subroutine call but it was not.  Stop as
48915796c8dcSSimon Schubert 	     well.  FENN */
48925796c8dcSSimon Schubert 	  /* And this works the same backward as frontward.  MVS */
4893c50c785cSJohn Marino 	  ecs->event_thread->control.stop_step = 1;
4894c50c785cSJohn Marino 	  print_end_stepping_range_reason ();
48955796c8dcSSimon Schubert 	  stop_stepping (ecs);
48965796c8dcSSimon Schubert 	  return;
48975796c8dcSSimon Schubert 	}
48985796c8dcSSimon Schubert 
48995796c8dcSSimon Schubert       /* Reverse stepping through solib trampolines.  */
49005796c8dcSSimon Schubert 
49015796c8dcSSimon Schubert       if (execution_direction == EXEC_REVERSE
4902c50c785cSJohn Marino 	  && ecs->event_thread->control.step_over_calls != STEP_OVER_NONE
49035796c8dcSSimon Schubert 	  && (gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc)
49045796c8dcSSimon Schubert 	      || (ecs->stop_func_start == 0
49055796c8dcSSimon Schubert 		  && in_solib_dynsym_resolve_code (stop_pc))))
49065796c8dcSSimon Schubert 	{
49075796c8dcSSimon Schubert 	  /* Any solib trampoline code can be handled in reverse
49085796c8dcSSimon Schubert 	     by simply continuing to single-step.  We have already
49095796c8dcSSimon Schubert 	     executed the solib function (backwards), and a few
49105796c8dcSSimon Schubert 	     steps will take us back through the trampoline to the
49115796c8dcSSimon Schubert 	     caller.  */
49125796c8dcSSimon Schubert 	  keep_going (ecs);
49135796c8dcSSimon Schubert 	  return;
49145796c8dcSSimon Schubert 	}
49155796c8dcSSimon Schubert 
4916c50c785cSJohn Marino       if (ecs->event_thread->control.step_over_calls == STEP_OVER_ALL)
49175796c8dcSSimon Schubert 	{
49185796c8dcSSimon Schubert 	  /* We're doing a "next".
49195796c8dcSSimon Schubert 
49205796c8dcSSimon Schubert 	     Normal (forward) execution: set a breakpoint at the
49215796c8dcSSimon Schubert 	     callee's return address (the address at which the caller
49225796c8dcSSimon Schubert 	     will resume).
49235796c8dcSSimon Schubert 
49245796c8dcSSimon Schubert 	     Reverse (backward) execution.  set the step-resume
49255796c8dcSSimon Schubert 	     breakpoint at the start of the function that we just
49265796c8dcSSimon Schubert 	     stepped into (backwards), and continue to there.  When we
49275796c8dcSSimon Schubert 	     get there, we'll need to single-step back to the caller.  */
49285796c8dcSSimon Schubert 
49295796c8dcSSimon Schubert 	  if (execution_direction == EXEC_REVERSE)
49305796c8dcSSimon Schubert 	    {
4931*ef5ccd6cSJohn Marino 	      /* If we're already at the start of the function, we've either
4932*ef5ccd6cSJohn Marino 		 just stepped backward into a single instruction function,
4933*ef5ccd6cSJohn Marino 		 or stepped back out of a signal handler to the first instruction
4934*ef5ccd6cSJohn Marino 		 of the function.  Just keep going, which will single-step back
4935*ef5ccd6cSJohn Marino 		 to the caller.  */
4936*ef5ccd6cSJohn Marino 	      if (ecs->stop_func_start != stop_pc)
4937*ef5ccd6cSJohn Marino 		{
49385796c8dcSSimon Schubert 		  struct symtab_and_line sr_sal;
49395796c8dcSSimon Schubert 
49405796c8dcSSimon Schubert 		  /* Normal function call return (static or dynamic).  */
49415796c8dcSSimon Schubert 		  init_sal (&sr_sal);
49425796c8dcSSimon Schubert 		  sr_sal.pc = ecs->stop_func_start;
4943cf7f2e2dSJohn Marino 		  sr_sal.pspace = get_frame_program_space (frame);
49445796c8dcSSimon Schubert 		  insert_step_resume_breakpoint_at_sal (gdbarch,
49455796c8dcSSimon Schubert 							sr_sal, null_frame_id);
49465796c8dcSSimon Schubert 		}
4947*ef5ccd6cSJohn Marino 	    }
49485796c8dcSSimon Schubert 	  else
49495796c8dcSSimon Schubert 	    insert_step_resume_breakpoint_at_caller (frame);
49505796c8dcSSimon Schubert 
49515796c8dcSSimon Schubert 	  keep_going (ecs);
49525796c8dcSSimon Schubert 	  return;
49535796c8dcSSimon Schubert 	}
49545796c8dcSSimon Schubert 
49555796c8dcSSimon Schubert       /* If we are in a function call trampoline (a stub between the
49565796c8dcSSimon Schubert          calling routine and the real function), locate the real
49575796c8dcSSimon Schubert          function.  That's what tells us (a) whether we want to step
49585796c8dcSSimon Schubert          into it at all, and (b) what prologue we want to run to the
49595796c8dcSSimon Schubert          end of, if we do step into it.  */
49605796c8dcSSimon Schubert       real_stop_pc = skip_language_trampoline (frame, stop_pc);
49615796c8dcSSimon Schubert       if (real_stop_pc == 0)
49625796c8dcSSimon Schubert 	real_stop_pc = gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc);
49635796c8dcSSimon Schubert       if (real_stop_pc != 0)
49645796c8dcSSimon Schubert 	ecs->stop_func_start = real_stop_pc;
49655796c8dcSSimon Schubert 
49665796c8dcSSimon Schubert       if (real_stop_pc != 0 && in_solib_dynsym_resolve_code (real_stop_pc))
49675796c8dcSSimon Schubert 	{
49685796c8dcSSimon Schubert 	  struct symtab_and_line sr_sal;
4969cf7f2e2dSJohn Marino 
49705796c8dcSSimon Schubert 	  init_sal (&sr_sal);
49715796c8dcSSimon Schubert 	  sr_sal.pc = ecs->stop_func_start;
4972cf7f2e2dSJohn Marino 	  sr_sal.pspace = get_frame_program_space (frame);
49735796c8dcSSimon Schubert 
49745796c8dcSSimon Schubert 	  insert_step_resume_breakpoint_at_sal (gdbarch,
49755796c8dcSSimon Schubert 						sr_sal, null_frame_id);
49765796c8dcSSimon Schubert 	  keep_going (ecs);
49775796c8dcSSimon Schubert 	  return;
49785796c8dcSSimon Schubert 	}
49795796c8dcSSimon Schubert 
49805796c8dcSSimon Schubert       /* If we have line number information for the function we are
4981a45ae5f8SJohn Marino 	 thinking of stepping into and the function isn't on the skip
4982a45ae5f8SJohn Marino 	 list, step into it.
49835796c8dcSSimon Schubert 
49845796c8dcSSimon Schubert          If there are several symtabs at that PC (e.g. with include
49855796c8dcSSimon Schubert          files), just want to know whether *any* of them have line
49865796c8dcSSimon Schubert          numbers.  find_pc_line handles this.  */
49875796c8dcSSimon Schubert       {
49885796c8dcSSimon Schubert 	struct symtab_and_line tmp_sal;
49895796c8dcSSimon Schubert 
49905796c8dcSSimon Schubert 	tmp_sal = find_pc_line (ecs->stop_func_start, 0);
4991a45ae5f8SJohn Marino 	if (tmp_sal.line != 0
4992*ef5ccd6cSJohn Marino 	    && !function_name_is_marked_for_skip (ecs->stop_func_name,
4993*ef5ccd6cSJohn Marino 						  &tmp_sal))
49945796c8dcSSimon Schubert 	  {
49955796c8dcSSimon Schubert 	    if (execution_direction == EXEC_REVERSE)
49965796c8dcSSimon Schubert 	      handle_step_into_function_backward (gdbarch, ecs);
49975796c8dcSSimon Schubert 	    else
49985796c8dcSSimon Schubert 	      handle_step_into_function (gdbarch, ecs);
49995796c8dcSSimon Schubert 	    return;
50005796c8dcSSimon Schubert 	  }
50015796c8dcSSimon Schubert       }
50025796c8dcSSimon Schubert 
50035796c8dcSSimon Schubert       /* If we have no line number and the step-stop-if-no-debug is
50045796c8dcSSimon Schubert          set, we stop the step so that the user has a chance to switch
50055796c8dcSSimon Schubert          in assembly mode.  */
5006c50c785cSJohn Marino       if (ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE
50075796c8dcSSimon Schubert 	  && step_stop_if_no_debug)
50085796c8dcSSimon Schubert 	{
5009c50c785cSJohn Marino 	  ecs->event_thread->control.stop_step = 1;
5010c50c785cSJohn Marino 	  print_end_stepping_range_reason ();
50115796c8dcSSimon Schubert 	  stop_stepping (ecs);
50125796c8dcSSimon Schubert 	  return;
50135796c8dcSSimon Schubert 	}
50145796c8dcSSimon Schubert 
50155796c8dcSSimon Schubert       if (execution_direction == EXEC_REVERSE)
50165796c8dcSSimon Schubert 	{
5017*ef5ccd6cSJohn Marino 	  /* If we're already at the start of the function, we've either just
5018*ef5ccd6cSJohn Marino 	     stepped backward into a single instruction function without line
5019*ef5ccd6cSJohn Marino 	     number info, or stepped back out of a signal handler to the first
5020*ef5ccd6cSJohn Marino 	     instruction of the function without line number info.  Just keep
5021*ef5ccd6cSJohn Marino 	     going, which will single-step back to the caller.  */
5022*ef5ccd6cSJohn Marino 	  if (ecs->stop_func_start != stop_pc)
5023*ef5ccd6cSJohn Marino 	    {
50245796c8dcSSimon Schubert 	      /* Set a breakpoint at callee's start address.
50255796c8dcSSimon Schubert 		 From there we can step once and be back in the caller.  */
50265796c8dcSSimon Schubert 	      struct symtab_and_line sr_sal;
5027cf7f2e2dSJohn Marino 
50285796c8dcSSimon Schubert 	      init_sal (&sr_sal);
50295796c8dcSSimon Schubert 	      sr_sal.pc = ecs->stop_func_start;
5030cf7f2e2dSJohn Marino 	      sr_sal.pspace = get_frame_program_space (frame);
50315796c8dcSSimon Schubert 	      insert_step_resume_breakpoint_at_sal (gdbarch,
50325796c8dcSSimon Schubert 						    sr_sal, null_frame_id);
50335796c8dcSSimon Schubert 	    }
5034*ef5ccd6cSJohn Marino 	}
50355796c8dcSSimon Schubert       else
50365796c8dcSSimon Schubert 	/* Set a breakpoint at callee's return address (the address
50375796c8dcSSimon Schubert 	   at which the caller will resume).  */
50385796c8dcSSimon Schubert 	insert_step_resume_breakpoint_at_caller (frame);
50395796c8dcSSimon Schubert 
50405796c8dcSSimon Schubert       keep_going (ecs);
50415796c8dcSSimon Schubert       return;
50425796c8dcSSimon Schubert     }
50435796c8dcSSimon Schubert 
50445796c8dcSSimon Schubert   /* Reverse stepping through solib trampolines.  */
50455796c8dcSSimon Schubert 
50465796c8dcSSimon Schubert   if (execution_direction == EXEC_REVERSE
5047c50c785cSJohn Marino       && ecs->event_thread->control.step_over_calls != STEP_OVER_NONE)
50485796c8dcSSimon Schubert     {
50495796c8dcSSimon Schubert       if (gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc)
50505796c8dcSSimon Schubert 	  || (ecs->stop_func_start == 0
50515796c8dcSSimon Schubert 	      && in_solib_dynsym_resolve_code (stop_pc)))
50525796c8dcSSimon Schubert 	{
50535796c8dcSSimon Schubert 	  /* Any solib trampoline code can be handled in reverse
50545796c8dcSSimon Schubert 	     by simply continuing to single-step.  We have already
50555796c8dcSSimon Schubert 	     executed the solib function (backwards), and a few
50565796c8dcSSimon Schubert 	     steps will take us back through the trampoline to the
50575796c8dcSSimon Schubert 	     caller.  */
50585796c8dcSSimon Schubert 	  keep_going (ecs);
50595796c8dcSSimon Schubert 	  return;
50605796c8dcSSimon Schubert 	}
50615796c8dcSSimon Schubert       else if (in_solib_dynsym_resolve_code (stop_pc))
50625796c8dcSSimon Schubert 	{
50635796c8dcSSimon Schubert 	  /* Stepped backward into the solib dynsym resolver.
50645796c8dcSSimon Schubert 	     Set a breakpoint at its start and continue, then
50655796c8dcSSimon Schubert 	     one more step will take us out.  */
50665796c8dcSSimon Schubert 	  struct symtab_and_line sr_sal;
5067cf7f2e2dSJohn Marino 
50685796c8dcSSimon Schubert 	  init_sal (&sr_sal);
50695796c8dcSSimon Schubert 	  sr_sal.pc = ecs->stop_func_start;
5070cf7f2e2dSJohn Marino 	  sr_sal.pspace = get_frame_program_space (frame);
50715796c8dcSSimon Schubert 	  insert_step_resume_breakpoint_at_sal (gdbarch,
50725796c8dcSSimon Schubert 						sr_sal, null_frame_id);
50735796c8dcSSimon Schubert 	  keep_going (ecs);
50745796c8dcSSimon Schubert 	  return;
50755796c8dcSSimon Schubert 	}
50765796c8dcSSimon Schubert     }
50775796c8dcSSimon Schubert 
50785796c8dcSSimon Schubert   stop_pc_sal = find_pc_line (stop_pc, 0);
50795796c8dcSSimon Schubert 
50805796c8dcSSimon Schubert   /* NOTE: tausq/2004-05-24: This if block used to be done before all
50815796c8dcSSimon Schubert      the trampoline processing logic, however, there are some trampolines
50825796c8dcSSimon Schubert      that have no names, so we should do trampoline handling first.  */
5083c50c785cSJohn Marino   if (ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE
50845796c8dcSSimon Schubert       && ecs->stop_func_name == NULL
50855796c8dcSSimon Schubert       && stop_pc_sal.line == 0)
50865796c8dcSSimon Schubert     {
50875796c8dcSSimon Schubert       if (debug_infrun)
5088c50c785cSJohn Marino 	 fprintf_unfiltered (gdb_stdlog,
5089c50c785cSJohn Marino 			     "infrun: stepped into undebuggable function\n");
50905796c8dcSSimon Schubert 
50915796c8dcSSimon Schubert       /* The inferior just stepped into, or returned to, an
50925796c8dcSSimon Schubert          undebuggable function (where there is no debugging information
50935796c8dcSSimon Schubert          and no line number corresponding to the address where the
50945796c8dcSSimon Schubert          inferior stopped).  Since we want to skip this kind of code,
50955796c8dcSSimon Schubert          we keep going until the inferior returns from this
50965796c8dcSSimon Schubert          function - unless the user has asked us not to (via
50975796c8dcSSimon Schubert          set step-mode) or we no longer know how to get back
50985796c8dcSSimon Schubert          to the call site.  */
50995796c8dcSSimon Schubert       if (step_stop_if_no_debug
51005796c8dcSSimon Schubert 	  || !frame_id_p (frame_unwind_caller_id (frame)))
51015796c8dcSSimon Schubert 	{
51025796c8dcSSimon Schubert 	  /* If we have no line number and the step-stop-if-no-debug
51035796c8dcSSimon Schubert 	     is set, we stop the step so that the user has a chance to
51045796c8dcSSimon Schubert 	     switch in assembly mode.  */
5105c50c785cSJohn Marino 	  ecs->event_thread->control.stop_step = 1;
5106c50c785cSJohn Marino 	  print_end_stepping_range_reason ();
51075796c8dcSSimon Schubert 	  stop_stepping (ecs);
51085796c8dcSSimon Schubert 	  return;
51095796c8dcSSimon Schubert 	}
51105796c8dcSSimon Schubert       else
51115796c8dcSSimon Schubert 	{
51125796c8dcSSimon Schubert 	  /* Set a breakpoint at callee's return address (the address
51135796c8dcSSimon Schubert 	     at which the caller will resume).  */
51145796c8dcSSimon Schubert 	  insert_step_resume_breakpoint_at_caller (frame);
51155796c8dcSSimon Schubert 	  keep_going (ecs);
51165796c8dcSSimon Schubert 	  return;
51175796c8dcSSimon Schubert 	}
51185796c8dcSSimon Schubert     }
51195796c8dcSSimon Schubert 
5120c50c785cSJohn Marino   if (ecs->event_thread->control.step_range_end == 1)
51215796c8dcSSimon Schubert     {
51225796c8dcSSimon Schubert       /* It is stepi or nexti.  We always want to stop stepping after
51235796c8dcSSimon Schubert          one instruction.  */
51245796c8dcSSimon Schubert       if (debug_infrun)
51255796c8dcSSimon Schubert 	 fprintf_unfiltered (gdb_stdlog, "infrun: stepi/nexti\n");
5126c50c785cSJohn Marino       ecs->event_thread->control.stop_step = 1;
5127c50c785cSJohn Marino       print_end_stepping_range_reason ();
51285796c8dcSSimon Schubert       stop_stepping (ecs);
51295796c8dcSSimon Schubert       return;
51305796c8dcSSimon Schubert     }
51315796c8dcSSimon Schubert 
51325796c8dcSSimon Schubert   if (stop_pc_sal.line == 0)
51335796c8dcSSimon Schubert     {
51345796c8dcSSimon Schubert       /* We have no line number information.  That means to stop
51355796c8dcSSimon Schubert          stepping (does this always happen right after one instruction,
51365796c8dcSSimon Schubert          when we do "s" in a function with no line numbers,
51375796c8dcSSimon Schubert          or can this happen as a result of a return or longjmp?).  */
51385796c8dcSSimon Schubert       if (debug_infrun)
51395796c8dcSSimon Schubert 	 fprintf_unfiltered (gdb_stdlog, "infrun: no line number info\n");
5140c50c785cSJohn Marino       ecs->event_thread->control.stop_step = 1;
5141c50c785cSJohn Marino       print_end_stepping_range_reason ();
51425796c8dcSSimon Schubert       stop_stepping (ecs);
51435796c8dcSSimon Schubert       return;
51445796c8dcSSimon Schubert     }
51455796c8dcSSimon Schubert 
51465796c8dcSSimon Schubert   /* Look for "calls" to inlined functions, part one.  If the inline
51475796c8dcSSimon Schubert      frame machinery detected some skipped call sites, we have entered
51485796c8dcSSimon Schubert      a new inline function.  */
51495796c8dcSSimon Schubert 
51505796c8dcSSimon Schubert   if (frame_id_eq (get_frame_id (get_current_frame ()),
5151c50c785cSJohn Marino 		   ecs->event_thread->control.step_frame_id)
51525796c8dcSSimon Schubert       && inline_skipped_frames (ecs->ptid))
51535796c8dcSSimon Schubert     {
51545796c8dcSSimon Schubert       struct symtab_and_line call_sal;
51555796c8dcSSimon Schubert 
51565796c8dcSSimon Schubert       if (debug_infrun)
51575796c8dcSSimon Schubert 	fprintf_unfiltered (gdb_stdlog,
51585796c8dcSSimon Schubert 			    "infrun: stepped into inlined function\n");
51595796c8dcSSimon Schubert 
51605796c8dcSSimon Schubert       find_frame_sal (get_current_frame (), &call_sal);
51615796c8dcSSimon Schubert 
5162c50c785cSJohn Marino       if (ecs->event_thread->control.step_over_calls != STEP_OVER_ALL)
51635796c8dcSSimon Schubert 	{
51645796c8dcSSimon Schubert 	  /* For "step", we're going to stop.  But if the call site
51655796c8dcSSimon Schubert 	     for this inlined function is on the same source line as
51665796c8dcSSimon Schubert 	     we were previously stepping, go down into the function
51675796c8dcSSimon Schubert 	     first.  Otherwise stop at the call site.  */
51685796c8dcSSimon Schubert 
51695796c8dcSSimon Schubert 	  if (call_sal.line == ecs->event_thread->current_line
51705796c8dcSSimon Schubert 	      && call_sal.symtab == ecs->event_thread->current_symtab)
51715796c8dcSSimon Schubert 	    step_into_inline_frame (ecs->ptid);
51725796c8dcSSimon Schubert 
5173c50c785cSJohn Marino 	  ecs->event_thread->control.stop_step = 1;
5174c50c785cSJohn Marino 	  print_end_stepping_range_reason ();
51755796c8dcSSimon Schubert 	  stop_stepping (ecs);
51765796c8dcSSimon Schubert 	  return;
51775796c8dcSSimon Schubert 	}
51785796c8dcSSimon Schubert       else
51795796c8dcSSimon Schubert 	{
51805796c8dcSSimon Schubert 	  /* For "next", we should stop at the call site if it is on a
51815796c8dcSSimon Schubert 	     different source line.  Otherwise continue through the
51825796c8dcSSimon Schubert 	     inlined function.  */
51835796c8dcSSimon Schubert 	  if (call_sal.line == ecs->event_thread->current_line
51845796c8dcSSimon Schubert 	      && call_sal.symtab == ecs->event_thread->current_symtab)
51855796c8dcSSimon Schubert 	    keep_going (ecs);
51865796c8dcSSimon Schubert 	  else
51875796c8dcSSimon Schubert 	    {
5188c50c785cSJohn Marino 	      ecs->event_thread->control.stop_step = 1;
5189c50c785cSJohn Marino 	      print_end_stepping_range_reason ();
51905796c8dcSSimon Schubert 	      stop_stepping (ecs);
51915796c8dcSSimon Schubert 	    }
51925796c8dcSSimon Schubert 	  return;
51935796c8dcSSimon Schubert 	}
51945796c8dcSSimon Schubert     }
51955796c8dcSSimon Schubert 
51965796c8dcSSimon Schubert   /* Look for "calls" to inlined functions, part two.  If we are still
51975796c8dcSSimon Schubert      in the same real function we were stepping through, but we have
51985796c8dcSSimon Schubert      to go further up to find the exact frame ID, we are stepping
51995796c8dcSSimon Schubert      through a more inlined call beyond its call site.  */
52005796c8dcSSimon Schubert 
52015796c8dcSSimon Schubert   if (get_frame_type (get_current_frame ()) == INLINE_FRAME
52025796c8dcSSimon Schubert       && !frame_id_eq (get_frame_id (get_current_frame ()),
5203c50c785cSJohn Marino 		       ecs->event_thread->control.step_frame_id)
52045796c8dcSSimon Schubert       && stepped_in_from (get_current_frame (),
5205c50c785cSJohn Marino 			  ecs->event_thread->control.step_frame_id))
52065796c8dcSSimon Schubert     {
52075796c8dcSSimon Schubert       if (debug_infrun)
52085796c8dcSSimon Schubert 	fprintf_unfiltered (gdb_stdlog,
52095796c8dcSSimon Schubert 			    "infrun: stepping through inlined function\n");
52105796c8dcSSimon Schubert 
5211c50c785cSJohn Marino       if (ecs->event_thread->control.step_over_calls == STEP_OVER_ALL)
52125796c8dcSSimon Schubert 	keep_going (ecs);
52135796c8dcSSimon Schubert       else
52145796c8dcSSimon Schubert 	{
5215c50c785cSJohn Marino 	  ecs->event_thread->control.stop_step = 1;
5216c50c785cSJohn Marino 	  print_end_stepping_range_reason ();
52175796c8dcSSimon Schubert 	  stop_stepping (ecs);
52185796c8dcSSimon Schubert 	}
52195796c8dcSSimon Schubert       return;
52205796c8dcSSimon Schubert     }
52215796c8dcSSimon Schubert 
52225796c8dcSSimon Schubert   if ((stop_pc == stop_pc_sal.pc)
52235796c8dcSSimon Schubert       && (ecs->event_thread->current_line != stop_pc_sal.line
52245796c8dcSSimon Schubert  	  || ecs->event_thread->current_symtab != stop_pc_sal.symtab))
52255796c8dcSSimon Schubert     {
52265796c8dcSSimon Schubert       /* We are at the start of a different line.  So stop.  Note that
52275796c8dcSSimon Schubert          we don't stop if we step into the middle of a different line.
52285796c8dcSSimon Schubert          That is said to make things like for (;;) statements work
52295796c8dcSSimon Schubert          better.  */
52305796c8dcSSimon Schubert       if (debug_infrun)
5231c50c785cSJohn Marino 	 fprintf_unfiltered (gdb_stdlog,
5232c50c785cSJohn Marino 			     "infrun: stepped to a different line\n");
5233c50c785cSJohn Marino       ecs->event_thread->control.stop_step = 1;
5234c50c785cSJohn Marino       print_end_stepping_range_reason ();
52355796c8dcSSimon Schubert       stop_stepping (ecs);
52365796c8dcSSimon Schubert       return;
52375796c8dcSSimon Schubert     }
52385796c8dcSSimon Schubert 
52395796c8dcSSimon Schubert   /* We aren't done stepping.
52405796c8dcSSimon Schubert 
52415796c8dcSSimon Schubert      Optimize by setting the stepping range to the line.
52425796c8dcSSimon Schubert      (We might not be in the original line, but if we entered a
52435796c8dcSSimon Schubert      new line in mid-statement, we continue stepping.  This makes
52445796c8dcSSimon Schubert      things like for(;;) statements work better.)  */
52455796c8dcSSimon Schubert 
5246c50c785cSJohn Marino   ecs->event_thread->control.step_range_start = stop_pc_sal.pc;
5247c50c785cSJohn Marino   ecs->event_thread->control.step_range_end = stop_pc_sal.end;
52485796c8dcSSimon Schubert   set_step_info (frame, stop_pc_sal);
52495796c8dcSSimon Schubert 
52505796c8dcSSimon Schubert   if (debug_infrun)
52515796c8dcSSimon Schubert      fprintf_unfiltered (gdb_stdlog, "infrun: keep going\n");
52525796c8dcSSimon Schubert   keep_going (ecs);
52535796c8dcSSimon Schubert }
52545796c8dcSSimon Schubert 
52555796c8dcSSimon Schubert /* Is thread TP in the middle of single-stepping?  */
52565796c8dcSSimon Schubert 
52575796c8dcSSimon Schubert static int
currently_stepping(struct thread_info * tp)52585796c8dcSSimon Schubert currently_stepping (struct thread_info *tp)
52595796c8dcSSimon Schubert {
5260c50c785cSJohn Marino   return ((tp->control.step_range_end
5261c50c785cSJohn Marino 	   && tp->control.step_resume_breakpoint == NULL)
5262c50c785cSJohn Marino 	  || tp->control.trap_expected
52635796c8dcSSimon Schubert 	  || bpstat_should_step ());
52645796c8dcSSimon Schubert }
52655796c8dcSSimon Schubert 
52665796c8dcSSimon Schubert /* Returns true if any thread *but* the one passed in "data" is in the
52675796c8dcSSimon Schubert    middle of stepping or of handling a "next".  */
52685796c8dcSSimon Schubert 
52695796c8dcSSimon Schubert static int
currently_stepping_or_nexting_callback(struct thread_info * tp,void * data)52705796c8dcSSimon Schubert currently_stepping_or_nexting_callback (struct thread_info *tp, void *data)
52715796c8dcSSimon Schubert {
52725796c8dcSSimon Schubert   if (tp == data)
52735796c8dcSSimon Schubert     return 0;
52745796c8dcSSimon Schubert 
5275c50c785cSJohn Marino   return (tp->control.step_range_end
5276a45ae5f8SJohn Marino  	  || tp->control.trap_expected);
52775796c8dcSSimon Schubert }
52785796c8dcSSimon Schubert 
52795796c8dcSSimon Schubert /* Inferior has stepped into a subroutine call with source code that
52805796c8dcSSimon Schubert    we should not step over.  Do step to the first line of code in
52815796c8dcSSimon Schubert    it.  */
52825796c8dcSSimon Schubert 
52835796c8dcSSimon Schubert static void
handle_step_into_function(struct gdbarch * gdbarch,struct execution_control_state * ecs)52845796c8dcSSimon Schubert handle_step_into_function (struct gdbarch *gdbarch,
52855796c8dcSSimon Schubert 			   struct execution_control_state *ecs)
52865796c8dcSSimon Schubert {
52875796c8dcSSimon Schubert   struct symtab *s;
52885796c8dcSSimon Schubert   struct symtab_and_line stop_func_sal, sr_sal;
52895796c8dcSSimon Schubert 
5290a45ae5f8SJohn Marino   fill_in_stop_func (gdbarch, ecs);
5291a45ae5f8SJohn Marino 
52925796c8dcSSimon Schubert   s = find_pc_symtab (stop_pc);
52935796c8dcSSimon Schubert   if (s && s->language != language_asm)
52945796c8dcSSimon Schubert     ecs->stop_func_start = gdbarch_skip_prologue (gdbarch,
52955796c8dcSSimon Schubert 						  ecs->stop_func_start);
52965796c8dcSSimon Schubert 
52975796c8dcSSimon Schubert   stop_func_sal = find_pc_line (ecs->stop_func_start, 0);
52985796c8dcSSimon Schubert   /* Use the step_resume_break to step until the end of the prologue,
52995796c8dcSSimon Schubert      even if that involves jumps (as it seems to on the vax under
53005796c8dcSSimon Schubert      4.2).  */
53015796c8dcSSimon Schubert   /* If the prologue ends in the middle of a source line, continue to
53025796c8dcSSimon Schubert      the end of that source line (if it is still within the function).
53035796c8dcSSimon Schubert      Otherwise, just go to end of prologue.  */
53045796c8dcSSimon Schubert   if (stop_func_sal.end
53055796c8dcSSimon Schubert       && stop_func_sal.pc != ecs->stop_func_start
53065796c8dcSSimon Schubert       && stop_func_sal.end < ecs->stop_func_end)
53075796c8dcSSimon Schubert     ecs->stop_func_start = stop_func_sal.end;
53085796c8dcSSimon Schubert 
53095796c8dcSSimon Schubert   /* Architectures which require breakpoint adjustment might not be able
53105796c8dcSSimon Schubert      to place a breakpoint at the computed address.  If so, the test
53115796c8dcSSimon Schubert      ``ecs->stop_func_start == stop_pc'' will never succeed.  Adjust
53125796c8dcSSimon Schubert      ecs->stop_func_start to an address at which a breakpoint may be
53135796c8dcSSimon Schubert      legitimately placed.
53145796c8dcSSimon Schubert 
53155796c8dcSSimon Schubert      Note:  kevinb/2004-01-19:  On FR-V, if this adjustment is not
53165796c8dcSSimon Schubert      made, GDB will enter an infinite loop when stepping through
53175796c8dcSSimon Schubert      optimized code consisting of VLIW instructions which contain
53185796c8dcSSimon Schubert      subinstructions corresponding to different source lines.  On
53195796c8dcSSimon Schubert      FR-V, it's not permitted to place a breakpoint on any but the
53205796c8dcSSimon Schubert      first subinstruction of a VLIW instruction.  When a breakpoint is
53215796c8dcSSimon Schubert      set, GDB will adjust the breakpoint address to the beginning of
53225796c8dcSSimon Schubert      the VLIW instruction.  Thus, we need to make the corresponding
53235796c8dcSSimon Schubert      adjustment here when computing the stop address.  */
53245796c8dcSSimon Schubert 
53255796c8dcSSimon Schubert   if (gdbarch_adjust_breakpoint_address_p (gdbarch))
53265796c8dcSSimon Schubert     {
53275796c8dcSSimon Schubert       ecs->stop_func_start
53285796c8dcSSimon Schubert 	= gdbarch_adjust_breakpoint_address (gdbarch,
53295796c8dcSSimon Schubert 					     ecs->stop_func_start);
53305796c8dcSSimon Schubert     }
53315796c8dcSSimon Schubert 
53325796c8dcSSimon Schubert   if (ecs->stop_func_start == stop_pc)
53335796c8dcSSimon Schubert     {
53345796c8dcSSimon Schubert       /* We are already there: stop now.  */
5335c50c785cSJohn Marino       ecs->event_thread->control.stop_step = 1;
5336c50c785cSJohn Marino       print_end_stepping_range_reason ();
53375796c8dcSSimon Schubert       stop_stepping (ecs);
53385796c8dcSSimon Schubert       return;
53395796c8dcSSimon Schubert     }
53405796c8dcSSimon Schubert   else
53415796c8dcSSimon Schubert     {
53425796c8dcSSimon Schubert       /* Put the step-breakpoint there and go until there.  */
53435796c8dcSSimon Schubert       init_sal (&sr_sal);	/* initialize to zeroes */
53445796c8dcSSimon Schubert       sr_sal.pc = ecs->stop_func_start;
53455796c8dcSSimon Schubert       sr_sal.section = find_pc_overlay (ecs->stop_func_start);
5346cf7f2e2dSJohn Marino       sr_sal.pspace = get_frame_program_space (get_current_frame ());
53475796c8dcSSimon Schubert 
53485796c8dcSSimon Schubert       /* Do not specify what the fp should be when we stop since on
53495796c8dcSSimon Schubert          some machines the prologue is where the new fp value is
53505796c8dcSSimon Schubert          established.  */
53515796c8dcSSimon Schubert       insert_step_resume_breakpoint_at_sal (gdbarch, sr_sal, null_frame_id);
53525796c8dcSSimon Schubert 
53535796c8dcSSimon Schubert       /* And make sure stepping stops right away then.  */
5354c50c785cSJohn Marino       ecs->event_thread->control.step_range_end
5355c50c785cSJohn Marino         = ecs->event_thread->control.step_range_start;
53565796c8dcSSimon Schubert     }
53575796c8dcSSimon Schubert   keep_going (ecs);
53585796c8dcSSimon Schubert }
53595796c8dcSSimon Schubert 
53605796c8dcSSimon Schubert /* Inferior has stepped backward into a subroutine call with source
53615796c8dcSSimon Schubert    code that we should not step over.  Do step to the beginning of the
53625796c8dcSSimon Schubert    last line of code in it.  */
53635796c8dcSSimon Schubert 
53645796c8dcSSimon Schubert static void
handle_step_into_function_backward(struct gdbarch * gdbarch,struct execution_control_state * ecs)53655796c8dcSSimon Schubert handle_step_into_function_backward (struct gdbarch *gdbarch,
53665796c8dcSSimon Schubert 				    struct execution_control_state *ecs)
53675796c8dcSSimon Schubert {
53685796c8dcSSimon Schubert   struct symtab *s;
5369cf7f2e2dSJohn Marino   struct symtab_and_line stop_func_sal;
53705796c8dcSSimon Schubert 
5371a45ae5f8SJohn Marino   fill_in_stop_func (gdbarch, ecs);
5372a45ae5f8SJohn Marino 
53735796c8dcSSimon Schubert   s = find_pc_symtab (stop_pc);
53745796c8dcSSimon Schubert   if (s && s->language != language_asm)
53755796c8dcSSimon Schubert     ecs->stop_func_start = gdbarch_skip_prologue (gdbarch,
53765796c8dcSSimon Schubert 						  ecs->stop_func_start);
53775796c8dcSSimon Schubert 
53785796c8dcSSimon Schubert   stop_func_sal = find_pc_line (stop_pc, 0);
53795796c8dcSSimon Schubert 
53805796c8dcSSimon Schubert   /* OK, we're just going to keep stepping here.  */
53815796c8dcSSimon Schubert   if (stop_func_sal.pc == stop_pc)
53825796c8dcSSimon Schubert     {
53835796c8dcSSimon Schubert       /* We're there already.  Just stop stepping now.  */
5384c50c785cSJohn Marino       ecs->event_thread->control.stop_step = 1;
5385c50c785cSJohn Marino       print_end_stepping_range_reason ();
53865796c8dcSSimon Schubert       stop_stepping (ecs);
53875796c8dcSSimon Schubert     }
53885796c8dcSSimon Schubert   else
53895796c8dcSSimon Schubert     {
53905796c8dcSSimon Schubert       /* Else just reset the step range and keep going.
53915796c8dcSSimon Schubert 	 No step-resume breakpoint, they don't work for
53925796c8dcSSimon Schubert 	 epilogues, which can have multiple entry paths.  */
5393c50c785cSJohn Marino       ecs->event_thread->control.step_range_start = stop_func_sal.pc;
5394c50c785cSJohn Marino       ecs->event_thread->control.step_range_end = stop_func_sal.end;
53955796c8dcSSimon Schubert       keep_going (ecs);
53965796c8dcSSimon Schubert     }
53975796c8dcSSimon Schubert   return;
53985796c8dcSSimon Schubert }
53995796c8dcSSimon Schubert 
54005796c8dcSSimon Schubert /* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID.
54015796c8dcSSimon Schubert    This is used to both functions and to skip over code.  */
54025796c8dcSSimon Schubert 
54035796c8dcSSimon Schubert static void
insert_step_resume_breakpoint_at_sal_1(struct gdbarch * gdbarch,struct symtab_and_line sr_sal,struct frame_id sr_id,enum bptype sr_type)5404a45ae5f8SJohn Marino insert_step_resume_breakpoint_at_sal_1 (struct gdbarch *gdbarch,
54055796c8dcSSimon Schubert 					struct symtab_and_line sr_sal,
5406a45ae5f8SJohn Marino 					struct frame_id sr_id,
5407a45ae5f8SJohn Marino 					enum bptype sr_type)
54085796c8dcSSimon Schubert {
54095796c8dcSSimon Schubert   /* There should never be more than one step-resume or longjmp-resume
54105796c8dcSSimon Schubert      breakpoint per thread, so we should never be setting a new
54115796c8dcSSimon Schubert      step_resume_breakpoint when one is already active.  */
5412c50c785cSJohn Marino   gdb_assert (inferior_thread ()->control.step_resume_breakpoint == NULL);
5413a45ae5f8SJohn Marino   gdb_assert (sr_type == bp_step_resume || sr_type == bp_hp_step_resume);
54145796c8dcSSimon Schubert 
54155796c8dcSSimon Schubert   if (debug_infrun)
54165796c8dcSSimon Schubert     fprintf_unfiltered (gdb_stdlog,
54175796c8dcSSimon Schubert 			"infrun: inserting step-resume breakpoint at %s\n",
54185796c8dcSSimon Schubert 			paddress (gdbarch, sr_sal.pc));
54195796c8dcSSimon Schubert 
5420c50c785cSJohn Marino   inferior_thread ()->control.step_resume_breakpoint
5421a45ae5f8SJohn Marino     = set_momentary_breakpoint (gdbarch, sr_sal, sr_id, sr_type);
54225796c8dcSSimon Schubert }
54235796c8dcSSimon Schubert 
5424a45ae5f8SJohn Marino void
insert_step_resume_breakpoint_at_sal(struct gdbarch * gdbarch,struct symtab_and_line sr_sal,struct frame_id sr_id)5425a45ae5f8SJohn Marino insert_step_resume_breakpoint_at_sal (struct gdbarch *gdbarch,
5426a45ae5f8SJohn Marino 				      struct symtab_and_line sr_sal,
5427a45ae5f8SJohn Marino 				      struct frame_id sr_id)
5428a45ae5f8SJohn Marino {
5429a45ae5f8SJohn Marino   insert_step_resume_breakpoint_at_sal_1 (gdbarch,
5430a45ae5f8SJohn Marino 					  sr_sal, sr_id,
5431a45ae5f8SJohn Marino 					  bp_step_resume);
5432a45ae5f8SJohn Marino }
5433a45ae5f8SJohn Marino 
5434a45ae5f8SJohn Marino /* Insert a "high-priority step-resume breakpoint" at RETURN_FRAME.pc.
5435a45ae5f8SJohn Marino    This is used to skip a potential signal handler.
54365796c8dcSSimon Schubert 
54375796c8dcSSimon Schubert    This is called with the interrupted function's frame.  The signal
54385796c8dcSSimon Schubert    handler, when it returns, will resume the interrupted function at
54395796c8dcSSimon Schubert    RETURN_FRAME.pc.  */
54405796c8dcSSimon Schubert 
54415796c8dcSSimon Schubert static void
insert_hp_step_resume_breakpoint_at_frame(struct frame_info * return_frame)5442a45ae5f8SJohn Marino insert_hp_step_resume_breakpoint_at_frame (struct frame_info *return_frame)
54435796c8dcSSimon Schubert {
54445796c8dcSSimon Schubert   struct symtab_and_line sr_sal;
54455796c8dcSSimon Schubert   struct gdbarch *gdbarch;
54465796c8dcSSimon Schubert 
54475796c8dcSSimon Schubert   gdb_assert (return_frame != NULL);
54485796c8dcSSimon Schubert   init_sal (&sr_sal);		/* initialize to zeros */
54495796c8dcSSimon Schubert 
54505796c8dcSSimon Schubert   gdbarch = get_frame_arch (return_frame);
54515796c8dcSSimon Schubert   sr_sal.pc = gdbarch_addr_bits_remove (gdbarch, get_frame_pc (return_frame));
54525796c8dcSSimon Schubert   sr_sal.section = find_pc_overlay (sr_sal.pc);
5453cf7f2e2dSJohn Marino   sr_sal.pspace = get_frame_program_space (return_frame);
54545796c8dcSSimon Schubert 
5455a45ae5f8SJohn Marino   insert_step_resume_breakpoint_at_sal_1 (gdbarch, sr_sal,
5456a45ae5f8SJohn Marino 					  get_stack_frame_id (return_frame),
5457a45ae5f8SJohn Marino 					  bp_hp_step_resume);
54585796c8dcSSimon Schubert }
54595796c8dcSSimon Schubert 
5460a45ae5f8SJohn Marino /* Insert a "step-resume breakpoint" at the previous frame's PC.  This
5461a45ae5f8SJohn Marino    is used to skip a function after stepping into it (for "next" or if
5462a45ae5f8SJohn Marino    the called function has no debugging information).
54635796c8dcSSimon Schubert 
54645796c8dcSSimon Schubert    The current function has almost always been reached by single
54655796c8dcSSimon Schubert    stepping a call or return instruction.  NEXT_FRAME belongs to the
54665796c8dcSSimon Schubert    current function, and the breakpoint will be set at the caller's
54675796c8dcSSimon Schubert    resume address.
54685796c8dcSSimon Schubert 
54695796c8dcSSimon Schubert    This is a separate function rather than reusing
5470a45ae5f8SJohn Marino    insert_hp_step_resume_breakpoint_at_frame in order to avoid
54715796c8dcSSimon Schubert    get_prev_frame, which may stop prematurely (see the implementation
54725796c8dcSSimon Schubert    of frame_unwind_caller_id for an example).  */
54735796c8dcSSimon Schubert 
54745796c8dcSSimon Schubert static void
insert_step_resume_breakpoint_at_caller(struct frame_info * next_frame)54755796c8dcSSimon Schubert insert_step_resume_breakpoint_at_caller (struct frame_info *next_frame)
54765796c8dcSSimon Schubert {
54775796c8dcSSimon Schubert   struct symtab_and_line sr_sal;
54785796c8dcSSimon Schubert   struct gdbarch *gdbarch;
54795796c8dcSSimon Schubert 
54805796c8dcSSimon Schubert   /* We shouldn't have gotten here if we don't know where the call site
54815796c8dcSSimon Schubert      is.  */
54825796c8dcSSimon Schubert   gdb_assert (frame_id_p (frame_unwind_caller_id (next_frame)));
54835796c8dcSSimon Schubert 
54845796c8dcSSimon Schubert   init_sal (&sr_sal);		/* initialize to zeros */
54855796c8dcSSimon Schubert 
54865796c8dcSSimon Schubert   gdbarch = frame_unwind_caller_arch (next_frame);
54875796c8dcSSimon Schubert   sr_sal.pc = gdbarch_addr_bits_remove (gdbarch,
54885796c8dcSSimon Schubert 					frame_unwind_caller_pc (next_frame));
54895796c8dcSSimon Schubert   sr_sal.section = find_pc_overlay (sr_sal.pc);
5490cf7f2e2dSJohn Marino   sr_sal.pspace = frame_unwind_program_space (next_frame);
54915796c8dcSSimon Schubert 
54925796c8dcSSimon Schubert   insert_step_resume_breakpoint_at_sal (gdbarch, sr_sal,
54935796c8dcSSimon Schubert 					frame_unwind_caller_id (next_frame));
54945796c8dcSSimon Schubert }
54955796c8dcSSimon Schubert 
54965796c8dcSSimon Schubert /* Insert a "longjmp-resume" breakpoint at PC.  This is used to set a
54975796c8dcSSimon Schubert    new breakpoint at the target of a jmp_buf.  The handling of
54985796c8dcSSimon Schubert    longjmp-resume uses the same mechanisms used for handling
54995796c8dcSSimon Schubert    "step-resume" breakpoints.  */
55005796c8dcSSimon Schubert 
55015796c8dcSSimon Schubert static void
insert_longjmp_resume_breakpoint(struct gdbarch * gdbarch,CORE_ADDR pc)55025796c8dcSSimon Schubert insert_longjmp_resume_breakpoint (struct gdbarch *gdbarch, CORE_ADDR pc)
55035796c8dcSSimon Schubert {
5504*ef5ccd6cSJohn Marino   /* There should never be more than one longjmp-resume breakpoint per
5505*ef5ccd6cSJohn Marino      thread, so we should never be setting a new
55065796c8dcSSimon Schubert      longjmp_resume_breakpoint when one is already active.  */
5507*ef5ccd6cSJohn Marino   gdb_assert (inferior_thread ()->control.exception_resume_breakpoint == NULL);
55085796c8dcSSimon Schubert 
55095796c8dcSSimon Schubert   if (debug_infrun)
55105796c8dcSSimon Schubert     fprintf_unfiltered (gdb_stdlog,
55115796c8dcSSimon Schubert 			"infrun: inserting longjmp-resume breakpoint at %s\n",
55125796c8dcSSimon Schubert 			paddress (gdbarch, pc));
55135796c8dcSSimon Schubert 
5514*ef5ccd6cSJohn Marino   inferior_thread ()->control.exception_resume_breakpoint =
55155796c8dcSSimon Schubert     set_momentary_breakpoint_at_pc (gdbarch, pc, bp_longjmp_resume);
55165796c8dcSSimon Schubert }
55175796c8dcSSimon Schubert 
5518c50c785cSJohn Marino /* Insert an exception resume breakpoint.  TP is the thread throwing
5519c50c785cSJohn Marino    the exception.  The block B is the block of the unwinder debug hook
5520c50c785cSJohn Marino    function.  FRAME is the frame corresponding to the call to this
5521c50c785cSJohn Marino    function.  SYM is the symbol of the function argument holding the
5522c50c785cSJohn Marino    target PC of the exception.  */
5523c50c785cSJohn Marino 
5524c50c785cSJohn Marino static void
insert_exception_resume_breakpoint(struct thread_info * tp,struct block * b,struct frame_info * frame,struct symbol * sym)5525c50c785cSJohn Marino insert_exception_resume_breakpoint (struct thread_info *tp,
5526c50c785cSJohn Marino 				    struct block *b,
5527c50c785cSJohn Marino 				    struct frame_info *frame,
5528c50c785cSJohn Marino 				    struct symbol *sym)
5529c50c785cSJohn Marino {
5530*ef5ccd6cSJohn Marino   volatile struct gdb_exception e;
5531c50c785cSJohn Marino 
5532c50c785cSJohn Marino   /* We want to ignore errors here.  */
5533c50c785cSJohn Marino   TRY_CATCH (e, RETURN_MASK_ERROR)
5534c50c785cSJohn Marino     {
5535c50c785cSJohn Marino       struct symbol *vsym;
5536c50c785cSJohn Marino       struct value *value;
5537c50c785cSJohn Marino       CORE_ADDR handler;
5538c50c785cSJohn Marino       struct breakpoint *bp;
5539c50c785cSJohn Marino 
5540c50c785cSJohn Marino       vsym = lookup_symbol (SYMBOL_LINKAGE_NAME (sym), b, VAR_DOMAIN, NULL);
5541c50c785cSJohn Marino       value = read_var_value (vsym, frame);
5542c50c785cSJohn Marino       /* If the value was optimized out, revert to the old behavior.  */
5543c50c785cSJohn Marino       if (! value_optimized_out (value))
5544c50c785cSJohn Marino 	{
5545c50c785cSJohn Marino 	  handler = value_as_address (value);
5546c50c785cSJohn Marino 
5547c50c785cSJohn Marino 	  if (debug_infrun)
5548c50c785cSJohn Marino 	    fprintf_unfiltered (gdb_stdlog,
5549c50c785cSJohn Marino 				"infrun: exception resume at %lx\n",
5550c50c785cSJohn Marino 				(unsigned long) handler);
5551c50c785cSJohn Marino 
5552c50c785cSJohn Marino 	  bp = set_momentary_breakpoint_at_pc (get_frame_arch (frame),
5553c50c785cSJohn Marino 					       handler, bp_exception_resume);
5554*ef5ccd6cSJohn Marino 
5555*ef5ccd6cSJohn Marino 	  /* set_momentary_breakpoint_at_pc invalidates FRAME.  */
5556*ef5ccd6cSJohn Marino 	  frame = NULL;
5557*ef5ccd6cSJohn Marino 
5558c50c785cSJohn Marino 	  bp->thread = tp->num;
5559c50c785cSJohn Marino 	  inferior_thread ()->control.exception_resume_breakpoint = bp;
5560c50c785cSJohn Marino 	}
5561c50c785cSJohn Marino     }
5562c50c785cSJohn Marino }
5563c50c785cSJohn Marino 
5564*ef5ccd6cSJohn Marino /* A helper for check_exception_resume that sets an
5565*ef5ccd6cSJohn Marino    exception-breakpoint based on a SystemTap probe.  */
5566*ef5ccd6cSJohn Marino 
5567*ef5ccd6cSJohn Marino static void
insert_exception_resume_from_probe(struct thread_info * tp,const struct probe * probe,struct frame_info * frame)5568*ef5ccd6cSJohn Marino insert_exception_resume_from_probe (struct thread_info *tp,
5569*ef5ccd6cSJohn Marino 				    const struct probe *probe,
5570*ef5ccd6cSJohn Marino 				    struct frame_info *frame)
5571*ef5ccd6cSJohn Marino {
5572*ef5ccd6cSJohn Marino   struct value *arg_value;
5573*ef5ccd6cSJohn Marino   CORE_ADDR handler;
5574*ef5ccd6cSJohn Marino   struct breakpoint *bp;
5575*ef5ccd6cSJohn Marino 
5576*ef5ccd6cSJohn Marino   arg_value = probe_safe_evaluate_at_pc (frame, 1);
5577*ef5ccd6cSJohn Marino   if (!arg_value)
5578*ef5ccd6cSJohn Marino     return;
5579*ef5ccd6cSJohn Marino 
5580*ef5ccd6cSJohn Marino   handler = value_as_address (arg_value);
5581*ef5ccd6cSJohn Marino 
5582*ef5ccd6cSJohn Marino   if (debug_infrun)
5583*ef5ccd6cSJohn Marino     fprintf_unfiltered (gdb_stdlog,
5584*ef5ccd6cSJohn Marino 			"infrun: exception resume at %s\n",
5585*ef5ccd6cSJohn Marino 			paddress (get_objfile_arch (probe->objfile),
5586*ef5ccd6cSJohn Marino 				  handler));
5587*ef5ccd6cSJohn Marino 
5588*ef5ccd6cSJohn Marino   bp = set_momentary_breakpoint_at_pc (get_frame_arch (frame),
5589*ef5ccd6cSJohn Marino 				       handler, bp_exception_resume);
5590*ef5ccd6cSJohn Marino   bp->thread = tp->num;
5591*ef5ccd6cSJohn Marino   inferior_thread ()->control.exception_resume_breakpoint = bp;
5592*ef5ccd6cSJohn Marino }
5593*ef5ccd6cSJohn Marino 
5594c50c785cSJohn Marino /* This is called when an exception has been intercepted.  Check to
5595c50c785cSJohn Marino    see whether the exception's destination is of interest, and if so,
5596c50c785cSJohn Marino    set an exception resume breakpoint there.  */
5597c50c785cSJohn Marino 
5598c50c785cSJohn Marino static void
check_exception_resume(struct execution_control_state * ecs,struct frame_info * frame)5599c50c785cSJohn Marino check_exception_resume (struct execution_control_state *ecs,
5600*ef5ccd6cSJohn Marino 			struct frame_info *frame)
5601c50c785cSJohn Marino {
5602*ef5ccd6cSJohn Marino   volatile struct gdb_exception e;
5603*ef5ccd6cSJohn Marino   const struct probe *probe;
5604*ef5ccd6cSJohn Marino   struct symbol *func;
5605*ef5ccd6cSJohn Marino 
5606*ef5ccd6cSJohn Marino   /* First see if this exception unwinding breakpoint was set via a
5607*ef5ccd6cSJohn Marino      SystemTap probe point.  If so, the probe has two arguments: the
5608*ef5ccd6cSJohn Marino      CFA and the HANDLER.  We ignore the CFA, extract the handler, and
5609*ef5ccd6cSJohn Marino      set a breakpoint there.  */
5610*ef5ccd6cSJohn Marino   probe = find_probe_by_pc (get_frame_pc (frame));
5611*ef5ccd6cSJohn Marino   if (probe)
5612*ef5ccd6cSJohn Marino     {
5613*ef5ccd6cSJohn Marino       insert_exception_resume_from_probe (ecs->event_thread, probe, frame);
5614*ef5ccd6cSJohn Marino       return;
5615*ef5ccd6cSJohn Marino     }
5616*ef5ccd6cSJohn Marino 
5617*ef5ccd6cSJohn Marino   func = get_frame_function (frame);
5618*ef5ccd6cSJohn Marino   if (!func)
5619*ef5ccd6cSJohn Marino     return;
5620c50c785cSJohn Marino 
5621c50c785cSJohn Marino   TRY_CATCH (e, RETURN_MASK_ERROR)
5622c50c785cSJohn Marino     {
5623c50c785cSJohn Marino       struct block *b;
5624*ef5ccd6cSJohn Marino       struct block_iterator iter;
5625c50c785cSJohn Marino       struct symbol *sym;
5626c50c785cSJohn Marino       int argno = 0;
5627c50c785cSJohn Marino 
5628c50c785cSJohn Marino       /* The exception breakpoint is a thread-specific breakpoint on
5629c50c785cSJohn Marino 	 the unwinder's debug hook, declared as:
5630c50c785cSJohn Marino 
5631c50c785cSJohn Marino 	 void _Unwind_DebugHook (void *cfa, void *handler);
5632c50c785cSJohn Marino 
5633c50c785cSJohn Marino 	 The CFA argument indicates the frame to which control is
5634c50c785cSJohn Marino 	 about to be transferred.  HANDLER is the destination PC.
5635c50c785cSJohn Marino 
5636c50c785cSJohn Marino 	 We ignore the CFA and set a temporary breakpoint at HANDLER.
5637c50c785cSJohn Marino 	 This is not extremely efficient but it avoids issues in gdb
5638c50c785cSJohn Marino 	 with computing the DWARF CFA, and it also works even in weird
5639c50c785cSJohn Marino 	 cases such as throwing an exception from inside a signal
5640c50c785cSJohn Marino 	 handler.  */
5641c50c785cSJohn Marino 
5642c50c785cSJohn Marino       b = SYMBOL_BLOCK_VALUE (func);
5643c50c785cSJohn Marino       ALL_BLOCK_SYMBOLS (b, iter, sym)
5644c50c785cSJohn Marino 	{
5645c50c785cSJohn Marino 	  if (!SYMBOL_IS_ARGUMENT (sym))
5646c50c785cSJohn Marino 	    continue;
5647c50c785cSJohn Marino 
5648c50c785cSJohn Marino 	  if (argno == 0)
5649c50c785cSJohn Marino 	    ++argno;
5650c50c785cSJohn Marino 	  else
5651c50c785cSJohn Marino 	    {
5652c50c785cSJohn Marino 	      insert_exception_resume_breakpoint (ecs->event_thread,
5653c50c785cSJohn Marino 						  b, frame, sym);
5654c50c785cSJohn Marino 	      break;
5655c50c785cSJohn Marino 	    }
5656c50c785cSJohn Marino 	}
5657c50c785cSJohn Marino     }
5658c50c785cSJohn Marino }
5659c50c785cSJohn Marino 
56605796c8dcSSimon Schubert static void
stop_stepping(struct execution_control_state * ecs)56615796c8dcSSimon Schubert stop_stepping (struct execution_control_state *ecs)
56625796c8dcSSimon Schubert {
56635796c8dcSSimon Schubert   if (debug_infrun)
56645796c8dcSSimon Schubert     fprintf_unfiltered (gdb_stdlog, "infrun: stop_stepping\n");
56655796c8dcSSimon Schubert 
56665796c8dcSSimon Schubert   /* Let callers know we don't want to wait for the inferior anymore.  */
56675796c8dcSSimon Schubert   ecs->wait_some_more = 0;
56685796c8dcSSimon Schubert }
56695796c8dcSSimon Schubert 
56705796c8dcSSimon Schubert /* This function handles various cases where we need to continue
56715796c8dcSSimon Schubert    waiting for the inferior.  */
5672c50c785cSJohn Marino /* (Used to be the keep_going: label in the old wait_for_inferior).  */
56735796c8dcSSimon Schubert 
56745796c8dcSSimon Schubert static void
keep_going(struct execution_control_state * ecs)56755796c8dcSSimon Schubert keep_going (struct execution_control_state *ecs)
56765796c8dcSSimon Schubert {
5677cf7f2e2dSJohn Marino   /* Make sure normal_stop is called if we get a QUIT handled before
5678cf7f2e2dSJohn Marino      reaching resume.  */
5679cf7f2e2dSJohn Marino   struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0);
5680cf7f2e2dSJohn Marino 
56815796c8dcSSimon Schubert   /* Save the pc before execution, to compare with pc after stop.  */
56825796c8dcSSimon Schubert   ecs->event_thread->prev_pc
56835796c8dcSSimon Schubert     = regcache_read_pc (get_thread_regcache (ecs->ptid));
56845796c8dcSSimon Schubert 
56855796c8dcSSimon Schubert   /* If we did not do break;, it means we should keep running the
56865796c8dcSSimon Schubert      inferior and not return to debugger.  */
56875796c8dcSSimon Schubert 
5688c50c785cSJohn Marino   if (ecs->event_thread->control.trap_expected
5689*ef5ccd6cSJohn Marino       && ecs->event_thread->suspend.stop_signal != GDB_SIGNAL_TRAP)
56905796c8dcSSimon Schubert     {
56915796c8dcSSimon Schubert       /* We took a signal (which we are supposed to pass through to
56925796c8dcSSimon Schubert 	 the inferior, else we'd not get here) and we haven't yet
56935796c8dcSSimon Schubert 	 gotten our trap.  Simply continue.  */
5694cf7f2e2dSJohn Marino 
5695cf7f2e2dSJohn Marino       discard_cleanups (old_cleanups);
56965796c8dcSSimon Schubert       resume (currently_stepping (ecs->event_thread),
5697c50c785cSJohn Marino 	      ecs->event_thread->suspend.stop_signal);
56985796c8dcSSimon Schubert     }
56995796c8dcSSimon Schubert   else
57005796c8dcSSimon Schubert     {
57015796c8dcSSimon Schubert       /* Either the trap was not expected, but we are continuing
57025796c8dcSSimon Schubert          anyway (the user asked that this signal be passed to the
57035796c8dcSSimon Schubert          child)
57045796c8dcSSimon Schubert          -- or --
57055796c8dcSSimon Schubert          The signal was SIGTRAP, e.g. it was our signal, but we
57065796c8dcSSimon Schubert          decided we should resume from it.
57075796c8dcSSimon Schubert 
57085796c8dcSSimon Schubert          We're going to run this baby now!
57095796c8dcSSimon Schubert 
57105796c8dcSSimon Schubert 	 Note that insert_breakpoints won't try to re-insert
57115796c8dcSSimon Schubert 	 already inserted breakpoints.  Therefore, we don't
57125796c8dcSSimon Schubert 	 care if breakpoints were already inserted, or not.  */
57135796c8dcSSimon Schubert 
57145796c8dcSSimon Schubert       if (ecs->event_thread->stepping_over_breakpoint)
57155796c8dcSSimon Schubert 	{
57165796c8dcSSimon Schubert 	  struct regcache *thread_regcache = get_thread_regcache (ecs->ptid);
5717cf7f2e2dSJohn Marino 
57185796c8dcSSimon Schubert 	  if (!use_displaced_stepping (get_regcache_arch (thread_regcache)))
57195796c8dcSSimon Schubert 	    /* Since we can't do a displaced step, we have to remove
57205796c8dcSSimon Schubert 	       the breakpoint while we step it.  To keep things
57215796c8dcSSimon Schubert 	       simple, we remove them all.  */
57225796c8dcSSimon Schubert 	    remove_breakpoints ();
57235796c8dcSSimon Schubert 	}
57245796c8dcSSimon Schubert       else
57255796c8dcSSimon Schubert 	{
5726*ef5ccd6cSJohn Marino 	  volatile struct gdb_exception e;
5727cf7f2e2dSJohn Marino 
57285796c8dcSSimon Schubert 	  /* Stop stepping when inserting breakpoints
57295796c8dcSSimon Schubert 	     has failed.  */
57305796c8dcSSimon Schubert 	  TRY_CATCH (e, RETURN_MASK_ERROR)
57315796c8dcSSimon Schubert 	    {
57325796c8dcSSimon Schubert 	      insert_breakpoints ();
57335796c8dcSSimon Schubert 	    }
57345796c8dcSSimon Schubert 	  if (e.reason < 0)
57355796c8dcSSimon Schubert 	    {
5736cf7f2e2dSJohn Marino 	      exception_print (gdb_stderr, e);
57375796c8dcSSimon Schubert 	      stop_stepping (ecs);
57385796c8dcSSimon Schubert 	      return;
57395796c8dcSSimon Schubert 	    }
57405796c8dcSSimon Schubert 	}
57415796c8dcSSimon Schubert 
5742c50c785cSJohn Marino       ecs->event_thread->control.trap_expected
5743c50c785cSJohn Marino 	= ecs->event_thread->stepping_over_breakpoint;
57445796c8dcSSimon Schubert 
57455796c8dcSSimon Schubert       /* Do not deliver SIGNAL_TRAP (except when the user explicitly
57465796c8dcSSimon Schubert          specifies that such a signal should be delivered to the
57475796c8dcSSimon Schubert          target program).
57485796c8dcSSimon Schubert 
57495796c8dcSSimon Schubert          Typically, this would occure when a user is debugging a
57505796c8dcSSimon Schubert          target monitor on a simulator: the target monitor sets a
57515796c8dcSSimon Schubert          breakpoint; the simulator encounters this break-point and
57525796c8dcSSimon Schubert          halts the simulation handing control to GDB; GDB, noteing
57535796c8dcSSimon Schubert          that the break-point isn't valid, returns control back to the
57545796c8dcSSimon Schubert          simulator; the simulator then delivers the hardware
57555796c8dcSSimon Schubert          equivalent of a SIGNAL_TRAP to the program being debugged.  */
57565796c8dcSSimon Schubert 
5757*ef5ccd6cSJohn Marino       if (ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP
5758c50c785cSJohn Marino 	  && !signal_program[ecs->event_thread->suspend.stop_signal])
5759*ef5ccd6cSJohn Marino 	ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0;
57605796c8dcSSimon Schubert 
5761cf7f2e2dSJohn Marino       discard_cleanups (old_cleanups);
57625796c8dcSSimon Schubert       resume (currently_stepping (ecs->event_thread),
5763c50c785cSJohn Marino 	      ecs->event_thread->suspend.stop_signal);
57645796c8dcSSimon Schubert     }
57655796c8dcSSimon Schubert 
57665796c8dcSSimon Schubert   prepare_to_wait (ecs);
57675796c8dcSSimon Schubert }
57685796c8dcSSimon Schubert 
57695796c8dcSSimon Schubert /* This function normally comes after a resume, before
57705796c8dcSSimon Schubert    handle_inferior_event exits.  It takes care of any last bits of
57715796c8dcSSimon Schubert    housekeeping, and sets the all-important wait_some_more flag.  */
57725796c8dcSSimon Schubert 
57735796c8dcSSimon Schubert static void
prepare_to_wait(struct execution_control_state * ecs)57745796c8dcSSimon Schubert prepare_to_wait (struct execution_control_state *ecs)
57755796c8dcSSimon Schubert {
57765796c8dcSSimon Schubert   if (debug_infrun)
57775796c8dcSSimon Schubert     fprintf_unfiltered (gdb_stdlog, "infrun: prepare_to_wait\n");
57785796c8dcSSimon Schubert 
57795796c8dcSSimon Schubert   /* This is the old end of the while loop.  Let everybody know we
57805796c8dcSSimon Schubert      want to wait for the inferior some more and get called again
57815796c8dcSSimon Schubert      soon.  */
57825796c8dcSSimon Schubert   ecs->wait_some_more = 1;
57835796c8dcSSimon Schubert }
57845796c8dcSSimon Schubert 
5785c50c785cSJohn Marino /* Several print_*_reason functions to print why the inferior has stopped.
5786c50c785cSJohn Marino    We always print something when the inferior exits, or receives a signal.
5787c50c785cSJohn Marino    The rest of the cases are dealt with later on in normal_stop and
5788c50c785cSJohn Marino    print_it_typical.  Ideally there should be a call to one of these
5789c50c785cSJohn Marino    print_*_reason functions functions from handle_inferior_event each time
5790c50c785cSJohn Marino    stop_stepping is called.  */
5791c50c785cSJohn Marino 
5792c50c785cSJohn Marino /* Print why the inferior has stopped.
5793c50c785cSJohn Marino    We are done with a step/next/si/ni command, print why the inferior has
5794c50c785cSJohn Marino    stopped.  For now print nothing.  Print a message only if not in the middle
5795c50c785cSJohn Marino    of doing a "step n" operation for n > 1.  */
5796c50c785cSJohn Marino 
57975796c8dcSSimon Schubert static void
print_end_stepping_range_reason(void)5798c50c785cSJohn Marino print_end_stepping_range_reason (void)
57995796c8dcSSimon Schubert {
5800c50c785cSJohn Marino   if ((!inferior_thread ()->step_multi
5801c50c785cSJohn Marino        || !inferior_thread ()->control.stop_step)
5802a45ae5f8SJohn Marino       && ui_out_is_mi_like_p (current_uiout))
5803a45ae5f8SJohn Marino     ui_out_field_string (current_uiout, "reason",
58045796c8dcSSimon Schubert                          async_reason_lookup (EXEC_ASYNC_END_STEPPING_RANGE));
5805c50c785cSJohn Marino }
5806c50c785cSJohn Marino 
5807c50c785cSJohn Marino /* The inferior was terminated by a signal, print why it stopped.  */
5808c50c785cSJohn Marino 
5809c50c785cSJohn Marino static void
print_signal_exited_reason(enum gdb_signal siggnal)5810*ef5ccd6cSJohn Marino print_signal_exited_reason (enum gdb_signal siggnal)
5811c50c785cSJohn Marino {
5812a45ae5f8SJohn Marino   struct ui_out *uiout = current_uiout;
5813a45ae5f8SJohn Marino 
58145796c8dcSSimon Schubert   annotate_signalled ();
58155796c8dcSSimon Schubert   if (ui_out_is_mi_like_p (uiout))
58165796c8dcSSimon Schubert     ui_out_field_string
5817c50c785cSJohn Marino       (uiout, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED));
58185796c8dcSSimon Schubert   ui_out_text (uiout, "\nProgram terminated with signal ");
58195796c8dcSSimon Schubert   annotate_signal_name ();
58205796c8dcSSimon Schubert   ui_out_field_string (uiout, "signal-name",
5821*ef5ccd6cSJohn Marino 		       gdb_signal_to_name (siggnal));
58225796c8dcSSimon Schubert   annotate_signal_name_end ();
58235796c8dcSSimon Schubert   ui_out_text (uiout, ", ");
58245796c8dcSSimon Schubert   annotate_signal_string ();
58255796c8dcSSimon Schubert   ui_out_field_string (uiout, "signal-meaning",
5826*ef5ccd6cSJohn Marino 		       gdb_signal_to_string (siggnal));
58275796c8dcSSimon Schubert   annotate_signal_string_end ();
58285796c8dcSSimon Schubert   ui_out_text (uiout, ".\n");
58295796c8dcSSimon Schubert   ui_out_text (uiout, "The program no longer exists.\n");
5830c50c785cSJohn Marino }
5831c50c785cSJohn Marino 
5832c50c785cSJohn Marino /* The inferior program is finished, print why it stopped.  */
5833c50c785cSJohn Marino 
5834c50c785cSJohn Marino static void
print_exited_reason(int exitstatus)5835c50c785cSJohn Marino print_exited_reason (int exitstatus)
5836c50c785cSJohn Marino {
5837c50c785cSJohn Marino   struct inferior *inf = current_inferior ();
5838c50c785cSJohn Marino   const char *pidstr = target_pid_to_str (pid_to_ptid (inf->pid));
5839a45ae5f8SJohn Marino   struct ui_out *uiout = current_uiout;
5840c50c785cSJohn Marino 
5841c50c785cSJohn Marino   annotate_exited (exitstatus);
5842c50c785cSJohn Marino   if (exitstatus)
58435796c8dcSSimon Schubert     {
58445796c8dcSSimon Schubert       if (ui_out_is_mi_like_p (uiout))
58455796c8dcSSimon Schubert 	ui_out_field_string (uiout, "reason",
58465796c8dcSSimon Schubert 			     async_reason_lookup (EXEC_ASYNC_EXITED));
5847c50c785cSJohn Marino       ui_out_text (uiout, "[Inferior ");
5848c50c785cSJohn Marino       ui_out_text (uiout, plongest (inf->num));
5849c50c785cSJohn Marino       ui_out_text (uiout, " (");
5850c50c785cSJohn Marino       ui_out_text (uiout, pidstr);
5851c50c785cSJohn Marino       ui_out_text (uiout, ") exited with code ");
5852c50c785cSJohn Marino       ui_out_field_fmt (uiout, "exit-code", "0%o", (unsigned int) exitstatus);
5853c50c785cSJohn Marino       ui_out_text (uiout, "]\n");
58545796c8dcSSimon Schubert     }
58555796c8dcSSimon Schubert   else
58565796c8dcSSimon Schubert     {
58575796c8dcSSimon Schubert       if (ui_out_is_mi_like_p (uiout))
58585796c8dcSSimon Schubert 	ui_out_field_string
5859c50c785cSJohn Marino 	  (uiout, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY));
5860c50c785cSJohn Marino       ui_out_text (uiout, "[Inferior ");
5861c50c785cSJohn Marino       ui_out_text (uiout, plongest (inf->num));
5862c50c785cSJohn Marino       ui_out_text (uiout, " (");
5863c50c785cSJohn Marino       ui_out_text (uiout, pidstr);
5864c50c785cSJohn Marino       ui_out_text (uiout, ") exited normally]\n");
58655796c8dcSSimon Schubert     }
58665796c8dcSSimon Schubert   /* Support the --return-child-result option.  */
5867c50c785cSJohn Marino   return_child_result_value = exitstatus;
5868c50c785cSJohn Marino }
5869c50c785cSJohn Marino 
5870c50c785cSJohn Marino /* Signal received, print why the inferior has stopped.  The signal table
5871c50c785cSJohn Marino    tells us to print about it.  */
5872c50c785cSJohn Marino 
5873c50c785cSJohn Marino static void
print_signal_received_reason(enum gdb_signal siggnal)5874*ef5ccd6cSJohn Marino print_signal_received_reason (enum gdb_signal siggnal)
5875c50c785cSJohn Marino {
5876a45ae5f8SJohn Marino   struct ui_out *uiout = current_uiout;
5877a45ae5f8SJohn Marino 
58785796c8dcSSimon Schubert   annotate_signal ();
58795796c8dcSSimon Schubert 
5880*ef5ccd6cSJohn Marino   if (siggnal == GDB_SIGNAL_0 && !ui_out_is_mi_like_p (uiout))
58815796c8dcSSimon Schubert     {
58825796c8dcSSimon Schubert       struct thread_info *t = inferior_thread ();
58835796c8dcSSimon Schubert 
58845796c8dcSSimon Schubert       ui_out_text (uiout, "\n[");
58855796c8dcSSimon Schubert       ui_out_field_string (uiout, "thread-name",
58865796c8dcSSimon Schubert 			   target_pid_to_str (t->ptid));
58875796c8dcSSimon Schubert       ui_out_field_fmt (uiout, "thread-id", "] #%d", t->num);
58885796c8dcSSimon Schubert       ui_out_text (uiout, " stopped");
58895796c8dcSSimon Schubert     }
58905796c8dcSSimon Schubert   else
58915796c8dcSSimon Schubert     {
58925796c8dcSSimon Schubert       ui_out_text (uiout, "\nProgram received signal ");
58935796c8dcSSimon Schubert       annotate_signal_name ();
58945796c8dcSSimon Schubert       if (ui_out_is_mi_like_p (uiout))
58955796c8dcSSimon Schubert 	ui_out_field_string
58965796c8dcSSimon Schubert 	  (uiout, "reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED));
58975796c8dcSSimon Schubert       ui_out_field_string (uiout, "signal-name",
5898*ef5ccd6cSJohn Marino 			   gdb_signal_to_name (siggnal));
58995796c8dcSSimon Schubert       annotate_signal_name_end ();
59005796c8dcSSimon Schubert       ui_out_text (uiout, ", ");
59015796c8dcSSimon Schubert       annotate_signal_string ();
59025796c8dcSSimon Schubert       ui_out_field_string (uiout, "signal-meaning",
5903*ef5ccd6cSJohn Marino 			   gdb_signal_to_string (siggnal));
59045796c8dcSSimon Schubert       annotate_signal_string_end ();
59055796c8dcSSimon Schubert     }
59065796c8dcSSimon Schubert   ui_out_text (uiout, ".\n");
5907c50c785cSJohn Marino }
5908c50c785cSJohn Marino 
5909c50c785cSJohn Marino /* Reverse execution: target ran out of history info, print why the inferior
5910c50c785cSJohn Marino    has stopped.  */
5911c50c785cSJohn Marino 
5912c50c785cSJohn Marino static void
print_no_history_reason(void)5913c50c785cSJohn Marino print_no_history_reason (void)
5914c50c785cSJohn Marino {
5915a45ae5f8SJohn Marino   ui_out_text (current_uiout, "\nNo more reverse-execution history.\n");
59165796c8dcSSimon Schubert }
59175796c8dcSSimon Schubert 
59185796c8dcSSimon Schubert /* Here to return control to GDB when the inferior stops for real.
59195796c8dcSSimon Schubert    Print appropriate messages, remove breakpoints, give terminal our modes.
59205796c8dcSSimon Schubert 
59215796c8dcSSimon Schubert    STOP_PRINT_FRAME nonzero means print the executing frame
59225796c8dcSSimon Schubert    (pc, function, args, file, line number and line text).
59235796c8dcSSimon Schubert    BREAKPOINTS_FAILED nonzero means stop was due to error
59245796c8dcSSimon Schubert    attempting to insert breakpoints.  */
59255796c8dcSSimon Schubert 
59265796c8dcSSimon Schubert void
normal_stop(void)59275796c8dcSSimon Schubert normal_stop (void)
59285796c8dcSSimon Schubert {
59295796c8dcSSimon Schubert   struct target_waitstatus last;
59305796c8dcSSimon Schubert   ptid_t last_ptid;
59315796c8dcSSimon Schubert   struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
59325796c8dcSSimon Schubert 
59335796c8dcSSimon Schubert   get_last_target_status (&last_ptid, &last);
59345796c8dcSSimon Schubert 
59355796c8dcSSimon Schubert   /* If an exception is thrown from this point on, make sure to
59365796c8dcSSimon Schubert      propagate GDB's knowledge of the executing state to the
59375796c8dcSSimon Schubert      frontend/user running state.  A QUIT is an easy exception to see
59385796c8dcSSimon Schubert      here, so do this before any filtered output.  */
59395796c8dcSSimon Schubert   if (!non_stop)
59405796c8dcSSimon Schubert     make_cleanup (finish_thread_state_cleanup, &minus_one_ptid);
59415796c8dcSSimon Schubert   else if (last.kind != TARGET_WAITKIND_SIGNALLED
5942a45ae5f8SJohn Marino 	   && last.kind != TARGET_WAITKIND_EXITED
5943a45ae5f8SJohn Marino 	   && last.kind != TARGET_WAITKIND_NO_RESUMED)
59445796c8dcSSimon Schubert     make_cleanup (finish_thread_state_cleanup, &inferior_ptid);
59455796c8dcSSimon Schubert 
59465796c8dcSSimon Schubert   /* In non-stop mode, we don't want GDB to switch threads behind the
59475796c8dcSSimon Schubert      user's back, to avoid races where the user is typing a command to
59485796c8dcSSimon Schubert      apply to thread x, but GDB switches to thread y before the user
59495796c8dcSSimon Schubert      finishes entering the command.  */
59505796c8dcSSimon Schubert 
59515796c8dcSSimon Schubert   /* As with the notification of thread events, we want to delay
59525796c8dcSSimon Schubert      notifying the user that we've switched thread context until
59535796c8dcSSimon Schubert      the inferior actually stops.
59545796c8dcSSimon Schubert 
59555796c8dcSSimon Schubert      There's no point in saying anything if the inferior has exited.
59565796c8dcSSimon Schubert      Note that SIGNALLED here means "exited with a signal", not
59575796c8dcSSimon Schubert      "received a signal".  */
59585796c8dcSSimon Schubert   if (!non_stop
59595796c8dcSSimon Schubert       && !ptid_equal (previous_inferior_ptid, inferior_ptid)
59605796c8dcSSimon Schubert       && target_has_execution
59615796c8dcSSimon Schubert       && last.kind != TARGET_WAITKIND_SIGNALLED
5962a45ae5f8SJohn Marino       && last.kind != TARGET_WAITKIND_EXITED
5963a45ae5f8SJohn Marino       && last.kind != TARGET_WAITKIND_NO_RESUMED)
59645796c8dcSSimon Schubert     {
59655796c8dcSSimon Schubert       target_terminal_ours_for_output ();
59665796c8dcSSimon Schubert       printf_filtered (_("[Switching to %s]\n"),
59675796c8dcSSimon Schubert 		       target_pid_to_str (inferior_ptid));
59685796c8dcSSimon Schubert       annotate_thread_changed ();
59695796c8dcSSimon Schubert       previous_inferior_ptid = inferior_ptid;
59705796c8dcSSimon Schubert     }
59715796c8dcSSimon Schubert 
5972a45ae5f8SJohn Marino   if (last.kind == TARGET_WAITKIND_NO_RESUMED)
5973a45ae5f8SJohn Marino     {
5974a45ae5f8SJohn Marino       gdb_assert (sync_execution || !target_can_async_p ());
5975a45ae5f8SJohn Marino 
5976a45ae5f8SJohn Marino       target_terminal_ours_for_output ();
5977a45ae5f8SJohn Marino       printf_filtered (_("No unwaited-for children left.\n"));
5978a45ae5f8SJohn Marino     }
5979a45ae5f8SJohn Marino 
59805796c8dcSSimon Schubert   if (!breakpoints_always_inserted_mode () && target_has_execution)
59815796c8dcSSimon Schubert     {
59825796c8dcSSimon Schubert       if (remove_breakpoints ())
59835796c8dcSSimon Schubert 	{
59845796c8dcSSimon Schubert 	  target_terminal_ours_for_output ();
5985c50c785cSJohn Marino 	  printf_filtered (_("Cannot remove breakpoints because "
5986c50c785cSJohn Marino 			     "program is no longer writable.\nFurther "
5987c50c785cSJohn Marino 			     "execution is probably impossible.\n"));
59885796c8dcSSimon Schubert 	}
59895796c8dcSSimon Schubert     }
59905796c8dcSSimon Schubert 
59915796c8dcSSimon Schubert   /* If an auto-display called a function and that got a signal,
59925796c8dcSSimon Schubert      delete that auto-display to avoid an infinite recursion.  */
59935796c8dcSSimon Schubert 
59945796c8dcSSimon Schubert   if (stopped_by_random_signal)
59955796c8dcSSimon Schubert     disable_current_display ();
59965796c8dcSSimon Schubert 
59975796c8dcSSimon Schubert   /* Don't print a message if in the middle of doing a "step n"
59985796c8dcSSimon Schubert      operation for n > 1 */
59995796c8dcSSimon Schubert   if (target_has_execution
60005796c8dcSSimon Schubert       && last.kind != TARGET_WAITKIND_SIGNALLED
60015796c8dcSSimon Schubert       && last.kind != TARGET_WAITKIND_EXITED
60025796c8dcSSimon Schubert       && inferior_thread ()->step_multi
6003c50c785cSJohn Marino       && inferior_thread ()->control.stop_step)
60045796c8dcSSimon Schubert     goto done;
60055796c8dcSSimon Schubert 
60065796c8dcSSimon Schubert   target_terminal_ours ();
6007a45ae5f8SJohn Marino   async_enable_stdin ();
60085796c8dcSSimon Schubert 
60095796c8dcSSimon Schubert   /* Set the current source location.  This will also happen if we
60105796c8dcSSimon Schubert      display the frame below, but the current SAL will be incorrect
60115796c8dcSSimon Schubert      during a user hook-stop function.  */
60125796c8dcSSimon Schubert   if (has_stack_frames () && !stop_stack_dummy)
60135796c8dcSSimon Schubert     set_current_sal_from_frame (get_current_frame (), 1);
60145796c8dcSSimon Schubert 
60155796c8dcSSimon Schubert   /* Let the user/frontend see the threads as stopped.  */
60165796c8dcSSimon Schubert   do_cleanups (old_chain);
60175796c8dcSSimon Schubert 
60185796c8dcSSimon Schubert   /* Look up the hook_stop and run it (CLI internally handles problem
60195796c8dcSSimon Schubert      of stop_command's pre-hook not existing).  */
60205796c8dcSSimon Schubert   if (stop_command)
60215796c8dcSSimon Schubert     catch_errors (hook_stop_stub, stop_command,
60225796c8dcSSimon Schubert 		  "Error while running hook_stop:\n", RETURN_MASK_ALL);
60235796c8dcSSimon Schubert 
60245796c8dcSSimon Schubert   if (!has_stack_frames ())
60255796c8dcSSimon Schubert     goto done;
60265796c8dcSSimon Schubert 
60275796c8dcSSimon Schubert   if (last.kind == TARGET_WAITKIND_SIGNALLED
60285796c8dcSSimon Schubert       || last.kind == TARGET_WAITKIND_EXITED)
60295796c8dcSSimon Schubert     goto done;
60305796c8dcSSimon Schubert 
60315796c8dcSSimon Schubert   /* Select innermost stack frame - i.e., current frame is frame 0,
60325796c8dcSSimon Schubert      and current location is based on that.
60335796c8dcSSimon Schubert      Don't do this on return from a stack dummy routine,
60345796c8dcSSimon Schubert      or if the program has exited.  */
60355796c8dcSSimon Schubert 
60365796c8dcSSimon Schubert   if (!stop_stack_dummy)
60375796c8dcSSimon Schubert     {
60385796c8dcSSimon Schubert       select_frame (get_current_frame ());
60395796c8dcSSimon Schubert 
60405796c8dcSSimon Schubert       /* Print current location without a level number, if
60415796c8dcSSimon Schubert          we have changed functions or hit a breakpoint.
60425796c8dcSSimon Schubert          Print source line if we have one.
60435796c8dcSSimon Schubert          bpstat_print() contains the logic deciding in detail
60445796c8dcSSimon Schubert          what to print, based on the event(s) that just occurred.  */
60455796c8dcSSimon Schubert 
60465796c8dcSSimon Schubert       /* If --batch-silent is enabled then there's no need to print the current
60475796c8dcSSimon Schubert 	 source location, and to try risks causing an error message about
60485796c8dcSSimon Schubert 	 missing source files.  */
60495796c8dcSSimon Schubert       if (stop_print_frame && !batch_silent)
60505796c8dcSSimon Schubert 	{
60515796c8dcSSimon Schubert 	  int bpstat_ret;
60525796c8dcSSimon Schubert 	  int source_flag;
60535796c8dcSSimon Schubert 	  int do_frame_printing = 1;
60545796c8dcSSimon Schubert 	  struct thread_info *tp = inferior_thread ();
60555796c8dcSSimon Schubert 
6056a45ae5f8SJohn Marino 	  bpstat_ret = bpstat_print (tp->control.stop_bpstat, last.kind);
60575796c8dcSSimon Schubert 	  switch (bpstat_ret)
60585796c8dcSSimon Schubert 	    {
60595796c8dcSSimon Schubert 	    case PRINT_UNKNOWN:
60605796c8dcSSimon Schubert 	      /* FIXME: cagney/2002-12-01: Given that a frame ID does
60615796c8dcSSimon Schubert 	         (or should) carry around the function and does (or
60625796c8dcSSimon Schubert 	         should) use that when doing a frame comparison.  */
6063c50c785cSJohn Marino 	      if (tp->control.stop_step
6064c50c785cSJohn Marino 		  && frame_id_eq (tp->control.step_frame_id,
60655796c8dcSSimon Schubert 				  get_frame_id (get_current_frame ()))
60665796c8dcSSimon Schubert 		  && step_start_function == find_pc_function (stop_pc))
6067c50c785cSJohn Marino 		source_flag = SRC_LINE;		/* Finished step, just
6068c50c785cSJohn Marino 						   print source line.  */
60695796c8dcSSimon Schubert 	      else
6070c50c785cSJohn Marino 		source_flag = SRC_AND_LOC;	/* Print location and
6071c50c785cSJohn Marino 						   source line.  */
60725796c8dcSSimon Schubert 	      break;
60735796c8dcSSimon Schubert 	    case PRINT_SRC_AND_LOC:
6074c50c785cSJohn Marino 	      source_flag = SRC_AND_LOC;	/* Print location and
6075c50c785cSJohn Marino 						   source line.  */
60765796c8dcSSimon Schubert 	      break;
60775796c8dcSSimon Schubert 	    case PRINT_SRC_ONLY:
60785796c8dcSSimon Schubert 	      source_flag = SRC_LINE;
60795796c8dcSSimon Schubert 	      break;
60805796c8dcSSimon Schubert 	    case PRINT_NOTHING:
60815796c8dcSSimon Schubert 	      source_flag = SRC_LINE;	/* something bogus */
60825796c8dcSSimon Schubert 	      do_frame_printing = 0;
60835796c8dcSSimon Schubert 	      break;
60845796c8dcSSimon Schubert 	    default:
60855796c8dcSSimon Schubert 	      internal_error (__FILE__, __LINE__, _("Unknown value."));
60865796c8dcSSimon Schubert 	    }
60875796c8dcSSimon Schubert 
60885796c8dcSSimon Schubert 	  /* The behavior of this routine with respect to the source
60895796c8dcSSimon Schubert 	     flag is:
60905796c8dcSSimon Schubert 	     SRC_LINE: Print only source line
60915796c8dcSSimon Schubert 	     LOCATION: Print only location
6092c50c785cSJohn Marino 	     SRC_AND_LOC: Print location and source line.  */
60935796c8dcSSimon Schubert 	  if (do_frame_printing)
60945796c8dcSSimon Schubert 	    print_stack_frame (get_selected_frame (NULL), 0, source_flag);
60955796c8dcSSimon Schubert 
60965796c8dcSSimon Schubert 	  /* Display the auto-display expressions.  */
60975796c8dcSSimon Schubert 	  do_displays ();
60985796c8dcSSimon Schubert 	}
60995796c8dcSSimon Schubert     }
61005796c8dcSSimon Schubert 
61015796c8dcSSimon Schubert   /* Save the function value return registers, if we care.
61025796c8dcSSimon Schubert      We might be about to restore their previous contents.  */
6103a45ae5f8SJohn Marino   if (inferior_thread ()->control.proceed_to_finish
6104a45ae5f8SJohn Marino       && execution_direction != EXEC_REVERSE)
61055796c8dcSSimon Schubert     {
61065796c8dcSSimon Schubert       /* This should not be necessary.  */
61075796c8dcSSimon Schubert       if (stop_registers)
61085796c8dcSSimon Schubert 	regcache_xfree (stop_registers);
61095796c8dcSSimon Schubert 
61105796c8dcSSimon Schubert       /* NB: The copy goes through to the target picking up the value of
61115796c8dcSSimon Schubert 	 all the registers.  */
61125796c8dcSSimon Schubert       stop_registers = regcache_dup (get_current_regcache ());
61135796c8dcSSimon Schubert     }
61145796c8dcSSimon Schubert 
6115cf7f2e2dSJohn Marino   if (stop_stack_dummy == STOP_STACK_DUMMY)
61165796c8dcSSimon Schubert     {
61175796c8dcSSimon Schubert       /* Pop the empty frame that contains the stack dummy.
61185796c8dcSSimon Schubert 	 This also restores inferior state prior to the call
6119c50c785cSJohn Marino 	 (struct infcall_suspend_state).  */
61205796c8dcSSimon Schubert       struct frame_info *frame = get_current_frame ();
6121cf7f2e2dSJohn Marino 
61225796c8dcSSimon Schubert       gdb_assert (get_frame_type (frame) == DUMMY_FRAME);
61235796c8dcSSimon Schubert       frame_pop (frame);
6124c50c785cSJohn Marino       /* frame_pop() calls reinit_frame_cache as the last thing it
6125c50c785cSJohn Marino 	 does which means there's currently no selected frame.  We
6126c50c785cSJohn Marino 	 don't need to re-establish a selected frame if the dummy call
6127c50c785cSJohn Marino 	 returns normally, that will be done by
6128c50c785cSJohn Marino 	 restore_infcall_control_state.  However, we do have to handle
6129c50c785cSJohn Marino 	 the case where the dummy call is returning after being
6130c50c785cSJohn Marino 	 stopped (e.g. the dummy call previously hit a breakpoint).
6131c50c785cSJohn Marino 	 We can't know which case we have so just always re-establish
6132c50c785cSJohn Marino 	 a selected frame here.  */
61335796c8dcSSimon Schubert       select_frame (get_current_frame ());
61345796c8dcSSimon Schubert     }
61355796c8dcSSimon Schubert 
61365796c8dcSSimon Schubert done:
61375796c8dcSSimon Schubert   annotate_stopped ();
61385796c8dcSSimon Schubert 
61395796c8dcSSimon Schubert   /* Suppress the stop observer if we're in the middle of:
61405796c8dcSSimon Schubert 
61415796c8dcSSimon Schubert      - a step n (n > 1), as there still more steps to be done.
61425796c8dcSSimon Schubert 
61435796c8dcSSimon Schubert      - a "finish" command, as the observer will be called in
61445796c8dcSSimon Schubert        finish_command_continuation, so it can include the inferior
61455796c8dcSSimon Schubert        function's return value.
61465796c8dcSSimon Schubert 
61475796c8dcSSimon Schubert      - calling an inferior function, as we pretend we inferior didn't
61485796c8dcSSimon Schubert        run at all.  The return value of the call is handled by the
61495796c8dcSSimon Schubert        expression evaluator, through call_function_by_hand.  */
61505796c8dcSSimon Schubert 
61515796c8dcSSimon Schubert   if (!target_has_execution
61525796c8dcSSimon Schubert       || last.kind == TARGET_WAITKIND_SIGNALLED
61535796c8dcSSimon Schubert       || last.kind == TARGET_WAITKIND_EXITED
6154a45ae5f8SJohn Marino       || last.kind == TARGET_WAITKIND_NO_RESUMED
6155*ef5ccd6cSJohn Marino       || (!(inferior_thread ()->step_multi
6156*ef5ccd6cSJohn Marino 	    && inferior_thread ()->control.stop_step)
6157c50c785cSJohn Marino 	  && !(inferior_thread ()->control.stop_bpstat
6158c50c785cSJohn Marino 	       && inferior_thread ()->control.proceed_to_finish)
6159c50c785cSJohn Marino 	  && !inferior_thread ()->control.in_infcall))
61605796c8dcSSimon Schubert     {
61615796c8dcSSimon Schubert       if (!ptid_equal (inferior_ptid, null_ptid))
6162c50c785cSJohn Marino 	observer_notify_normal_stop (inferior_thread ()->control.stop_bpstat,
61635796c8dcSSimon Schubert 				     stop_print_frame);
61645796c8dcSSimon Schubert       else
61655796c8dcSSimon Schubert 	observer_notify_normal_stop (NULL, stop_print_frame);
61665796c8dcSSimon Schubert     }
61675796c8dcSSimon Schubert 
61685796c8dcSSimon Schubert   if (target_has_execution)
61695796c8dcSSimon Schubert     {
61705796c8dcSSimon Schubert       if (last.kind != TARGET_WAITKIND_SIGNALLED
61715796c8dcSSimon Schubert 	  && last.kind != TARGET_WAITKIND_EXITED)
61725796c8dcSSimon Schubert 	/* Delete the breakpoint we stopped at, if it wants to be deleted.
61735796c8dcSSimon Schubert 	   Delete any breakpoint that is to be deleted at the next stop.  */
6174c50c785cSJohn Marino 	breakpoint_auto_delete (inferior_thread ()->control.stop_bpstat);
61755796c8dcSSimon Schubert     }
6176cf7f2e2dSJohn Marino 
6177cf7f2e2dSJohn Marino   /* Try to get rid of automatically added inferiors that are no
6178cf7f2e2dSJohn Marino      longer needed.  Keeping those around slows down things linearly.
6179cf7f2e2dSJohn Marino      Note that this never removes the current inferior.  */
6180cf7f2e2dSJohn Marino   prune_inferiors ();
61815796c8dcSSimon Schubert }
61825796c8dcSSimon Schubert 
61835796c8dcSSimon Schubert static int
hook_stop_stub(void * cmd)61845796c8dcSSimon Schubert hook_stop_stub (void *cmd)
61855796c8dcSSimon Schubert {
61865796c8dcSSimon Schubert   execute_cmd_pre_hook ((struct cmd_list_element *) cmd);
61875796c8dcSSimon Schubert   return (0);
61885796c8dcSSimon Schubert }
61895796c8dcSSimon Schubert 
61905796c8dcSSimon Schubert int
signal_stop_state(int signo)61915796c8dcSSimon Schubert signal_stop_state (int signo)
61925796c8dcSSimon Schubert {
61935796c8dcSSimon Schubert   return signal_stop[signo];
61945796c8dcSSimon Schubert }
61955796c8dcSSimon Schubert 
61965796c8dcSSimon Schubert int
signal_print_state(int signo)61975796c8dcSSimon Schubert signal_print_state (int signo)
61985796c8dcSSimon Schubert {
61995796c8dcSSimon Schubert   return signal_print[signo];
62005796c8dcSSimon Schubert }
62015796c8dcSSimon Schubert 
62025796c8dcSSimon Schubert int
signal_pass_state(int signo)62035796c8dcSSimon Schubert signal_pass_state (int signo)
62045796c8dcSSimon Schubert {
62055796c8dcSSimon Schubert   return signal_program[signo];
62065796c8dcSSimon Schubert }
62075796c8dcSSimon Schubert 
6208a45ae5f8SJohn Marino static void
signal_cache_update(int signo)6209a45ae5f8SJohn Marino signal_cache_update (int signo)
6210a45ae5f8SJohn Marino {
6211a45ae5f8SJohn Marino   if (signo == -1)
6212a45ae5f8SJohn Marino     {
6213*ef5ccd6cSJohn Marino       for (signo = 0; signo < (int) GDB_SIGNAL_LAST; signo++)
6214a45ae5f8SJohn Marino 	signal_cache_update (signo);
6215a45ae5f8SJohn Marino 
6216a45ae5f8SJohn Marino       return;
6217a45ae5f8SJohn Marino     }
6218a45ae5f8SJohn Marino 
6219a45ae5f8SJohn Marino   signal_pass[signo] = (signal_stop[signo] == 0
6220a45ae5f8SJohn Marino 			&& signal_print[signo] == 0
6221*ef5ccd6cSJohn Marino 			&& signal_program[signo] == 1
6222*ef5ccd6cSJohn Marino 			&& signal_catch[signo] == 0);
6223a45ae5f8SJohn Marino }
6224a45ae5f8SJohn Marino 
62255796c8dcSSimon Schubert int
signal_stop_update(int signo,int state)62265796c8dcSSimon Schubert signal_stop_update (int signo, int state)
62275796c8dcSSimon Schubert {
62285796c8dcSSimon Schubert   int ret = signal_stop[signo];
6229cf7f2e2dSJohn Marino 
62305796c8dcSSimon Schubert   signal_stop[signo] = state;
6231a45ae5f8SJohn Marino   signal_cache_update (signo);
62325796c8dcSSimon Schubert   return ret;
62335796c8dcSSimon Schubert }
62345796c8dcSSimon Schubert 
62355796c8dcSSimon Schubert int
signal_print_update(int signo,int state)62365796c8dcSSimon Schubert signal_print_update (int signo, int state)
62375796c8dcSSimon Schubert {
62385796c8dcSSimon Schubert   int ret = signal_print[signo];
6239cf7f2e2dSJohn Marino 
62405796c8dcSSimon Schubert   signal_print[signo] = state;
6241a45ae5f8SJohn Marino   signal_cache_update (signo);
62425796c8dcSSimon Schubert   return ret;
62435796c8dcSSimon Schubert }
62445796c8dcSSimon Schubert 
62455796c8dcSSimon Schubert int
signal_pass_update(int signo,int state)62465796c8dcSSimon Schubert signal_pass_update (int signo, int state)
62475796c8dcSSimon Schubert {
62485796c8dcSSimon Schubert   int ret = signal_program[signo];
6249cf7f2e2dSJohn Marino 
62505796c8dcSSimon Schubert   signal_program[signo] = state;
6251a45ae5f8SJohn Marino   signal_cache_update (signo);
62525796c8dcSSimon Schubert   return ret;
62535796c8dcSSimon Schubert }
62545796c8dcSSimon Schubert 
6255*ef5ccd6cSJohn Marino /* Update the global 'signal_catch' from INFO and notify the
6256*ef5ccd6cSJohn Marino    target.  */
6257*ef5ccd6cSJohn Marino 
6258*ef5ccd6cSJohn Marino void
signal_catch_update(const unsigned int * info)6259*ef5ccd6cSJohn Marino signal_catch_update (const unsigned int *info)
6260*ef5ccd6cSJohn Marino {
6261*ef5ccd6cSJohn Marino   int i;
6262*ef5ccd6cSJohn Marino 
6263*ef5ccd6cSJohn Marino   for (i = 0; i < GDB_SIGNAL_LAST; ++i)
6264*ef5ccd6cSJohn Marino     signal_catch[i] = info[i] > 0;
6265*ef5ccd6cSJohn Marino   signal_cache_update (-1);
6266*ef5ccd6cSJohn Marino   target_pass_signals ((int) GDB_SIGNAL_LAST, signal_pass);
6267*ef5ccd6cSJohn Marino }
6268*ef5ccd6cSJohn Marino 
62695796c8dcSSimon Schubert static void
sig_print_header(void)62705796c8dcSSimon Schubert sig_print_header (void)
62715796c8dcSSimon Schubert {
6272c50c785cSJohn Marino   printf_filtered (_("Signal        Stop\tPrint\tPass "
6273c50c785cSJohn Marino 		     "to program\tDescription\n"));
62745796c8dcSSimon Schubert }
62755796c8dcSSimon Schubert 
62765796c8dcSSimon Schubert static void
sig_print_info(enum gdb_signal oursig)6277*ef5ccd6cSJohn Marino sig_print_info (enum gdb_signal oursig)
62785796c8dcSSimon Schubert {
6279*ef5ccd6cSJohn Marino   const char *name = gdb_signal_to_name (oursig);
62805796c8dcSSimon Schubert   int name_padding = 13 - strlen (name);
62815796c8dcSSimon Schubert 
62825796c8dcSSimon Schubert   if (name_padding <= 0)
62835796c8dcSSimon Schubert     name_padding = 0;
62845796c8dcSSimon Schubert 
62855796c8dcSSimon Schubert   printf_filtered ("%s", name);
62865796c8dcSSimon Schubert   printf_filtered ("%*.*s ", name_padding, name_padding, "                 ");
62875796c8dcSSimon Schubert   printf_filtered ("%s\t", signal_stop[oursig] ? "Yes" : "No");
62885796c8dcSSimon Schubert   printf_filtered ("%s\t", signal_print[oursig] ? "Yes" : "No");
62895796c8dcSSimon Schubert   printf_filtered ("%s\t\t", signal_program[oursig] ? "Yes" : "No");
6290*ef5ccd6cSJohn Marino   printf_filtered ("%s\n", gdb_signal_to_string (oursig));
62915796c8dcSSimon Schubert }
62925796c8dcSSimon Schubert 
62935796c8dcSSimon Schubert /* Specify how various signals in the inferior should be handled.  */
62945796c8dcSSimon Schubert 
62955796c8dcSSimon Schubert static void
handle_command(char * args,int from_tty)62965796c8dcSSimon Schubert handle_command (char *args, int from_tty)
62975796c8dcSSimon Schubert {
62985796c8dcSSimon Schubert   char **argv;
62995796c8dcSSimon Schubert   int digits, wordlen;
63005796c8dcSSimon Schubert   int sigfirst, signum, siglast;
6301*ef5ccd6cSJohn Marino   enum gdb_signal oursig;
63025796c8dcSSimon Schubert   int allsigs;
63035796c8dcSSimon Schubert   int nsigs;
63045796c8dcSSimon Schubert   unsigned char *sigs;
63055796c8dcSSimon Schubert   struct cleanup *old_chain;
63065796c8dcSSimon Schubert 
63075796c8dcSSimon Schubert   if (args == NULL)
63085796c8dcSSimon Schubert     {
63095796c8dcSSimon Schubert       error_no_arg (_("signal to handle"));
63105796c8dcSSimon Schubert     }
63115796c8dcSSimon Schubert 
63125796c8dcSSimon Schubert   /* Allocate and zero an array of flags for which signals to handle.  */
63135796c8dcSSimon Schubert 
6314*ef5ccd6cSJohn Marino   nsigs = (int) GDB_SIGNAL_LAST;
63155796c8dcSSimon Schubert   sigs = (unsigned char *) alloca (nsigs);
63165796c8dcSSimon Schubert   memset (sigs, 0, nsigs);
63175796c8dcSSimon Schubert 
63185796c8dcSSimon Schubert   /* Break the command line up into args.  */
63195796c8dcSSimon Schubert 
63205796c8dcSSimon Schubert   argv = gdb_buildargv (args);
63215796c8dcSSimon Schubert   old_chain = make_cleanup_freeargv (argv);
63225796c8dcSSimon Schubert 
63235796c8dcSSimon Schubert   /* Walk through the args, looking for signal oursigs, signal names, and
63245796c8dcSSimon Schubert      actions.  Signal numbers and signal names may be interspersed with
63255796c8dcSSimon Schubert      actions, with the actions being performed for all signals cumulatively
63265796c8dcSSimon Schubert      specified.  Signal ranges can be specified as <LOW>-<HIGH>.  */
63275796c8dcSSimon Schubert 
63285796c8dcSSimon Schubert   while (*argv != NULL)
63295796c8dcSSimon Schubert     {
63305796c8dcSSimon Schubert       wordlen = strlen (*argv);
63315796c8dcSSimon Schubert       for (digits = 0; isdigit ((*argv)[digits]); digits++)
63325796c8dcSSimon Schubert 	{;
63335796c8dcSSimon Schubert 	}
63345796c8dcSSimon Schubert       allsigs = 0;
63355796c8dcSSimon Schubert       sigfirst = siglast = -1;
63365796c8dcSSimon Schubert 
63375796c8dcSSimon Schubert       if (wordlen >= 1 && !strncmp (*argv, "all", wordlen))
63385796c8dcSSimon Schubert 	{
63395796c8dcSSimon Schubert 	  /* Apply action to all signals except those used by the
63405796c8dcSSimon Schubert 	     debugger.  Silently skip those.  */
63415796c8dcSSimon Schubert 	  allsigs = 1;
63425796c8dcSSimon Schubert 	  sigfirst = 0;
63435796c8dcSSimon Schubert 	  siglast = nsigs - 1;
63445796c8dcSSimon Schubert 	}
63455796c8dcSSimon Schubert       else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen))
63465796c8dcSSimon Schubert 	{
63475796c8dcSSimon Schubert 	  SET_SIGS (nsigs, sigs, signal_stop);
63485796c8dcSSimon Schubert 	  SET_SIGS (nsigs, sigs, signal_print);
63495796c8dcSSimon Schubert 	}
63505796c8dcSSimon Schubert       else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen))
63515796c8dcSSimon Schubert 	{
63525796c8dcSSimon Schubert 	  UNSET_SIGS (nsigs, sigs, signal_program);
63535796c8dcSSimon Schubert 	}
63545796c8dcSSimon Schubert       else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen))
63555796c8dcSSimon Schubert 	{
63565796c8dcSSimon Schubert 	  SET_SIGS (nsigs, sigs, signal_print);
63575796c8dcSSimon Schubert 	}
63585796c8dcSSimon Schubert       else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen))
63595796c8dcSSimon Schubert 	{
63605796c8dcSSimon Schubert 	  SET_SIGS (nsigs, sigs, signal_program);
63615796c8dcSSimon Schubert 	}
63625796c8dcSSimon Schubert       else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen))
63635796c8dcSSimon Schubert 	{
63645796c8dcSSimon Schubert 	  UNSET_SIGS (nsigs, sigs, signal_stop);
63655796c8dcSSimon Schubert 	}
63665796c8dcSSimon Schubert       else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen))
63675796c8dcSSimon Schubert 	{
63685796c8dcSSimon Schubert 	  SET_SIGS (nsigs, sigs, signal_program);
63695796c8dcSSimon Schubert 	}
63705796c8dcSSimon Schubert       else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen))
63715796c8dcSSimon Schubert 	{
63725796c8dcSSimon Schubert 	  UNSET_SIGS (nsigs, sigs, signal_print);
63735796c8dcSSimon Schubert 	  UNSET_SIGS (nsigs, sigs, signal_stop);
63745796c8dcSSimon Schubert 	}
63755796c8dcSSimon Schubert       else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen))
63765796c8dcSSimon Schubert 	{
63775796c8dcSSimon Schubert 	  UNSET_SIGS (nsigs, sigs, signal_program);
63785796c8dcSSimon Schubert 	}
63795796c8dcSSimon Schubert       else if (digits > 0)
63805796c8dcSSimon Schubert 	{
63815796c8dcSSimon Schubert 	  /* It is numeric.  The numeric signal refers to our own
63825796c8dcSSimon Schubert 	     internal signal numbering from target.h, not to host/target
63835796c8dcSSimon Schubert 	     signal  number.  This is a feature; users really should be
63845796c8dcSSimon Schubert 	     using symbolic names anyway, and the common ones like
63855796c8dcSSimon Schubert 	     SIGHUP, SIGINT, SIGALRM, etc. will work right anyway.  */
63865796c8dcSSimon Schubert 
63875796c8dcSSimon Schubert 	  sigfirst = siglast = (int)
6388*ef5ccd6cSJohn Marino 	    gdb_signal_from_command (atoi (*argv));
63895796c8dcSSimon Schubert 	  if ((*argv)[digits] == '-')
63905796c8dcSSimon Schubert 	    {
63915796c8dcSSimon Schubert 	      siglast = (int)
6392*ef5ccd6cSJohn Marino 		gdb_signal_from_command (atoi ((*argv) + digits + 1));
63935796c8dcSSimon Schubert 	    }
63945796c8dcSSimon Schubert 	  if (sigfirst > siglast)
63955796c8dcSSimon Schubert 	    {
63965796c8dcSSimon Schubert 	      /* Bet he didn't figure we'd think of this case...  */
63975796c8dcSSimon Schubert 	      signum = sigfirst;
63985796c8dcSSimon Schubert 	      sigfirst = siglast;
63995796c8dcSSimon Schubert 	      siglast = signum;
64005796c8dcSSimon Schubert 	    }
64015796c8dcSSimon Schubert 	}
64025796c8dcSSimon Schubert       else
64035796c8dcSSimon Schubert 	{
6404*ef5ccd6cSJohn Marino 	  oursig = gdb_signal_from_name (*argv);
6405*ef5ccd6cSJohn Marino 	  if (oursig != GDB_SIGNAL_UNKNOWN)
64065796c8dcSSimon Schubert 	    {
64075796c8dcSSimon Schubert 	      sigfirst = siglast = (int) oursig;
64085796c8dcSSimon Schubert 	    }
64095796c8dcSSimon Schubert 	  else
64105796c8dcSSimon Schubert 	    {
64115796c8dcSSimon Schubert 	      /* Not a number and not a recognized flag word => complain.  */
64125796c8dcSSimon Schubert 	      error (_("Unrecognized or ambiguous flag word: \"%s\"."), *argv);
64135796c8dcSSimon Schubert 	    }
64145796c8dcSSimon Schubert 	}
64155796c8dcSSimon Schubert 
64165796c8dcSSimon Schubert       /* If any signal numbers or symbol names were found, set flags for
64175796c8dcSSimon Schubert          which signals to apply actions to.  */
64185796c8dcSSimon Schubert 
64195796c8dcSSimon Schubert       for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++)
64205796c8dcSSimon Schubert 	{
6421*ef5ccd6cSJohn Marino 	  switch ((enum gdb_signal) signum)
64225796c8dcSSimon Schubert 	    {
6423*ef5ccd6cSJohn Marino 	    case GDB_SIGNAL_TRAP:
6424*ef5ccd6cSJohn Marino 	    case GDB_SIGNAL_INT:
64255796c8dcSSimon Schubert 	      if (!allsigs && !sigs[signum])
64265796c8dcSSimon Schubert 		{
64275796c8dcSSimon Schubert 		  if (query (_("%s is used by the debugger.\n\
6428c50c785cSJohn Marino Are you sure you want to change it? "),
6429*ef5ccd6cSJohn Marino 			     gdb_signal_to_name ((enum gdb_signal) signum)))
64305796c8dcSSimon Schubert 		    {
64315796c8dcSSimon Schubert 		      sigs[signum] = 1;
64325796c8dcSSimon Schubert 		    }
64335796c8dcSSimon Schubert 		  else
64345796c8dcSSimon Schubert 		    {
64355796c8dcSSimon Schubert 		      printf_unfiltered (_("Not confirmed, unchanged.\n"));
64365796c8dcSSimon Schubert 		      gdb_flush (gdb_stdout);
64375796c8dcSSimon Schubert 		    }
64385796c8dcSSimon Schubert 		}
64395796c8dcSSimon Schubert 	      break;
6440*ef5ccd6cSJohn Marino 	    case GDB_SIGNAL_0:
6441*ef5ccd6cSJohn Marino 	    case GDB_SIGNAL_DEFAULT:
6442*ef5ccd6cSJohn Marino 	    case GDB_SIGNAL_UNKNOWN:
64435796c8dcSSimon Schubert 	      /* Make sure that "all" doesn't print these.  */
64445796c8dcSSimon Schubert 	      break;
64455796c8dcSSimon Schubert 	    default:
64465796c8dcSSimon Schubert 	      sigs[signum] = 1;
64475796c8dcSSimon Schubert 	      break;
64485796c8dcSSimon Schubert 	    }
64495796c8dcSSimon Schubert 	}
64505796c8dcSSimon Schubert 
64515796c8dcSSimon Schubert       argv++;
64525796c8dcSSimon Schubert     }
64535796c8dcSSimon Schubert 
64545796c8dcSSimon Schubert   for (signum = 0; signum < nsigs; signum++)
64555796c8dcSSimon Schubert     if (sigs[signum])
64565796c8dcSSimon Schubert       {
6457a45ae5f8SJohn Marino 	signal_cache_update (-1);
6458*ef5ccd6cSJohn Marino 	target_pass_signals ((int) GDB_SIGNAL_LAST, signal_pass);
6459*ef5ccd6cSJohn Marino 	target_program_signals ((int) GDB_SIGNAL_LAST, signal_program);
64605796c8dcSSimon Schubert 
64615796c8dcSSimon Schubert 	if (from_tty)
64625796c8dcSSimon Schubert 	  {
64635796c8dcSSimon Schubert 	    /* Show the results.  */
64645796c8dcSSimon Schubert 	    sig_print_header ();
64655796c8dcSSimon Schubert 	    for (; signum < nsigs; signum++)
64665796c8dcSSimon Schubert 	      if (sigs[signum])
64675796c8dcSSimon Schubert 		sig_print_info (signum);
64685796c8dcSSimon Schubert 	  }
64695796c8dcSSimon Schubert 
64705796c8dcSSimon Schubert 	break;
64715796c8dcSSimon Schubert       }
64725796c8dcSSimon Schubert 
64735796c8dcSSimon Schubert   do_cleanups (old_chain);
64745796c8dcSSimon Schubert }
64755796c8dcSSimon Schubert 
6476*ef5ccd6cSJohn Marino /* Complete the "handle" command.  */
6477*ef5ccd6cSJohn Marino 
VEC(char_ptr)6478*ef5ccd6cSJohn Marino static VEC (char_ptr) *
6479*ef5ccd6cSJohn Marino handle_completer (struct cmd_list_element *ignore,
6480*ef5ccd6cSJohn Marino 		  char *text, char *word)
6481*ef5ccd6cSJohn Marino {
6482*ef5ccd6cSJohn Marino   VEC (char_ptr) *vec_signals, *vec_keywords, *return_val;
6483*ef5ccd6cSJohn Marino   static const char * const keywords[] =
6484*ef5ccd6cSJohn Marino     {
6485*ef5ccd6cSJohn Marino       "all",
6486*ef5ccd6cSJohn Marino       "stop",
6487*ef5ccd6cSJohn Marino       "ignore",
6488*ef5ccd6cSJohn Marino       "print",
6489*ef5ccd6cSJohn Marino       "pass",
6490*ef5ccd6cSJohn Marino       "nostop",
6491*ef5ccd6cSJohn Marino       "noignore",
6492*ef5ccd6cSJohn Marino       "noprint",
6493*ef5ccd6cSJohn Marino       "nopass",
6494*ef5ccd6cSJohn Marino       NULL,
6495*ef5ccd6cSJohn Marino     };
6496*ef5ccd6cSJohn Marino 
6497*ef5ccd6cSJohn Marino   vec_signals = signal_completer (ignore, text, word);
6498*ef5ccd6cSJohn Marino   vec_keywords = complete_on_enum (keywords, word, word);
6499*ef5ccd6cSJohn Marino 
6500*ef5ccd6cSJohn Marino   return_val = VEC_merge (char_ptr, vec_signals, vec_keywords);
6501*ef5ccd6cSJohn Marino   VEC_free (char_ptr, vec_signals);
6502*ef5ccd6cSJohn Marino   VEC_free (char_ptr, vec_keywords);
6503*ef5ccd6cSJohn Marino   return return_val;
6504*ef5ccd6cSJohn Marino }
6505*ef5ccd6cSJohn Marino 
65065796c8dcSSimon Schubert static void
xdb_handle_command(char * args,int from_tty)65075796c8dcSSimon Schubert xdb_handle_command (char *args, int from_tty)
65085796c8dcSSimon Schubert {
65095796c8dcSSimon Schubert   char **argv;
65105796c8dcSSimon Schubert   struct cleanup *old_chain;
65115796c8dcSSimon Schubert 
65125796c8dcSSimon Schubert   if (args == NULL)
65135796c8dcSSimon Schubert     error_no_arg (_("xdb command"));
65145796c8dcSSimon Schubert 
65155796c8dcSSimon Schubert   /* Break the command line up into args.  */
65165796c8dcSSimon Schubert 
65175796c8dcSSimon Schubert   argv = gdb_buildargv (args);
65185796c8dcSSimon Schubert   old_chain = make_cleanup_freeargv (argv);
65195796c8dcSSimon Schubert   if (argv[1] != (char *) NULL)
65205796c8dcSSimon Schubert     {
65215796c8dcSSimon Schubert       char *argBuf;
65225796c8dcSSimon Schubert       int bufLen;
65235796c8dcSSimon Schubert 
65245796c8dcSSimon Schubert       bufLen = strlen (argv[0]) + 20;
65255796c8dcSSimon Schubert       argBuf = (char *) xmalloc (bufLen);
65265796c8dcSSimon Schubert       if (argBuf)
65275796c8dcSSimon Schubert 	{
65285796c8dcSSimon Schubert 	  int validFlag = 1;
6529*ef5ccd6cSJohn Marino 	  enum gdb_signal oursig;
65305796c8dcSSimon Schubert 
6531*ef5ccd6cSJohn Marino 	  oursig = gdb_signal_from_name (argv[0]);
65325796c8dcSSimon Schubert 	  memset (argBuf, 0, bufLen);
65335796c8dcSSimon Schubert 	  if (strcmp (argv[1], "Q") == 0)
65345796c8dcSSimon Schubert 	    sprintf (argBuf, "%s %s", argv[0], "noprint");
65355796c8dcSSimon Schubert 	  else
65365796c8dcSSimon Schubert 	    {
65375796c8dcSSimon Schubert 	      if (strcmp (argv[1], "s") == 0)
65385796c8dcSSimon Schubert 		{
65395796c8dcSSimon Schubert 		  if (!signal_stop[oursig])
65405796c8dcSSimon Schubert 		    sprintf (argBuf, "%s %s", argv[0], "stop");
65415796c8dcSSimon Schubert 		  else
65425796c8dcSSimon Schubert 		    sprintf (argBuf, "%s %s", argv[0], "nostop");
65435796c8dcSSimon Schubert 		}
65445796c8dcSSimon Schubert 	      else if (strcmp (argv[1], "i") == 0)
65455796c8dcSSimon Schubert 		{
65465796c8dcSSimon Schubert 		  if (!signal_program[oursig])
65475796c8dcSSimon Schubert 		    sprintf (argBuf, "%s %s", argv[0], "pass");
65485796c8dcSSimon Schubert 		  else
65495796c8dcSSimon Schubert 		    sprintf (argBuf, "%s %s", argv[0], "nopass");
65505796c8dcSSimon Schubert 		}
65515796c8dcSSimon Schubert 	      else if (strcmp (argv[1], "r") == 0)
65525796c8dcSSimon Schubert 		{
65535796c8dcSSimon Schubert 		  if (!signal_print[oursig])
65545796c8dcSSimon Schubert 		    sprintf (argBuf, "%s %s", argv[0], "print");
65555796c8dcSSimon Schubert 		  else
65565796c8dcSSimon Schubert 		    sprintf (argBuf, "%s %s", argv[0], "noprint");
65575796c8dcSSimon Schubert 		}
65585796c8dcSSimon Schubert 	      else
65595796c8dcSSimon Schubert 		validFlag = 0;
65605796c8dcSSimon Schubert 	    }
65615796c8dcSSimon Schubert 	  if (validFlag)
65625796c8dcSSimon Schubert 	    handle_command (argBuf, from_tty);
65635796c8dcSSimon Schubert 	  else
65645796c8dcSSimon Schubert 	    printf_filtered (_("Invalid signal handling flag.\n"));
65655796c8dcSSimon Schubert 	  if (argBuf)
65665796c8dcSSimon Schubert 	    xfree (argBuf);
65675796c8dcSSimon Schubert 	}
65685796c8dcSSimon Schubert     }
65695796c8dcSSimon Schubert   do_cleanups (old_chain);
65705796c8dcSSimon Schubert }
65715796c8dcSSimon Schubert 
6572*ef5ccd6cSJohn Marino enum gdb_signal
gdb_signal_from_command(int num)6573*ef5ccd6cSJohn Marino gdb_signal_from_command (int num)
6574*ef5ccd6cSJohn Marino {
6575*ef5ccd6cSJohn Marino   if (num >= 1 && num <= 15)
6576*ef5ccd6cSJohn Marino     return (enum gdb_signal) num;
6577*ef5ccd6cSJohn Marino   error (_("Only signals 1-15 are valid as numeric signals.\n\
6578*ef5ccd6cSJohn Marino Use \"info signals\" for a list of symbolic signals."));
6579*ef5ccd6cSJohn Marino }
6580*ef5ccd6cSJohn Marino 
65815796c8dcSSimon Schubert /* Print current contents of the tables set by the handle command.
65825796c8dcSSimon Schubert    It is possible we should just be printing signals actually used
65835796c8dcSSimon Schubert    by the current target (but for things to work right when switching
65845796c8dcSSimon Schubert    targets, all signals should be in the signal tables).  */
65855796c8dcSSimon Schubert 
65865796c8dcSSimon Schubert static void
signals_info(char * signum_exp,int from_tty)65875796c8dcSSimon Schubert signals_info (char *signum_exp, int from_tty)
65885796c8dcSSimon Schubert {
6589*ef5ccd6cSJohn Marino   enum gdb_signal oursig;
6590cf7f2e2dSJohn Marino 
65915796c8dcSSimon Schubert   sig_print_header ();
65925796c8dcSSimon Schubert 
65935796c8dcSSimon Schubert   if (signum_exp)
65945796c8dcSSimon Schubert     {
65955796c8dcSSimon Schubert       /* First see if this is a symbol name.  */
6596*ef5ccd6cSJohn Marino       oursig = gdb_signal_from_name (signum_exp);
6597*ef5ccd6cSJohn Marino       if (oursig == GDB_SIGNAL_UNKNOWN)
65985796c8dcSSimon Schubert 	{
65995796c8dcSSimon Schubert 	  /* No, try numeric.  */
66005796c8dcSSimon Schubert 	  oursig =
6601*ef5ccd6cSJohn Marino 	    gdb_signal_from_command (parse_and_eval_long (signum_exp));
66025796c8dcSSimon Schubert 	}
66035796c8dcSSimon Schubert       sig_print_info (oursig);
66045796c8dcSSimon Schubert       return;
66055796c8dcSSimon Schubert     }
66065796c8dcSSimon Schubert 
66075796c8dcSSimon Schubert   printf_filtered ("\n");
66085796c8dcSSimon Schubert   /* These ugly casts brought to you by the native VAX compiler.  */
6609*ef5ccd6cSJohn Marino   for (oursig = GDB_SIGNAL_FIRST;
6610*ef5ccd6cSJohn Marino        (int) oursig < (int) GDB_SIGNAL_LAST;
6611*ef5ccd6cSJohn Marino        oursig = (enum gdb_signal) ((int) oursig + 1))
66125796c8dcSSimon Schubert     {
66135796c8dcSSimon Schubert       QUIT;
66145796c8dcSSimon Schubert 
6615*ef5ccd6cSJohn Marino       if (oursig != GDB_SIGNAL_UNKNOWN
6616*ef5ccd6cSJohn Marino 	  && oursig != GDB_SIGNAL_DEFAULT && oursig != GDB_SIGNAL_0)
66175796c8dcSSimon Schubert 	sig_print_info (oursig);
66185796c8dcSSimon Schubert     }
66195796c8dcSSimon Schubert 
6620c50c785cSJohn Marino   printf_filtered (_("\nUse the \"handle\" command "
6621c50c785cSJohn Marino 		     "to change these tables.\n"));
66225796c8dcSSimon Schubert }
66235796c8dcSSimon Schubert 
6624a45ae5f8SJohn Marino /* Check if it makes sense to read $_siginfo from the current thread
6625a45ae5f8SJohn Marino    at this point.  If not, throw an error.  */
6626a45ae5f8SJohn Marino 
6627a45ae5f8SJohn Marino static void
validate_siginfo_access(void)6628a45ae5f8SJohn Marino validate_siginfo_access (void)
6629a45ae5f8SJohn Marino {
6630a45ae5f8SJohn Marino   /* No current inferior, no siginfo.  */
6631a45ae5f8SJohn Marino   if (ptid_equal (inferior_ptid, null_ptid))
6632a45ae5f8SJohn Marino     error (_("No thread selected."));
6633a45ae5f8SJohn Marino 
6634a45ae5f8SJohn Marino   /* Don't try to read from a dead thread.  */
6635a45ae5f8SJohn Marino   if (is_exited (inferior_ptid))
6636a45ae5f8SJohn Marino     error (_("The current thread has terminated"));
6637a45ae5f8SJohn Marino 
6638a45ae5f8SJohn Marino   /* ... or from a spinning thread.  */
6639a45ae5f8SJohn Marino   if (is_running (inferior_ptid))
6640a45ae5f8SJohn Marino     error (_("Selected thread is running."));
6641a45ae5f8SJohn Marino }
6642a45ae5f8SJohn Marino 
66435796c8dcSSimon Schubert /* The $_siginfo convenience variable is a bit special.  We don't know
66445796c8dcSSimon Schubert    for sure the type of the value until we actually have a chance to
6645a45ae5f8SJohn Marino    fetch the data.  The type can change depending on gdbarch, so it is
66465796c8dcSSimon Schubert    also dependent on which thread you have selected.
66475796c8dcSSimon Schubert 
66485796c8dcSSimon Schubert      1. making $_siginfo be an internalvar that creates a new value on
66495796c8dcSSimon Schubert      access.
66505796c8dcSSimon Schubert 
66515796c8dcSSimon Schubert      2. making the value of $_siginfo be an lval_computed value.  */
66525796c8dcSSimon Schubert 
66535796c8dcSSimon Schubert /* This function implements the lval_computed support for reading a
66545796c8dcSSimon Schubert    $_siginfo value.  */
66555796c8dcSSimon Schubert 
66565796c8dcSSimon Schubert static void
siginfo_value_read(struct value * v)66575796c8dcSSimon Schubert siginfo_value_read (struct value *v)
66585796c8dcSSimon Schubert {
66595796c8dcSSimon Schubert   LONGEST transferred;
66605796c8dcSSimon Schubert 
6661a45ae5f8SJohn Marino   validate_siginfo_access ();
6662a45ae5f8SJohn Marino 
66635796c8dcSSimon Schubert   transferred =
66645796c8dcSSimon Schubert     target_read (&current_target, TARGET_OBJECT_SIGNAL_INFO,
66655796c8dcSSimon Schubert 		 NULL,
66665796c8dcSSimon Schubert 		 value_contents_all_raw (v),
66675796c8dcSSimon Schubert 		 value_offset (v),
66685796c8dcSSimon Schubert 		 TYPE_LENGTH (value_type (v)));
66695796c8dcSSimon Schubert 
66705796c8dcSSimon Schubert   if (transferred != TYPE_LENGTH (value_type (v)))
66715796c8dcSSimon Schubert     error (_("Unable to read siginfo"));
66725796c8dcSSimon Schubert }
66735796c8dcSSimon Schubert 
66745796c8dcSSimon Schubert /* This function implements the lval_computed support for writing a
66755796c8dcSSimon Schubert    $_siginfo value.  */
66765796c8dcSSimon Schubert 
66775796c8dcSSimon Schubert static void
siginfo_value_write(struct value * v,struct value * fromval)66785796c8dcSSimon Schubert siginfo_value_write (struct value *v, struct value *fromval)
66795796c8dcSSimon Schubert {
66805796c8dcSSimon Schubert   LONGEST transferred;
66815796c8dcSSimon Schubert 
6682a45ae5f8SJohn Marino   validate_siginfo_access ();
6683a45ae5f8SJohn Marino 
66845796c8dcSSimon Schubert   transferred = target_write (&current_target,
66855796c8dcSSimon Schubert 			      TARGET_OBJECT_SIGNAL_INFO,
66865796c8dcSSimon Schubert 			      NULL,
66875796c8dcSSimon Schubert 			      value_contents_all_raw (fromval),
66885796c8dcSSimon Schubert 			      value_offset (v),
66895796c8dcSSimon Schubert 			      TYPE_LENGTH (value_type (fromval)));
66905796c8dcSSimon Schubert 
66915796c8dcSSimon Schubert   if (transferred != TYPE_LENGTH (value_type (fromval)))
66925796c8dcSSimon Schubert     error (_("Unable to write siginfo"));
66935796c8dcSSimon Schubert }
66945796c8dcSSimon Schubert 
6695a45ae5f8SJohn Marino static const struct lval_funcs siginfo_value_funcs =
66965796c8dcSSimon Schubert   {
66975796c8dcSSimon Schubert     siginfo_value_read,
66985796c8dcSSimon Schubert     siginfo_value_write
66995796c8dcSSimon Schubert   };
67005796c8dcSSimon Schubert 
67015796c8dcSSimon Schubert /* Return a new value with the correct type for the siginfo object of
67025796c8dcSSimon Schubert    the current thread using architecture GDBARCH.  Return a void value
67035796c8dcSSimon Schubert    if there's no object available.  */
67045796c8dcSSimon Schubert 
67055796c8dcSSimon Schubert static struct value *
siginfo_make_value(struct gdbarch * gdbarch,struct internalvar * var,void * ignore)6706*ef5ccd6cSJohn Marino siginfo_make_value (struct gdbarch *gdbarch, struct internalvar *var,
6707*ef5ccd6cSJohn Marino 		    void *ignore)
67085796c8dcSSimon Schubert {
67095796c8dcSSimon Schubert   if (target_has_stack
67105796c8dcSSimon Schubert       && !ptid_equal (inferior_ptid, null_ptid)
67115796c8dcSSimon Schubert       && gdbarch_get_siginfo_type_p (gdbarch))
67125796c8dcSSimon Schubert     {
67135796c8dcSSimon Schubert       struct type *type = gdbarch_get_siginfo_type (gdbarch);
6714cf7f2e2dSJohn Marino 
67155796c8dcSSimon Schubert       return allocate_computed_value (type, &siginfo_value_funcs, NULL);
67165796c8dcSSimon Schubert     }
67175796c8dcSSimon Schubert 
67185796c8dcSSimon Schubert   return allocate_value (builtin_type (gdbarch)->builtin_void);
67195796c8dcSSimon Schubert }
67205796c8dcSSimon Schubert 
67215796c8dcSSimon Schubert 
6722c50c785cSJohn Marino /* infcall_suspend_state contains state about the program itself like its
6723c50c785cSJohn Marino    registers and any signal it received when it last stopped.
6724c50c785cSJohn Marino    This state must be restored regardless of how the inferior function call
6725c50c785cSJohn Marino    ends (either successfully, or after it hits a breakpoint or signal)
6726c50c785cSJohn Marino    if the program is to properly continue where it left off.  */
67275796c8dcSSimon Schubert 
6728c50c785cSJohn Marino struct infcall_suspend_state
67295796c8dcSSimon Schubert {
6730c50c785cSJohn Marino   struct thread_suspend_state thread_suspend;
6731*ef5ccd6cSJohn Marino #if 0 /* Currently unused and empty structures are not valid C.  */
6732c50c785cSJohn Marino   struct inferior_suspend_state inferior_suspend;
6733*ef5ccd6cSJohn Marino #endif
6734c50c785cSJohn Marino 
6735c50c785cSJohn Marino   /* Other fields:  */
67365796c8dcSSimon Schubert   CORE_ADDR stop_pc;
67375796c8dcSSimon Schubert   struct regcache *registers;
6738c50c785cSJohn Marino 
6739c50c785cSJohn Marino   /* Format of SIGINFO_DATA or NULL if it is not present.  */
6740c50c785cSJohn Marino   struct gdbarch *siginfo_gdbarch;
6741c50c785cSJohn Marino 
6742c50c785cSJohn Marino   /* The inferior format depends on SIGINFO_GDBARCH and it has a length of
6743c50c785cSJohn Marino      TYPE_LENGTH (gdbarch_get_siginfo_type ()).  For different gdbarch the
6744c50c785cSJohn Marino      content would be invalid.  */
6745c50c785cSJohn Marino   gdb_byte *siginfo_data;
67465796c8dcSSimon Schubert };
67475796c8dcSSimon Schubert 
6748c50c785cSJohn Marino struct infcall_suspend_state *
save_infcall_suspend_state(void)6749c50c785cSJohn Marino save_infcall_suspend_state (void)
67505796c8dcSSimon Schubert {
6751c50c785cSJohn Marino   struct infcall_suspend_state *inf_state;
67525796c8dcSSimon Schubert   struct thread_info *tp = inferior_thread ();
6753*ef5ccd6cSJohn Marino #if 0
6754c50c785cSJohn Marino   struct inferior *inf = current_inferior ();
6755*ef5ccd6cSJohn Marino #endif
6756c50c785cSJohn Marino   struct regcache *regcache = get_current_regcache ();
6757c50c785cSJohn Marino   struct gdbarch *gdbarch = get_regcache_arch (regcache);
6758c50c785cSJohn Marino   gdb_byte *siginfo_data = NULL;
67595796c8dcSSimon Schubert 
6760c50c785cSJohn Marino   if (gdbarch_get_siginfo_type_p (gdbarch))
6761c50c785cSJohn Marino     {
6762c50c785cSJohn Marino       struct type *type = gdbarch_get_siginfo_type (gdbarch);
6763c50c785cSJohn Marino       size_t len = TYPE_LENGTH (type);
6764c50c785cSJohn Marino       struct cleanup *back_to;
6765c50c785cSJohn Marino 
6766c50c785cSJohn Marino       siginfo_data = xmalloc (len);
6767c50c785cSJohn Marino       back_to = make_cleanup (xfree, siginfo_data);
6768c50c785cSJohn Marino 
6769c50c785cSJohn Marino       if (target_read (&current_target, TARGET_OBJECT_SIGNAL_INFO, NULL,
6770c50c785cSJohn Marino 		       siginfo_data, 0, len) == len)
6771c50c785cSJohn Marino 	discard_cleanups (back_to);
6772c50c785cSJohn Marino       else
6773c50c785cSJohn Marino 	{
6774c50c785cSJohn Marino 	  /* Errors ignored.  */
6775c50c785cSJohn Marino 	  do_cleanups (back_to);
6776c50c785cSJohn Marino 	  siginfo_data = NULL;
6777c50c785cSJohn Marino 	}
6778c50c785cSJohn Marino     }
6779c50c785cSJohn Marino 
6780c50c785cSJohn Marino   inf_state = XZALLOC (struct infcall_suspend_state);
6781c50c785cSJohn Marino 
6782c50c785cSJohn Marino   if (siginfo_data)
6783c50c785cSJohn Marino     {
6784c50c785cSJohn Marino       inf_state->siginfo_gdbarch = gdbarch;
6785c50c785cSJohn Marino       inf_state->siginfo_data = siginfo_data;
6786c50c785cSJohn Marino     }
6787c50c785cSJohn Marino 
6788c50c785cSJohn Marino   inf_state->thread_suspend = tp->suspend;
6789*ef5ccd6cSJohn Marino #if 0 /* Currently unused and empty structures are not valid C.  */
6790c50c785cSJohn Marino   inf_state->inferior_suspend = inf->suspend;
6791*ef5ccd6cSJohn Marino #endif
6792c50c785cSJohn Marino 
6793c50c785cSJohn Marino   /* run_inferior_call will not use the signal due to its `proceed' call with
6794*ef5ccd6cSJohn Marino      GDB_SIGNAL_0 anyway.  */
6795*ef5ccd6cSJohn Marino   tp->suspend.stop_signal = GDB_SIGNAL_0;
6796c50c785cSJohn Marino 
67975796c8dcSSimon Schubert   inf_state->stop_pc = stop_pc;
67985796c8dcSSimon Schubert 
6799c50c785cSJohn Marino   inf_state->registers = regcache_dup (regcache);
68005796c8dcSSimon Schubert 
68015796c8dcSSimon Schubert   return inf_state;
68025796c8dcSSimon Schubert }
68035796c8dcSSimon Schubert 
68045796c8dcSSimon Schubert /* Restore inferior session state to INF_STATE.  */
68055796c8dcSSimon Schubert 
68065796c8dcSSimon Schubert void
restore_infcall_suspend_state(struct infcall_suspend_state * inf_state)6807c50c785cSJohn Marino restore_infcall_suspend_state (struct infcall_suspend_state *inf_state)
68085796c8dcSSimon Schubert {
68095796c8dcSSimon Schubert   struct thread_info *tp = inferior_thread ();
6810*ef5ccd6cSJohn Marino #if 0
6811c50c785cSJohn Marino   struct inferior *inf = current_inferior ();
6812*ef5ccd6cSJohn Marino #endif
6813c50c785cSJohn Marino   struct regcache *regcache = get_current_regcache ();
6814c50c785cSJohn Marino   struct gdbarch *gdbarch = get_regcache_arch (regcache);
68155796c8dcSSimon Schubert 
6816c50c785cSJohn Marino   tp->suspend = inf_state->thread_suspend;
6817*ef5ccd6cSJohn Marino #if 0 /* Currently unused and empty structures are not valid C.  */
6818c50c785cSJohn Marino   inf->suspend = inf_state->inferior_suspend;
6819*ef5ccd6cSJohn Marino #endif
6820c50c785cSJohn Marino 
68215796c8dcSSimon Schubert   stop_pc = inf_state->stop_pc;
68225796c8dcSSimon Schubert 
6823c50c785cSJohn Marino   if (inf_state->siginfo_gdbarch == gdbarch)
6824c50c785cSJohn Marino     {
6825c50c785cSJohn Marino       struct type *type = gdbarch_get_siginfo_type (gdbarch);
6826c50c785cSJohn Marino 
6827c50c785cSJohn Marino       /* Errors ignored.  */
6828c50c785cSJohn Marino       target_write (&current_target, TARGET_OBJECT_SIGNAL_INFO, NULL,
6829*ef5ccd6cSJohn Marino 		    inf_state->siginfo_data, 0, TYPE_LENGTH (type));
6830c50c785cSJohn Marino     }
6831c50c785cSJohn Marino 
68325796c8dcSSimon Schubert   /* The inferior can be gone if the user types "print exit(0)"
68335796c8dcSSimon Schubert      (and perhaps other times).  */
68345796c8dcSSimon Schubert   if (target_has_execution)
68355796c8dcSSimon Schubert     /* NB: The register write goes through to the target.  */
6836c50c785cSJohn Marino     regcache_cpy (regcache, inf_state->registers);
6837c50c785cSJohn Marino 
6838c50c785cSJohn Marino   discard_infcall_suspend_state (inf_state);
68395796c8dcSSimon Schubert }
68405796c8dcSSimon Schubert 
68415796c8dcSSimon Schubert static void
do_restore_infcall_suspend_state_cleanup(void * state)6842c50c785cSJohn Marino do_restore_infcall_suspend_state_cleanup (void *state)
68435796c8dcSSimon Schubert {
6844c50c785cSJohn Marino   restore_infcall_suspend_state (state);
68455796c8dcSSimon Schubert }
68465796c8dcSSimon Schubert 
68475796c8dcSSimon Schubert struct cleanup *
make_cleanup_restore_infcall_suspend_state(struct infcall_suspend_state * inf_state)6848c50c785cSJohn Marino make_cleanup_restore_infcall_suspend_state
6849c50c785cSJohn Marino   (struct infcall_suspend_state *inf_state)
68505796c8dcSSimon Schubert {
6851c50c785cSJohn Marino   return make_cleanup (do_restore_infcall_suspend_state_cleanup, inf_state);
68525796c8dcSSimon Schubert }
68535796c8dcSSimon Schubert 
68545796c8dcSSimon Schubert void
discard_infcall_suspend_state(struct infcall_suspend_state * inf_state)6855c50c785cSJohn Marino discard_infcall_suspend_state (struct infcall_suspend_state *inf_state)
68565796c8dcSSimon Schubert {
68575796c8dcSSimon Schubert   regcache_xfree (inf_state->registers);
6858c50c785cSJohn Marino   xfree (inf_state->siginfo_data);
68595796c8dcSSimon Schubert   xfree (inf_state);
68605796c8dcSSimon Schubert }
68615796c8dcSSimon Schubert 
68625796c8dcSSimon Schubert struct regcache *
get_infcall_suspend_state_regcache(struct infcall_suspend_state * inf_state)6863c50c785cSJohn Marino get_infcall_suspend_state_regcache (struct infcall_suspend_state *inf_state)
68645796c8dcSSimon Schubert {
68655796c8dcSSimon Schubert   return inf_state->registers;
68665796c8dcSSimon Schubert }
68675796c8dcSSimon Schubert 
6868c50c785cSJohn Marino /* infcall_control_state contains state regarding gdb's control of the
6869c50c785cSJohn Marino    inferior itself like stepping control.  It also contains session state like
6870c50c785cSJohn Marino    the user's currently selected frame.  */
68715796c8dcSSimon Schubert 
6872c50c785cSJohn Marino struct infcall_control_state
68735796c8dcSSimon Schubert {
6874c50c785cSJohn Marino   struct thread_control_state thread_control;
6875c50c785cSJohn Marino   struct inferior_control_state inferior_control;
6876c50c785cSJohn Marino 
6877c50c785cSJohn Marino   /* Other fields:  */
6878cf7f2e2dSJohn Marino   enum stop_stack_kind stop_stack_dummy;
68795796c8dcSSimon Schubert   int stopped_by_random_signal;
68805796c8dcSSimon Schubert   int stop_after_trap;
68815796c8dcSSimon Schubert 
68825796c8dcSSimon Schubert   /* ID if the selected frame when the inferior function call was made.  */
68835796c8dcSSimon Schubert   struct frame_id selected_frame_id;
68845796c8dcSSimon Schubert };
68855796c8dcSSimon Schubert 
68865796c8dcSSimon Schubert /* Save all of the information associated with the inferior<==>gdb
68875796c8dcSSimon Schubert    connection.  */
68885796c8dcSSimon Schubert 
6889c50c785cSJohn Marino struct infcall_control_state *
save_infcall_control_state(void)6890c50c785cSJohn Marino save_infcall_control_state (void)
68915796c8dcSSimon Schubert {
6892c50c785cSJohn Marino   struct infcall_control_state *inf_status = xmalloc (sizeof (*inf_status));
68935796c8dcSSimon Schubert   struct thread_info *tp = inferior_thread ();
68945796c8dcSSimon Schubert   struct inferior *inf = current_inferior ();
68955796c8dcSSimon Schubert 
6896c50c785cSJohn Marino   inf_status->thread_control = tp->control;
6897c50c785cSJohn Marino   inf_status->inferior_control = inf->control;
6898c50c785cSJohn Marino 
6899c50c785cSJohn Marino   tp->control.step_resume_breakpoint = NULL;
6900c50c785cSJohn Marino   tp->control.exception_resume_breakpoint = NULL;
6901c50c785cSJohn Marino 
6902c50c785cSJohn Marino   /* Save original bpstat chain to INF_STATUS; replace it in TP with copy of
6903c50c785cSJohn Marino      chain.  If caller's caller is walking the chain, they'll be happier if we
6904c50c785cSJohn Marino      hand them back the original chain when restore_infcall_control_state is
6905c50c785cSJohn Marino      called.  */
6906c50c785cSJohn Marino   tp->control.stop_bpstat = bpstat_copy (tp->control.stop_bpstat);
6907c50c785cSJohn Marino 
6908c50c785cSJohn Marino   /* Other fields:  */
69095796c8dcSSimon Schubert   inf_status->stop_stack_dummy = stop_stack_dummy;
69105796c8dcSSimon Schubert   inf_status->stopped_by_random_signal = stopped_by_random_signal;
69115796c8dcSSimon Schubert   inf_status->stop_after_trap = stop_after_trap;
69125796c8dcSSimon Schubert 
69135796c8dcSSimon Schubert   inf_status->selected_frame_id = get_frame_id (get_selected_frame (NULL));
69145796c8dcSSimon Schubert 
69155796c8dcSSimon Schubert   return inf_status;
69165796c8dcSSimon Schubert }
69175796c8dcSSimon Schubert 
69185796c8dcSSimon Schubert static int
restore_selected_frame(void * args)69195796c8dcSSimon Schubert restore_selected_frame (void *args)
69205796c8dcSSimon Schubert {
69215796c8dcSSimon Schubert   struct frame_id *fid = (struct frame_id *) args;
69225796c8dcSSimon Schubert   struct frame_info *frame;
69235796c8dcSSimon Schubert 
69245796c8dcSSimon Schubert   frame = frame_find_by_id (*fid);
69255796c8dcSSimon Schubert 
69265796c8dcSSimon Schubert   /* If inf_status->selected_frame_id is NULL, there was no previously
69275796c8dcSSimon Schubert      selected frame.  */
69285796c8dcSSimon Schubert   if (frame == NULL)
69295796c8dcSSimon Schubert     {
69305796c8dcSSimon Schubert       warning (_("Unable to restore previously selected frame."));
69315796c8dcSSimon Schubert       return 0;
69325796c8dcSSimon Schubert     }
69335796c8dcSSimon Schubert 
69345796c8dcSSimon Schubert   select_frame (frame);
69355796c8dcSSimon Schubert 
69365796c8dcSSimon Schubert   return (1);
69375796c8dcSSimon Schubert }
69385796c8dcSSimon Schubert 
69395796c8dcSSimon Schubert /* Restore inferior session state to INF_STATUS.  */
69405796c8dcSSimon Schubert 
69415796c8dcSSimon Schubert void
restore_infcall_control_state(struct infcall_control_state * inf_status)6942c50c785cSJohn Marino restore_infcall_control_state (struct infcall_control_state *inf_status)
69435796c8dcSSimon Schubert {
69445796c8dcSSimon Schubert   struct thread_info *tp = inferior_thread ();
69455796c8dcSSimon Schubert   struct inferior *inf = current_inferior ();
69465796c8dcSSimon Schubert 
6947c50c785cSJohn Marino   if (tp->control.step_resume_breakpoint)
6948c50c785cSJohn Marino     tp->control.step_resume_breakpoint->disposition = disp_del_at_next_stop;
6949c50c785cSJohn Marino 
6950c50c785cSJohn Marino   if (tp->control.exception_resume_breakpoint)
6951c50c785cSJohn Marino     tp->control.exception_resume_breakpoint->disposition
6952c50c785cSJohn Marino       = disp_del_at_next_stop;
6953c50c785cSJohn Marino 
6954c50c785cSJohn Marino   /* Handle the bpstat_copy of the chain.  */
6955c50c785cSJohn Marino   bpstat_clear (&tp->control.stop_bpstat);
6956c50c785cSJohn Marino 
6957c50c785cSJohn Marino   tp->control = inf_status->thread_control;
6958c50c785cSJohn Marino   inf->control = inf_status->inferior_control;
6959c50c785cSJohn Marino 
6960c50c785cSJohn Marino   /* Other fields:  */
69615796c8dcSSimon Schubert   stop_stack_dummy = inf_status->stop_stack_dummy;
69625796c8dcSSimon Schubert   stopped_by_random_signal = inf_status->stopped_by_random_signal;
69635796c8dcSSimon Schubert   stop_after_trap = inf_status->stop_after_trap;
69645796c8dcSSimon Schubert 
69655796c8dcSSimon Schubert   if (target_has_stack)
69665796c8dcSSimon Schubert     {
69675796c8dcSSimon Schubert       /* The point of catch_errors is that if the stack is clobbered,
69685796c8dcSSimon Schubert          walking the stack might encounter a garbage pointer and
69695796c8dcSSimon Schubert          error() trying to dereference it.  */
69705796c8dcSSimon Schubert       if (catch_errors
69715796c8dcSSimon Schubert 	  (restore_selected_frame, &inf_status->selected_frame_id,
69725796c8dcSSimon Schubert 	   "Unable to restore previously selected frame:\n",
69735796c8dcSSimon Schubert 	   RETURN_MASK_ERROR) == 0)
69745796c8dcSSimon Schubert 	/* Error in restoring the selected frame.  Select the innermost
69755796c8dcSSimon Schubert 	   frame.  */
69765796c8dcSSimon Schubert 	select_frame (get_current_frame ());
69775796c8dcSSimon Schubert     }
69785796c8dcSSimon Schubert 
69795796c8dcSSimon Schubert   xfree (inf_status);
69805796c8dcSSimon Schubert }
69815796c8dcSSimon Schubert 
69825796c8dcSSimon Schubert static void
do_restore_infcall_control_state_cleanup(void * sts)6983c50c785cSJohn Marino do_restore_infcall_control_state_cleanup (void *sts)
69845796c8dcSSimon Schubert {
6985c50c785cSJohn Marino   restore_infcall_control_state (sts);
69865796c8dcSSimon Schubert }
69875796c8dcSSimon Schubert 
69885796c8dcSSimon Schubert struct cleanup *
make_cleanup_restore_infcall_control_state(struct infcall_control_state * inf_status)6989c50c785cSJohn Marino make_cleanup_restore_infcall_control_state
6990c50c785cSJohn Marino   (struct infcall_control_state *inf_status)
69915796c8dcSSimon Schubert {
6992c50c785cSJohn Marino   return make_cleanup (do_restore_infcall_control_state_cleanup, inf_status);
69935796c8dcSSimon Schubert }
69945796c8dcSSimon Schubert 
69955796c8dcSSimon Schubert void
discard_infcall_control_state(struct infcall_control_state * inf_status)6996c50c785cSJohn Marino discard_infcall_control_state (struct infcall_control_state *inf_status)
69975796c8dcSSimon Schubert {
6998c50c785cSJohn Marino   if (inf_status->thread_control.step_resume_breakpoint)
6999c50c785cSJohn Marino     inf_status->thread_control.step_resume_breakpoint->disposition
7000c50c785cSJohn Marino       = disp_del_at_next_stop;
7001c50c785cSJohn Marino 
7002c50c785cSJohn Marino   if (inf_status->thread_control.exception_resume_breakpoint)
7003c50c785cSJohn Marino     inf_status->thread_control.exception_resume_breakpoint->disposition
7004c50c785cSJohn Marino       = disp_del_at_next_stop;
7005c50c785cSJohn Marino 
7006c50c785cSJohn Marino   /* See save_infcall_control_state for info on stop_bpstat.  */
7007c50c785cSJohn Marino   bpstat_clear (&inf_status->thread_control.stop_bpstat);
7008c50c785cSJohn Marino 
70095796c8dcSSimon Schubert   xfree (inf_status);
70105796c8dcSSimon Schubert }
70115796c8dcSSimon Schubert 
70125796c8dcSSimon Schubert int
ptid_match(ptid_t ptid,ptid_t filter)7013cf7f2e2dSJohn Marino ptid_match (ptid_t ptid, ptid_t filter)
7014cf7f2e2dSJohn Marino {
7015cf7f2e2dSJohn Marino   if (ptid_equal (filter, minus_one_ptid))
7016cf7f2e2dSJohn Marino     return 1;
7017cf7f2e2dSJohn Marino   if (ptid_is_pid (filter)
7018cf7f2e2dSJohn Marino       && ptid_get_pid (ptid) == ptid_get_pid (filter))
7019cf7f2e2dSJohn Marino     return 1;
7020cf7f2e2dSJohn Marino   else if (ptid_equal (ptid, filter))
7021cf7f2e2dSJohn Marino     return 1;
7022cf7f2e2dSJohn Marino 
7023cf7f2e2dSJohn Marino   return 0;
7024cf7f2e2dSJohn Marino }
7025cf7f2e2dSJohn Marino 
70265796c8dcSSimon Schubert /* restore_inferior_ptid() will be used by the cleanup machinery
70275796c8dcSSimon Schubert    to restore the inferior_ptid value saved in a call to
70285796c8dcSSimon Schubert    save_inferior_ptid().  */
70295796c8dcSSimon Schubert 
70305796c8dcSSimon Schubert static void
restore_inferior_ptid(void * arg)70315796c8dcSSimon Schubert restore_inferior_ptid (void *arg)
70325796c8dcSSimon Schubert {
70335796c8dcSSimon Schubert   ptid_t *saved_ptid_ptr = arg;
7034cf7f2e2dSJohn Marino 
70355796c8dcSSimon Schubert   inferior_ptid = *saved_ptid_ptr;
70365796c8dcSSimon Schubert   xfree (arg);
70375796c8dcSSimon Schubert }
70385796c8dcSSimon Schubert 
70395796c8dcSSimon Schubert /* Save the value of inferior_ptid so that it may be restored by a
70405796c8dcSSimon Schubert    later call to do_cleanups().  Returns the struct cleanup pointer
70415796c8dcSSimon Schubert    needed for later doing the cleanup.  */
70425796c8dcSSimon Schubert 
70435796c8dcSSimon Schubert struct cleanup *
save_inferior_ptid(void)70445796c8dcSSimon Schubert save_inferior_ptid (void)
70455796c8dcSSimon Schubert {
70465796c8dcSSimon Schubert   ptid_t *saved_ptid_ptr;
70475796c8dcSSimon Schubert 
70485796c8dcSSimon Schubert   saved_ptid_ptr = xmalloc (sizeof (ptid_t));
70495796c8dcSSimon Schubert   *saved_ptid_ptr = inferior_ptid;
70505796c8dcSSimon Schubert   return make_cleanup (restore_inferior_ptid, saved_ptid_ptr);
70515796c8dcSSimon Schubert }
70525796c8dcSSimon Schubert 
70535796c8dcSSimon Schubert 
70545796c8dcSSimon Schubert /* User interface for reverse debugging:
70555796c8dcSSimon Schubert    Set exec-direction / show exec-direction commands
70565796c8dcSSimon Schubert    (returns error unless target implements to_set_exec_direction method).  */
70575796c8dcSSimon Schubert 
7058a45ae5f8SJohn Marino int execution_direction = EXEC_FORWARD;
70595796c8dcSSimon Schubert static const char exec_forward[] = "forward";
70605796c8dcSSimon Schubert static const char exec_reverse[] = "reverse";
70615796c8dcSSimon Schubert static const char *exec_direction = exec_forward;
7062*ef5ccd6cSJohn Marino static const char *const exec_direction_names[] = {
70635796c8dcSSimon Schubert   exec_forward,
70645796c8dcSSimon Schubert   exec_reverse,
70655796c8dcSSimon Schubert   NULL
70665796c8dcSSimon Schubert };
70675796c8dcSSimon Schubert 
70685796c8dcSSimon Schubert static void
set_exec_direction_func(char * args,int from_tty,struct cmd_list_element * cmd)70695796c8dcSSimon Schubert set_exec_direction_func (char *args, int from_tty,
70705796c8dcSSimon Schubert 			 struct cmd_list_element *cmd)
70715796c8dcSSimon Schubert {
70725796c8dcSSimon Schubert   if (target_can_execute_reverse)
70735796c8dcSSimon Schubert     {
70745796c8dcSSimon Schubert       if (!strcmp (exec_direction, exec_forward))
70755796c8dcSSimon Schubert 	execution_direction = EXEC_FORWARD;
70765796c8dcSSimon Schubert       else if (!strcmp (exec_direction, exec_reverse))
70775796c8dcSSimon Schubert 	execution_direction = EXEC_REVERSE;
70785796c8dcSSimon Schubert     }
7079cf7f2e2dSJohn Marino   else
7080cf7f2e2dSJohn Marino     {
7081cf7f2e2dSJohn Marino       exec_direction = exec_forward;
7082cf7f2e2dSJohn Marino       error (_("Target does not support this operation."));
7083cf7f2e2dSJohn Marino     }
70845796c8dcSSimon Schubert }
70855796c8dcSSimon Schubert 
70865796c8dcSSimon Schubert static void
show_exec_direction_func(struct ui_file * out,int from_tty,struct cmd_list_element * cmd,const char * value)70875796c8dcSSimon Schubert show_exec_direction_func (struct ui_file *out, int from_tty,
70885796c8dcSSimon Schubert 			  struct cmd_list_element *cmd, const char *value)
70895796c8dcSSimon Schubert {
70905796c8dcSSimon Schubert   switch (execution_direction) {
70915796c8dcSSimon Schubert   case EXEC_FORWARD:
70925796c8dcSSimon Schubert     fprintf_filtered (out, _("Forward.\n"));
70935796c8dcSSimon Schubert     break;
70945796c8dcSSimon Schubert   case EXEC_REVERSE:
70955796c8dcSSimon Schubert     fprintf_filtered (out, _("Reverse.\n"));
70965796c8dcSSimon Schubert     break;
70975796c8dcSSimon Schubert   default:
7098a45ae5f8SJohn Marino     internal_error (__FILE__, __LINE__,
7099a45ae5f8SJohn Marino 		    _("bogus execution_direction value: %d"),
7100a45ae5f8SJohn Marino 		    (int) execution_direction);
71015796c8dcSSimon Schubert   }
71025796c8dcSSimon Schubert }
71035796c8dcSSimon Schubert 
71045796c8dcSSimon Schubert /* User interface for non-stop mode.  */
71055796c8dcSSimon Schubert 
71065796c8dcSSimon Schubert int non_stop = 0;
71075796c8dcSSimon Schubert 
71085796c8dcSSimon Schubert static void
set_non_stop(char * args,int from_tty,struct cmd_list_element * c)71095796c8dcSSimon Schubert set_non_stop (char *args, int from_tty,
71105796c8dcSSimon Schubert 	      struct cmd_list_element *c)
71115796c8dcSSimon Schubert {
71125796c8dcSSimon Schubert   if (target_has_execution)
71135796c8dcSSimon Schubert     {
71145796c8dcSSimon Schubert       non_stop_1 = non_stop;
71155796c8dcSSimon Schubert       error (_("Cannot change this setting while the inferior is running."));
71165796c8dcSSimon Schubert     }
71175796c8dcSSimon Schubert 
71185796c8dcSSimon Schubert   non_stop = non_stop_1;
71195796c8dcSSimon Schubert }
71205796c8dcSSimon Schubert 
71215796c8dcSSimon Schubert static void
show_non_stop(struct ui_file * file,int from_tty,struct cmd_list_element * c,const char * value)71225796c8dcSSimon Schubert show_non_stop (struct ui_file *file, int from_tty,
71235796c8dcSSimon Schubert 	       struct cmd_list_element *c, const char *value)
71245796c8dcSSimon Schubert {
71255796c8dcSSimon Schubert   fprintf_filtered (file,
71265796c8dcSSimon Schubert 		    _("Controlling the inferior in non-stop mode is %s.\n"),
71275796c8dcSSimon Schubert 		    value);
71285796c8dcSSimon Schubert }
71295796c8dcSSimon Schubert 
71305796c8dcSSimon Schubert static void
show_schedule_multiple(struct ui_file * file,int from_tty,struct cmd_list_element * c,const char * value)71315796c8dcSSimon Schubert show_schedule_multiple (struct ui_file *file, int from_tty,
71325796c8dcSSimon Schubert 			struct cmd_list_element *c, const char *value)
71335796c8dcSSimon Schubert {
7134c50c785cSJohn Marino   fprintf_filtered (file, _("Resuming the execution of threads "
7135c50c785cSJohn Marino 			    "of all processes is %s.\n"), value);
71365796c8dcSSimon Schubert }
71375796c8dcSSimon Schubert 
7138*ef5ccd6cSJohn Marino /* Implementation of `siginfo' variable.  */
7139*ef5ccd6cSJohn Marino 
7140*ef5ccd6cSJohn Marino static const struct internalvar_funcs siginfo_funcs =
7141*ef5ccd6cSJohn Marino {
7142*ef5ccd6cSJohn Marino   siginfo_make_value,
7143*ef5ccd6cSJohn Marino   NULL,
7144*ef5ccd6cSJohn Marino   NULL
7145*ef5ccd6cSJohn Marino };
7146*ef5ccd6cSJohn Marino 
71475796c8dcSSimon Schubert void
_initialize_infrun(void)71485796c8dcSSimon Schubert _initialize_infrun (void)
71495796c8dcSSimon Schubert {
71505796c8dcSSimon Schubert   int i;
71515796c8dcSSimon Schubert   int numsigs;
7152*ef5ccd6cSJohn Marino   struct cmd_list_element *c;
71535796c8dcSSimon Schubert 
71545796c8dcSSimon Schubert   add_info ("signals", signals_info, _("\
71555796c8dcSSimon Schubert What debugger does when program gets various signals.\n\
71565796c8dcSSimon Schubert Specify a signal as argument to print info on that signal only."));
71575796c8dcSSimon Schubert   add_info_alias ("handle", "signals", 0);
71585796c8dcSSimon Schubert 
7159*ef5ccd6cSJohn Marino   c = add_com ("handle", class_run, handle_command, _("\
7160*ef5ccd6cSJohn Marino Specify how to handle signals.\n\
7161*ef5ccd6cSJohn Marino Usage: handle SIGNAL [ACTIONS]\n\
71625796c8dcSSimon Schubert Args are signals and actions to apply to those signals.\n\
7163*ef5ccd6cSJohn Marino If no actions are specified, the current settings for the specified signals\n\
7164*ef5ccd6cSJohn Marino will be displayed instead.\n\
7165*ef5ccd6cSJohn Marino \n\
71665796c8dcSSimon Schubert Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
71675796c8dcSSimon Schubert from 1-15 are allowed for compatibility with old versions of GDB.\n\
71685796c8dcSSimon Schubert Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
71695796c8dcSSimon Schubert The special arg \"all\" is recognized to mean all signals except those\n\
71705796c8dcSSimon Schubert used by the debugger, typically SIGTRAP and SIGINT.\n\
7171*ef5ccd6cSJohn Marino \n\
71725796c8dcSSimon Schubert Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
71735796c8dcSSimon Schubert \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
71745796c8dcSSimon Schubert Stop means reenter debugger if this signal happens (implies print).\n\
71755796c8dcSSimon Schubert Print means print a message if this signal happens.\n\
71765796c8dcSSimon Schubert Pass means let program see this signal; otherwise program doesn't know.\n\
71775796c8dcSSimon Schubert Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
7178*ef5ccd6cSJohn Marino Pass and Stop may be combined.\n\
7179*ef5ccd6cSJohn Marino \n\
7180*ef5ccd6cSJohn Marino Multiple signals may be specified.  Signal numbers and signal names\n\
7181*ef5ccd6cSJohn Marino may be interspersed with actions, with the actions being performed for\n\
7182*ef5ccd6cSJohn Marino all signals cumulatively specified."));
7183*ef5ccd6cSJohn Marino   set_cmd_completer (c, handle_completer);
7184*ef5ccd6cSJohn Marino 
71855796c8dcSSimon Schubert   if (xdb_commands)
71865796c8dcSSimon Schubert     {
71875796c8dcSSimon Schubert       add_com ("lz", class_info, signals_info, _("\
71885796c8dcSSimon Schubert What debugger does when program gets various signals.\n\
71895796c8dcSSimon Schubert Specify a signal as argument to print info on that signal only."));
71905796c8dcSSimon Schubert       add_com ("z", class_run, xdb_handle_command, _("\
71915796c8dcSSimon Schubert Specify how to handle a signal.\n\
71925796c8dcSSimon Schubert Args are signals and actions to apply to those signals.\n\
71935796c8dcSSimon Schubert Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
71945796c8dcSSimon Schubert from 1-15 are allowed for compatibility with old versions of GDB.\n\
71955796c8dcSSimon Schubert Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
71965796c8dcSSimon Schubert The special arg \"all\" is recognized to mean all signals except those\n\
71975796c8dcSSimon Schubert used by the debugger, typically SIGTRAP and SIGINT.\n\
71985796c8dcSSimon Schubert Recognized actions include \"s\" (toggles between stop and nostop),\n\
71995796c8dcSSimon Schubert \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
72005796c8dcSSimon Schubert nopass), \"Q\" (noprint)\n\
72015796c8dcSSimon Schubert Stop means reenter debugger if this signal happens (implies print).\n\
72025796c8dcSSimon Schubert Print means print a message if this signal happens.\n\
72035796c8dcSSimon Schubert Pass means let program see this signal; otherwise program doesn't know.\n\
72045796c8dcSSimon Schubert Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
72055796c8dcSSimon Schubert Pass and Stop may be combined."));
72065796c8dcSSimon Schubert     }
72075796c8dcSSimon Schubert 
72085796c8dcSSimon Schubert   if (!dbx_commands)
72095796c8dcSSimon Schubert     stop_command = add_cmd ("stop", class_obscure,
72105796c8dcSSimon Schubert 			    not_just_help_class_command, _("\
72115796c8dcSSimon Schubert There is no `stop' command, but you can set a hook on `stop'.\n\
72125796c8dcSSimon Schubert This allows you to set a list of commands to be run each time execution\n\
72135796c8dcSSimon Schubert of the program stops."), &cmdlist);
72145796c8dcSSimon Schubert 
7215*ef5ccd6cSJohn Marino   add_setshow_zuinteger_cmd ("infrun", class_maintenance, &debug_infrun, _("\
72165796c8dcSSimon Schubert Set inferior debugging."), _("\
72175796c8dcSSimon Schubert Show inferior debugging."), _("\
72185796c8dcSSimon Schubert When non-zero, inferior specific debugging is enabled."),
72195796c8dcSSimon Schubert 			     NULL,
72205796c8dcSSimon Schubert 			     show_debug_infrun,
72215796c8dcSSimon Schubert 			     &setdebuglist, &showdebuglist);
72225796c8dcSSimon Schubert 
7223c50c785cSJohn Marino   add_setshow_boolean_cmd ("displaced", class_maintenance,
7224c50c785cSJohn Marino 			   &debug_displaced, _("\
72255796c8dcSSimon Schubert Set displaced stepping debugging."), _("\
72265796c8dcSSimon Schubert Show displaced stepping debugging."), _("\
72275796c8dcSSimon Schubert When non-zero, displaced stepping specific debugging is enabled."),
72285796c8dcSSimon Schubert 			    NULL,
72295796c8dcSSimon Schubert 			    show_debug_displaced,
72305796c8dcSSimon Schubert 			    &setdebuglist, &showdebuglist);
72315796c8dcSSimon Schubert 
72325796c8dcSSimon Schubert   add_setshow_boolean_cmd ("non-stop", no_class,
72335796c8dcSSimon Schubert 			   &non_stop_1, _("\
72345796c8dcSSimon Schubert Set whether gdb controls the inferior in non-stop mode."), _("\
72355796c8dcSSimon Schubert Show whether gdb controls the inferior in non-stop mode."), _("\
72365796c8dcSSimon Schubert When debugging a multi-threaded program and this setting is\n\
72375796c8dcSSimon Schubert off (the default, also called all-stop mode), when one thread stops\n\
72385796c8dcSSimon Schubert (for a breakpoint, watchpoint, exception, or similar events), GDB stops\n\
72395796c8dcSSimon Schubert all other threads in the program while you interact with the thread of\n\
72405796c8dcSSimon Schubert interest.  When you continue or step a thread, you can allow the other\n\
72415796c8dcSSimon Schubert threads to run, or have them remain stopped, but while you inspect any\n\
72425796c8dcSSimon Schubert thread's state, all threads stop.\n\
72435796c8dcSSimon Schubert \n\
72445796c8dcSSimon Schubert In non-stop mode, when one thread stops, other threads can continue\n\
72455796c8dcSSimon Schubert to run freely.  You'll be able to step each thread independently,\n\
72465796c8dcSSimon Schubert leave it stopped or free to run as needed."),
72475796c8dcSSimon Schubert 			   set_non_stop,
72485796c8dcSSimon Schubert 			   show_non_stop,
72495796c8dcSSimon Schubert 			   &setlist,
72505796c8dcSSimon Schubert 			   &showlist);
72515796c8dcSSimon Schubert 
7252*ef5ccd6cSJohn Marino   numsigs = (int) GDB_SIGNAL_LAST;
72535796c8dcSSimon Schubert   signal_stop = (unsigned char *) xmalloc (sizeof (signal_stop[0]) * numsigs);
72545796c8dcSSimon Schubert   signal_print = (unsigned char *)
72555796c8dcSSimon Schubert     xmalloc (sizeof (signal_print[0]) * numsigs);
72565796c8dcSSimon Schubert   signal_program = (unsigned char *)
72575796c8dcSSimon Schubert     xmalloc (sizeof (signal_program[0]) * numsigs);
7258*ef5ccd6cSJohn Marino   signal_catch = (unsigned char *)
7259*ef5ccd6cSJohn Marino     xmalloc (sizeof (signal_catch[0]) * numsigs);
7260a45ae5f8SJohn Marino   signal_pass = (unsigned char *)
7261a45ae5f8SJohn Marino     xmalloc (sizeof (signal_program[0]) * numsigs);
72625796c8dcSSimon Schubert   for (i = 0; i < numsigs; i++)
72635796c8dcSSimon Schubert     {
72645796c8dcSSimon Schubert       signal_stop[i] = 1;
72655796c8dcSSimon Schubert       signal_print[i] = 1;
72665796c8dcSSimon Schubert       signal_program[i] = 1;
7267*ef5ccd6cSJohn Marino       signal_catch[i] = 0;
72685796c8dcSSimon Schubert     }
72695796c8dcSSimon Schubert 
72705796c8dcSSimon Schubert   /* Signals caused by debugger's own actions
72715796c8dcSSimon Schubert      should not be given to the program afterwards.  */
7272*ef5ccd6cSJohn Marino   signal_program[GDB_SIGNAL_TRAP] = 0;
7273*ef5ccd6cSJohn Marino   signal_program[GDB_SIGNAL_INT] = 0;
72745796c8dcSSimon Schubert 
72755796c8dcSSimon Schubert   /* Signals that are not errors should not normally enter the debugger.  */
7276*ef5ccd6cSJohn Marino   signal_stop[GDB_SIGNAL_ALRM] = 0;
7277*ef5ccd6cSJohn Marino   signal_print[GDB_SIGNAL_ALRM] = 0;
7278*ef5ccd6cSJohn Marino   signal_stop[GDB_SIGNAL_VTALRM] = 0;
7279*ef5ccd6cSJohn Marino   signal_print[GDB_SIGNAL_VTALRM] = 0;
7280*ef5ccd6cSJohn Marino   signal_stop[GDB_SIGNAL_PROF] = 0;
7281*ef5ccd6cSJohn Marino   signal_print[GDB_SIGNAL_PROF] = 0;
7282*ef5ccd6cSJohn Marino   signal_stop[GDB_SIGNAL_CHLD] = 0;
7283*ef5ccd6cSJohn Marino   signal_print[GDB_SIGNAL_CHLD] = 0;
7284*ef5ccd6cSJohn Marino   signal_stop[GDB_SIGNAL_IO] = 0;
7285*ef5ccd6cSJohn Marino   signal_print[GDB_SIGNAL_IO] = 0;
7286*ef5ccd6cSJohn Marino   signal_stop[GDB_SIGNAL_POLL] = 0;
7287*ef5ccd6cSJohn Marino   signal_print[GDB_SIGNAL_POLL] = 0;
7288*ef5ccd6cSJohn Marino   signal_stop[GDB_SIGNAL_URG] = 0;
7289*ef5ccd6cSJohn Marino   signal_print[GDB_SIGNAL_URG] = 0;
7290*ef5ccd6cSJohn Marino   signal_stop[GDB_SIGNAL_WINCH] = 0;
7291*ef5ccd6cSJohn Marino   signal_print[GDB_SIGNAL_WINCH] = 0;
7292*ef5ccd6cSJohn Marino   signal_stop[GDB_SIGNAL_PRIO] = 0;
7293*ef5ccd6cSJohn Marino   signal_print[GDB_SIGNAL_PRIO] = 0;
72945796c8dcSSimon Schubert 
72955796c8dcSSimon Schubert   /* These signals are used internally by user-level thread
72965796c8dcSSimon Schubert      implementations.  (See signal(5) on Solaris.)  Like the above
72975796c8dcSSimon Schubert      signals, a healthy program receives and handles them as part of
72985796c8dcSSimon Schubert      its normal operation.  */
7299*ef5ccd6cSJohn Marino   signal_stop[GDB_SIGNAL_LWP] = 0;
7300*ef5ccd6cSJohn Marino   signal_print[GDB_SIGNAL_LWP] = 0;
7301*ef5ccd6cSJohn Marino   signal_stop[GDB_SIGNAL_WAITING] = 0;
7302*ef5ccd6cSJohn Marino   signal_print[GDB_SIGNAL_WAITING] = 0;
7303*ef5ccd6cSJohn Marino   signal_stop[GDB_SIGNAL_CANCEL] = 0;
7304*ef5ccd6cSJohn Marino   signal_print[GDB_SIGNAL_CANCEL] = 0;
73055796c8dcSSimon Schubert 
7306a45ae5f8SJohn Marino   /* Update cached state.  */
7307a45ae5f8SJohn Marino   signal_cache_update (-1);
7308a45ae5f8SJohn Marino 
73095796c8dcSSimon Schubert   add_setshow_zinteger_cmd ("stop-on-solib-events", class_support,
73105796c8dcSSimon Schubert 			    &stop_on_solib_events, _("\
73115796c8dcSSimon Schubert Set stopping for shared library events."), _("\
73125796c8dcSSimon Schubert Show stopping for shared library events."), _("\
73135796c8dcSSimon Schubert If nonzero, gdb will give control to the user when the dynamic linker\n\
73145796c8dcSSimon Schubert notifies gdb of shared library events.  The most common event of interest\n\
73155796c8dcSSimon Schubert to the user would be loading/unloading of a new library."),
73165796c8dcSSimon Schubert 			    NULL,
73175796c8dcSSimon Schubert 			    show_stop_on_solib_events,
73185796c8dcSSimon Schubert 			    &setlist, &showlist);
73195796c8dcSSimon Schubert 
73205796c8dcSSimon Schubert   add_setshow_enum_cmd ("follow-fork-mode", class_run,
73215796c8dcSSimon Schubert 			follow_fork_mode_kind_names,
73225796c8dcSSimon Schubert 			&follow_fork_mode_string, _("\
73235796c8dcSSimon Schubert Set debugger response to a program call of fork or vfork."), _("\
73245796c8dcSSimon Schubert Show debugger response to a program call of fork or vfork."), _("\
73255796c8dcSSimon Schubert A fork or vfork creates a new process.  follow-fork-mode can be:\n\
73265796c8dcSSimon Schubert   parent  - the original process is debugged after a fork\n\
73275796c8dcSSimon Schubert   child   - the new process is debugged after a fork\n\
73285796c8dcSSimon Schubert The unfollowed process will continue to run.\n\
73295796c8dcSSimon Schubert By default, the debugger will follow the parent process."),
73305796c8dcSSimon Schubert 			NULL,
73315796c8dcSSimon Schubert 			show_follow_fork_mode_string,
73325796c8dcSSimon Schubert 			&setlist, &showlist);
73335796c8dcSSimon Schubert 
7334cf7f2e2dSJohn Marino   add_setshow_enum_cmd ("follow-exec-mode", class_run,
7335cf7f2e2dSJohn Marino 			follow_exec_mode_names,
7336cf7f2e2dSJohn Marino 			&follow_exec_mode_string, _("\
7337cf7f2e2dSJohn Marino Set debugger response to a program call of exec."), _("\
7338cf7f2e2dSJohn Marino Show debugger response to a program call of exec."), _("\
7339cf7f2e2dSJohn Marino An exec call replaces the program image of a process.\n\
7340cf7f2e2dSJohn Marino \n\
7341cf7f2e2dSJohn Marino follow-exec-mode can be:\n\
7342cf7f2e2dSJohn Marino \n\
7343cf7f2e2dSJohn Marino   new - the debugger creates a new inferior and rebinds the process\n\
7344cf7f2e2dSJohn Marino to this new inferior.  The program the process was running before\n\
7345cf7f2e2dSJohn Marino the exec call can be restarted afterwards by restarting the original\n\
7346cf7f2e2dSJohn Marino inferior.\n\
7347cf7f2e2dSJohn Marino \n\
7348cf7f2e2dSJohn Marino   same - the debugger keeps the process bound to the same inferior.\n\
7349cf7f2e2dSJohn Marino The new executable image replaces the previous executable loaded in\n\
7350cf7f2e2dSJohn Marino the inferior.  Restarting the inferior after the exec call restarts\n\
7351cf7f2e2dSJohn Marino the executable the process was running after the exec call.\n\
7352cf7f2e2dSJohn Marino \n\
7353cf7f2e2dSJohn Marino By default, the debugger will use the same inferior."),
7354cf7f2e2dSJohn Marino 			NULL,
7355cf7f2e2dSJohn Marino 			show_follow_exec_mode_string,
7356cf7f2e2dSJohn Marino 			&setlist, &showlist);
7357cf7f2e2dSJohn Marino 
73585796c8dcSSimon Schubert   add_setshow_enum_cmd ("scheduler-locking", class_run,
73595796c8dcSSimon Schubert 			scheduler_enums, &scheduler_mode, _("\
73605796c8dcSSimon Schubert Set mode for locking scheduler during execution."), _("\
73615796c8dcSSimon Schubert Show mode for locking scheduler during execution."), _("\
73625796c8dcSSimon Schubert off  == no locking (threads may preempt at any time)\n\
73635796c8dcSSimon Schubert on   == full locking (no thread except the current thread may run)\n\
73645796c8dcSSimon Schubert step == scheduler locked during every single-step operation.\n\
73655796c8dcSSimon Schubert 	In this mode, no other thread may run during a step command.\n\
73665796c8dcSSimon Schubert 	Other threads may run while stepping over a function call ('next')."),
73675796c8dcSSimon Schubert 			set_schedlock_func,	/* traps on target vector */
73685796c8dcSSimon Schubert 			show_scheduler_mode,
73695796c8dcSSimon Schubert 			&setlist, &showlist);
73705796c8dcSSimon Schubert 
73715796c8dcSSimon Schubert   add_setshow_boolean_cmd ("schedule-multiple", class_run, &sched_multi, _("\
73725796c8dcSSimon Schubert Set mode for resuming threads of all processes."), _("\
73735796c8dcSSimon Schubert Show mode for resuming threads of all processes."), _("\
73745796c8dcSSimon Schubert When on, execution commands (such as 'continue' or 'next') resume all\n\
73755796c8dcSSimon Schubert threads of all processes.  When off (which is the default), execution\n\
73765796c8dcSSimon Schubert commands only resume the threads of the current process.  The set of\n\
73775796c8dcSSimon Schubert threads that are resumed is further refined by the scheduler-locking\n\
73785796c8dcSSimon Schubert mode (see help set scheduler-locking)."),
73795796c8dcSSimon Schubert 			   NULL,
73805796c8dcSSimon Schubert 			   show_schedule_multiple,
73815796c8dcSSimon Schubert 			   &setlist, &showlist);
73825796c8dcSSimon Schubert 
73835796c8dcSSimon Schubert   add_setshow_boolean_cmd ("step-mode", class_run, &step_stop_if_no_debug, _("\
73845796c8dcSSimon Schubert Set mode of the step operation."), _("\
73855796c8dcSSimon Schubert Show mode of the step operation."), _("\
73865796c8dcSSimon Schubert When set, doing a step over a function without debug line information\n\
73875796c8dcSSimon Schubert will stop at the first instruction of that function. Otherwise, the\n\
73885796c8dcSSimon Schubert function is skipped and the step command stops at a different source line."),
73895796c8dcSSimon Schubert 			   NULL,
73905796c8dcSSimon Schubert 			   show_step_stop_if_no_debug,
73915796c8dcSSimon Schubert 			   &setlist, &showlist);
73925796c8dcSSimon Schubert 
7393*ef5ccd6cSJohn Marino   add_setshow_auto_boolean_cmd ("displaced-stepping", class_run,
73945796c8dcSSimon Schubert 				&can_use_displaced_stepping, _("\
73955796c8dcSSimon Schubert Set debugger's willingness to use displaced stepping."), _("\
73965796c8dcSSimon Schubert Show debugger's willingness to use displaced stepping."), _("\
73975796c8dcSSimon Schubert If on, gdb will use displaced stepping to step over breakpoints if it is\n\
73985796c8dcSSimon Schubert supported by the target architecture.  If off, gdb will not use displaced\n\
73995796c8dcSSimon Schubert stepping to step over breakpoints, even if such is supported by the target\n\
74005796c8dcSSimon Schubert architecture.  If auto (which is the default), gdb will use displaced stepping\n\
74015796c8dcSSimon Schubert if the target architecture supports it and non-stop mode is active, but will not\n\
74025796c8dcSSimon Schubert use it in all-stop mode (see help set non-stop)."),
74035796c8dcSSimon Schubert 				NULL,
74045796c8dcSSimon Schubert 				show_can_use_displaced_stepping,
74055796c8dcSSimon Schubert 				&setlist, &showlist);
74065796c8dcSSimon Schubert 
74075796c8dcSSimon Schubert   add_setshow_enum_cmd ("exec-direction", class_run, exec_direction_names,
74085796c8dcSSimon Schubert 			&exec_direction, _("Set direction of execution.\n\
74095796c8dcSSimon Schubert Options are 'forward' or 'reverse'."),
74105796c8dcSSimon Schubert 			_("Show direction of execution (forward/reverse)."),
74115796c8dcSSimon Schubert 			_("Tells gdb whether to execute forward or backward."),
74125796c8dcSSimon Schubert 			set_exec_direction_func, show_exec_direction_func,
74135796c8dcSSimon Schubert 			&setlist, &showlist);
74145796c8dcSSimon Schubert 
7415cf7f2e2dSJohn Marino   /* Set/show detach-on-fork: user-settable mode.  */
7416cf7f2e2dSJohn Marino 
7417cf7f2e2dSJohn Marino   add_setshow_boolean_cmd ("detach-on-fork", class_run, &detach_fork, _("\
7418cf7f2e2dSJohn Marino Set whether gdb will detach the child of a fork."), _("\
7419cf7f2e2dSJohn Marino Show whether gdb will detach the child of a fork."), _("\
7420cf7f2e2dSJohn Marino Tells gdb whether to detach the child of a fork."),
7421cf7f2e2dSJohn Marino 			   NULL, NULL, &setlist, &showlist);
7422cf7f2e2dSJohn Marino 
7423a45ae5f8SJohn Marino   /* Set/show disable address space randomization mode.  */
7424a45ae5f8SJohn Marino 
7425a45ae5f8SJohn Marino   add_setshow_boolean_cmd ("disable-randomization", class_support,
7426a45ae5f8SJohn Marino 			   &disable_randomization, _("\
7427a45ae5f8SJohn Marino Set disabling of debuggee's virtual address space randomization."), _("\
7428a45ae5f8SJohn Marino Show disabling of debuggee's virtual address space randomization."), _("\
7429a45ae5f8SJohn Marino When this mode is on (which is the default), randomization of the virtual\n\
7430a45ae5f8SJohn Marino address space is disabled.  Standalone programs run with the randomization\n\
7431a45ae5f8SJohn Marino enabled by default on some platforms."),
7432a45ae5f8SJohn Marino 			   &set_disable_randomization,
7433a45ae5f8SJohn Marino 			   &show_disable_randomization,
7434a45ae5f8SJohn Marino 			   &setlist, &showlist);
7435a45ae5f8SJohn Marino 
74365796c8dcSSimon Schubert   /* ptid initializations */
74375796c8dcSSimon Schubert   inferior_ptid = null_ptid;
74385796c8dcSSimon Schubert   target_last_wait_ptid = minus_one_ptid;
74395796c8dcSSimon Schubert 
74405796c8dcSSimon Schubert   observer_attach_thread_ptid_changed (infrun_thread_ptid_changed);
74415796c8dcSSimon Schubert   observer_attach_thread_stop_requested (infrun_thread_stop_requested);
74425796c8dcSSimon Schubert   observer_attach_thread_exit (infrun_thread_thread_exit);
7443cf7f2e2dSJohn Marino   observer_attach_inferior_exit (infrun_inferior_exit);
74445796c8dcSSimon Schubert 
74455796c8dcSSimon Schubert   /* Explicitly create without lookup, since that tries to create a
74465796c8dcSSimon Schubert      value with a void typed value, and when we get here, gdbarch
74475796c8dcSSimon Schubert      isn't initialized yet.  At this point, we're quite sure there
74485796c8dcSSimon Schubert      isn't another convenience variable of the same name.  */
7449*ef5ccd6cSJohn Marino   create_internalvar_type_lazy ("_siginfo", &siginfo_funcs, NULL);
7450cf7f2e2dSJohn Marino 
7451cf7f2e2dSJohn Marino   add_setshow_boolean_cmd ("observer", no_class,
7452cf7f2e2dSJohn Marino 			   &observer_mode_1, _("\
7453cf7f2e2dSJohn Marino Set whether gdb controls the inferior in observer mode."), _("\
7454cf7f2e2dSJohn Marino Show whether gdb controls the inferior in observer mode."), _("\
7455cf7f2e2dSJohn Marino In observer mode, GDB can get data from the inferior, but not\n\
7456cf7f2e2dSJohn Marino affect its execution.  Registers and memory may not be changed,\n\
7457cf7f2e2dSJohn Marino breakpoints may not be set, and the program cannot be interrupted\n\
7458cf7f2e2dSJohn Marino or signalled."),
7459cf7f2e2dSJohn Marino 			   set_observer_mode,
7460cf7f2e2dSJohn Marino 			   show_observer_mode,
7461cf7f2e2dSJohn Marino 			   &setlist,
7462cf7f2e2dSJohn Marino 			   &showlist);
74635796c8dcSSimon Schubert }
7464