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