2004-11-21 13:51:53 +00:00
|
|
|
|
/* Low-level child interface to ptrace.
|
2004-09-12 13:04:41 +00:00
|
|
|
|
|
|
|
|
|
Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
|
2005-01-10 20:36:38 +00:00
|
|
|
|
1998, 1999, 2000, 2001, 2002, 2004, 2005
|
|
|
|
|
Free Software Foundation, Inc.
|
2004-09-12 13:04:41 +00:00
|
|
|
|
|
|
|
|
|
This file is part of GDB.
|
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
|
Boston, MA 02111-1307, USA. */
|
|
|
|
|
|
|
|
|
|
#include "defs.h"
|
|
|
|
|
#include "command.h"
|
2004-11-21 13:51:53 +00:00
|
|
|
|
#include "inferior.h"
|
|
|
|
|
#include "inflow.h"
|
2004-09-12 13:04:41 +00:00
|
|
|
|
#include "gdbcore.h"
|
2004-11-21 13:51:53 +00:00
|
|
|
|
#include "observer.h"
|
2005-01-10 20:36:38 +00:00
|
|
|
|
#include "regcache.h"
|
2004-09-12 13:04:41 +00:00
|
|
|
|
|
2005-01-10 20:36:38 +00:00
|
|
|
|
#include "gdb_assert.h"
|
2004-11-21 13:51:53 +00:00
|
|
|
|
#include "gdb_string.h"
|
|
|
|
|
#include "gdb_ptrace.h"
|
2004-10-15 13:29:33 +00:00
|
|
|
|
#include "gdb_wait.h"
|
2004-09-12 13:04:41 +00:00
|
|
|
|
#include <signal.h>
|
|
|
|
|
|
2004-11-21 13:51:53 +00:00
|
|
|
|
#include "inf-child.h"
|
|
|
|
|
|
|
|
|
|
/* HACK: Save the ptrace ops returned by inf_ptrace_target. */
|
2004-09-12 13:04:41 +00:00
|
|
|
|
static struct target_ops *ptrace_ops_hack;
|
* inf-ptrace.c: Reorder functions.
(inf_ptrace_open, inf_ptrace_reported_exec_events_per_call)
(inf_ptrace_can_run, inf_ptrace_post_attach): Removed.
(inf_ptrace_target): Don't set to_open,
to_reported_exec_events_per_call, to_can_run, to_post_attach,
to_stratum, to_has_all_memory, to_has_memory, to_has_stack,
to_has_registers, to_has_execution, to_magic. Reorder remaining
initializations.
2005-07-25 20:19:37 +00:00
|
|
|
|
|
|
|
|
|
|
2005-07-25 21:11:02 +00:00
|
|
|
|
#ifdef PT_GET_PROCESS_STATE
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
inf_ptrace_follow_fork (int follow_child)
|
|
|
|
|
{
|
|
|
|
|
pid_t pid, fpid;
|
|
|
|
|
ptrace_state_t pe;
|
|
|
|
|
|
|
|
|
|
/* FIXME: kettenis/20050720: This stuff should really be passed as
|
|
|
|
|
an argument by our caller. */
|
|
|
|
|
{
|
|
|
|
|
ptid_t ptid;
|
|
|
|
|
struct target_waitstatus status;
|
|
|
|
|
|
|
|
|
|
get_last_target_status (&ptid, &status);
|
|
|
|
|
gdb_assert (status.kind == TARGET_WAITKIND_FORKED);
|
|
|
|
|
|
|
|
|
|
pid = ptid_get_pid (ptid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ptrace (PT_GET_PROCESS_STATE, pid,
|
|
|
|
|
(PTRACE_TYPE_ARG3)&pe, sizeof pe) == -1)
|
|
|
|
|
perror_with_name (("ptrace"));
|
|
|
|
|
|
|
|
|
|
gdb_assert (pe.pe_report_event == PTRACE_FORK);
|
|
|
|
|
fpid = pe.pe_other_pid;
|
|
|
|
|
|
|
|
|
|
if (follow_child)
|
|
|
|
|
{
|
|
|
|
|
inferior_ptid = pid_to_ptid (fpid);
|
|
|
|
|
detach_breakpoints (pid);
|
|
|
|
|
|
|
|
|
|
/* Reset breakpoints in the child as appropriate. */
|
|
|
|
|
follow_inferior_reset_breakpoints ();
|
|
|
|
|
|
|
|
|
|
if (ptrace (PT_DETACH, pid, (PTRACE_TYPE_ARG3)1, 0) == -1)
|
|
|
|
|
perror_with_name (("ptrace"));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
inferior_ptid = pid_to_ptid (pid);
|
|
|
|
|
detach_breakpoints (fpid);
|
|
|
|
|
|
|
|
|
|
if (ptrace (PT_DETACH, fpid, (PTRACE_TYPE_ARG3)1, 0) == -1)
|
|
|
|
|
perror_with_name (("ptrace"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif /* PT_GET_PROCESS_STATE */
|
|
|
|
|
|
|
|
|
|
|
2005-07-25 20:42:29 +00:00
|
|
|
|
/* Prepare to be traced. */
|
2004-09-12 13:04:41 +00:00
|
|
|
|
|
|
|
|
|
static void
|
* inf-ptrace.c: Reorder functions.
(inf_ptrace_open, inf_ptrace_reported_exec_events_per_call)
(inf_ptrace_can_run, inf_ptrace_post_attach): Removed.
(inf_ptrace_target): Don't set to_open,
to_reported_exec_events_per_call, to_can_run, to_post_attach,
to_stratum, to_has_all_memory, to_has_memory, to_has_stack,
to_has_registers, to_has_execution, to_magic. Reorder remaining
initializations.
2005-07-25 20:19:37 +00:00
|
|
|
|
inf_ptrace_me (void)
|
2004-09-12 13:04:41 +00:00
|
|
|
|
{
|
* inf-ptrace.c: Reorder functions.
(inf_ptrace_open, inf_ptrace_reported_exec_events_per_call)
(inf_ptrace_can_run, inf_ptrace_post_attach): Removed.
(inf_ptrace_target): Don't set to_open,
to_reported_exec_events_per_call, to_can_run, to_post_attach,
to_stratum, to_has_all_memory, to_has_memory, to_has_stack,
to_has_registers, to_has_execution, to_magic. Reorder remaining
initializations.
2005-07-25 20:19:37 +00:00
|
|
|
|
/* "Trace me, Dr. Memory!" */
|
2005-07-25 20:42:29 +00:00
|
|
|
|
ptrace (PT_TRACE_ME, 0, (PTRACE_TYPE_ARG3)0, 0);
|
2004-09-12 13:04:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-07-25 20:42:29 +00:00
|
|
|
|
/* Start tracing PID. */
|
2004-09-12 13:04:41 +00:00
|
|
|
|
|
|
|
|
|
static void
|
* inf-ptrace.c: Reorder functions.
(inf_ptrace_open, inf_ptrace_reported_exec_events_per_call)
(inf_ptrace_can_run, inf_ptrace_post_attach): Removed.
(inf_ptrace_target): Don't set to_open,
to_reported_exec_events_per_call, to_can_run, to_post_attach,
to_stratum, to_has_all_memory, to_has_memory, to_has_stack,
to_has_registers, to_has_execution, to_magic. Reorder remaining
initializations.
2005-07-25 20:19:37 +00:00
|
|
|
|
inf_ptrace_him (int pid)
|
2004-09-12 13:04:41 +00:00
|
|
|
|
{
|
2005-07-25 21:11:02 +00:00
|
|
|
|
#ifdef PT_GET_PROCESS_STATE
|
|
|
|
|
{
|
|
|
|
|
ptrace_event_t pe;
|
|
|
|
|
|
|
|
|
|
/* Set the initial event mask. */
|
|
|
|
|
memset (&pe, 0, sizeof pe);
|
|
|
|
|
pe.pe_set_event |= PTRACE_FORK;
|
|
|
|
|
if (ptrace (PT_SET_EVENT_MASK, pid,
|
|
|
|
|
(PTRACE_TYPE_ARG3)&pe, sizeof pe) == -1)
|
|
|
|
|
perror_with_name (("ptrace"));
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
* inf-ptrace.c: Reorder functions.
(inf_ptrace_open, inf_ptrace_reported_exec_events_per_call)
(inf_ptrace_can_run, inf_ptrace_post_attach): Removed.
(inf_ptrace_target): Don't set to_open,
to_reported_exec_events_per_call, to_can_run, to_post_attach,
to_stratum, to_has_all_memory, to_has_memory, to_has_stack,
to_has_registers, to_has_execution, to_magic. Reorder remaining
initializations.
2005-07-25 20:19:37 +00:00
|
|
|
|
push_target (ptrace_ops_hack);
|
2004-09-12 13:04:41 +00:00
|
|
|
|
|
* inf-ptrace.c: Reorder functions.
(inf_ptrace_open, inf_ptrace_reported_exec_events_per_call)
(inf_ptrace_can_run, inf_ptrace_post_attach): Removed.
(inf_ptrace_target): Don't set to_open,
to_reported_exec_events_per_call, to_can_run, to_post_attach,
to_stratum, to_has_all_memory, to_has_memory, to_has_stack,
to_has_registers, to_has_execution, to_magic. Reorder remaining
initializations.
2005-07-25 20:19:37 +00:00
|
|
|
|
/* On some targets, there must be some explicit synchronization
|
|
|
|
|
between the parent and child processes after the debugger
|
|
|
|
|
forks, and before the child execs the debuggee program. This
|
|
|
|
|
call basically gives permission for the child to exec. */
|
2004-09-12 13:04:41 +00:00
|
|
|
|
|
* inf-ptrace.c: Reorder functions.
(inf_ptrace_open, inf_ptrace_reported_exec_events_per_call)
(inf_ptrace_can_run, inf_ptrace_post_attach): Removed.
(inf_ptrace_target): Don't set to_open,
to_reported_exec_events_per_call, to_can_run, to_post_attach,
to_stratum, to_has_all_memory, to_has_memory, to_has_stack,
to_has_registers, to_has_execution, to_magic. Reorder remaining
initializations.
2005-07-25 20:19:37 +00:00
|
|
|
|
target_acknowledge_created_inferior (pid);
|
2004-09-12 13:04:41 +00:00
|
|
|
|
|
* inf-ptrace.c: Reorder functions.
(inf_ptrace_open, inf_ptrace_reported_exec_events_per_call)
(inf_ptrace_can_run, inf_ptrace_post_attach): Removed.
(inf_ptrace_target): Don't set to_open,
to_reported_exec_events_per_call, to_can_run, to_post_attach,
to_stratum, to_has_all_memory, to_has_memory, to_has_stack,
to_has_registers, to_has_execution, to_magic. Reorder remaining
initializations.
2005-07-25 20:19:37 +00:00
|
|
|
|
/* START_INFERIOR_TRAPS_EXPECTED is defined in inferior.h, and will
|
|
|
|
|
be 1 or 2 depending on whether we're starting without or with a
|
|
|
|
|
shell. */
|
|
|
|
|
startup_inferior (START_INFERIOR_TRAPS_EXPECTED);
|
|
|
|
|
|
|
|
|
|
/* On some targets, there must be some explicit actions taken after
|
|
|
|
|
the inferior has been started up. */
|
|
|
|
|
target_post_startup_inferior (pid_to_ptid (pid));
|
2004-09-12 13:04:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-07-25 20:42:29 +00:00
|
|
|
|
/* Start a new inferior Unix child process. EXEC_FILE is the file to
|
|
|
|
|
run, ALLARGS is a string containing the arguments to the program.
|
|
|
|
|
ENV is the environment vector to pass. If FROM_TTY is non-zero, be
|
|
|
|
|
chatty about it. */
|
2004-09-12 13:04:41 +00:00
|
|
|
|
|
* inf-ptrace.c: Reorder functions.
(inf_ptrace_open, inf_ptrace_reported_exec_events_per_call)
(inf_ptrace_can_run, inf_ptrace_post_attach): Removed.
(inf_ptrace_target): Don't set to_open,
to_reported_exec_events_per_call, to_can_run, to_post_attach,
to_stratum, to_has_all_memory, to_has_memory, to_has_stack,
to_has_registers, to_has_execution, to_magic. Reorder remaining
initializations.
2005-07-25 20:19:37 +00:00
|
|
|
|
static void
|
|
|
|
|
inf_ptrace_create_inferior (char *exec_file, char *allargs, char **env,
|
|
|
|
|
int from_tty)
|
2004-09-12 13:04:41 +00:00
|
|
|
|
{
|
* inf-ptrace.c: Reorder functions.
(inf_ptrace_open, inf_ptrace_reported_exec_events_per_call)
(inf_ptrace_can_run, inf_ptrace_post_attach): Removed.
(inf_ptrace_target): Don't set to_open,
to_reported_exec_events_per_call, to_can_run, to_post_attach,
to_stratum, to_has_all_memory, to_has_memory, to_has_stack,
to_has_registers, to_has_execution, to_magic. Reorder remaining
initializations.
2005-07-25 20:19:37 +00:00
|
|
|
|
fork_inferior (exec_file, allargs, env, inf_ptrace_me, inf_ptrace_him,
|
|
|
|
|
NULL, NULL);
|
2005-07-25 20:42:29 +00:00
|
|
|
|
|
* inf-ptrace.c: Reorder functions.
(inf_ptrace_open, inf_ptrace_reported_exec_events_per_call)
(inf_ptrace_can_run, inf_ptrace_post_attach): Removed.
(inf_ptrace_target): Don't set to_open,
to_reported_exec_events_per_call, to_can_run, to_post_attach,
to_stratum, to_has_all_memory, to_has_memory, to_has_stack,
to_has_registers, to_has_execution, to_magic. Reorder remaining
initializations.
2005-07-25 20:19:37 +00:00
|
|
|
|
/* We are at the first instruction we care about. */
|
|
|
|
|
observer_notify_inferior_created (¤t_target, from_tty);
|
2005-07-25 20:42:29 +00:00
|
|
|
|
|
* inf-ptrace.c: Reorder functions.
(inf_ptrace_open, inf_ptrace_reported_exec_events_per_call)
(inf_ptrace_can_run, inf_ptrace_post_attach): Removed.
(inf_ptrace_target): Don't set to_open,
to_reported_exec_events_per_call, to_can_run, to_post_attach,
to_stratum, to_has_all_memory, to_has_memory, to_has_stack,
to_has_registers, to_has_execution, to_magic. Reorder remaining
initializations.
2005-07-25 20:19:37 +00:00
|
|
|
|
/* Pedal to the metal... */
|
|
|
|
|
proceed ((CORE_ADDR) -1, TARGET_SIGNAL_0, 0);
|
2004-09-12 13:04:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-07-25 20:42:29 +00:00
|
|
|
|
/* Clean up a rotting corpse of an inferior after it died. */
|
|
|
|
|
|
* inf-ptrace.c: Reorder functions.
(inf_ptrace_open, inf_ptrace_reported_exec_events_per_call)
(inf_ptrace_can_run, inf_ptrace_post_attach): Removed.
(inf_ptrace_target): Don't set to_open,
to_reported_exec_events_per_call, to_can_run, to_post_attach,
to_stratum, to_has_all_memory, to_has_memory, to_has_stack,
to_has_registers, to_has_execution, to_magic. Reorder remaining
initializations.
2005-07-25 20:19:37 +00:00
|
|
|
|
static void
|
|
|
|
|
inf_ptrace_mourn_inferior (void)
|
2004-09-12 13:04:41 +00:00
|
|
|
|
{
|
2005-07-25 20:42:29 +00:00
|
|
|
|
int status;
|
|
|
|
|
|
|
|
|
|
/* Wait just one more time to collect the inferior's exit status.
|
|
|
|
|
Don not check whether this succeeds though, since we may be
|
|
|
|
|
dealing with a process that we attached to. Such a process will
|
|
|
|
|
only report its exit status to its origional parent. */
|
|
|
|
|
waitpid (ptid_get_pid (inferior_ptid), &status, 0);
|
|
|
|
|
|
* inf-ptrace.c: Reorder functions.
(inf_ptrace_open, inf_ptrace_reported_exec_events_per_call)
(inf_ptrace_can_run, inf_ptrace_post_attach): Removed.
(inf_ptrace_target): Don't set to_open,
to_reported_exec_events_per_call, to_can_run, to_post_attach,
to_stratum, to_has_all_memory, to_has_memory, to_has_stack,
to_has_registers, to_has_execution, to_magic. Reorder remaining
initializations.
2005-07-25 20:19:37 +00:00
|
|
|
|
unpush_target (ptrace_ops_hack);
|
|
|
|
|
generic_mourn_inferior ();
|
2004-09-12 13:04:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-07-25 20:42:29 +00:00
|
|
|
|
/* Attach to the process specified by ARGS. If FROM_TTY is non-zero,
|
|
|
|
|
be chatty about it. */
|
2004-09-12 13:04:41 +00:00
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
inf_ptrace_attach (char *args, int from_tty)
|
|
|
|
|
{
|
|
|
|
|
char *exec_file;
|
2005-07-25 20:42:29 +00:00
|
|
|
|
pid_t pid;
|
2004-09-12 13:04:41 +00:00
|
|
|
|
char *dummy;
|
|
|
|
|
|
|
|
|
|
if (!args)
|
2005-02-11 Andrew Cagney <cagney@gnu.org>
Mark up error_no_arg, query, perror_with_name, complaint, and
internal_error.
* breakpoint.c, cp-abi.c, cp-namespace.c, cp-support.c: Update.
* cris-tdep.c, dbxread.c, dictionary.c, dsrec.c: Update.
* dummy-frame.c, dve3900-rom.c, dwarf2-frame.c, dwarf2expr.c: Update.
* dwarf2read.c, dwarfread.c, elfread.c, event-loop.c: Update.
* exceptions.c, exec.c, f-lang.c, findvar.c, fork-child.c: Update.
* frame-unwind.c, frame.c, frv-linux-tdep.c, frv-tdep.c: Update.
* gdb_assert.h, gdbarch.c, gdbtypes.c, gnu-nat.c: Update.
* go32-nat.c, hppa-tdep.c, hppabsd-nat.c, hpread.c: Update.
* i386-linux-nat.c, i386-nat.c, i386-tdep.c, i386bsd-nat.c: Update.
* i386fbsd-nat.c, inf-ptrace.c, inf-ttrace.c, infcall.c: Update.
* infcmd.c, inflow.c, infptrace.c, infrun.c, inftarg.c: Update.
* interps.c, language.c, linespec.c, linux-nat.c: Update.
* m32r-linux-nat.c, m68k-tdep.c, m68kbsd-nat.c: Update.
* m68klinux-nat.c, m88kbsd-nat.c, macroexp.c, macroscope.c: Update.
* macrotab.c, maint.c, mdebugread.c, memattr.c: Update.
* mips-linux-tdep.c, mips-tdep.c, mips64obsd-nat.c: Update.
* mipsnbsd-nat.c, mn10300-tdep.c, monitor.c, nto-procfs.c: Update.
* objc-lang.c, objfiles.c, objfiles.h, ocd.c, osabi.c: Update.
* parse.c, ppc-bdm.c, ppc-linux-nat.c, ppc-sysv-tdep.c: Update.
* ppcnbsd-nat.c, ppcobsd-nat.c, printcmd.c, procfs.c: Update.
* regcache.c, reggroups.c, remote-e7000.c, remote-mips.c: Update.
* remote-rdp.c, remote-sds.c, remote-sim.c, remote-st.c: Update.
* remote-utils.c, remote.c, rs6000-nat.c, rs6000-tdep.c: Update.
* s390-nat.c, s390-tdep.c, sentinel-frame.c, serial.c: Update.
* sh-tdep.c, sh3-rom.c, sh64-tdep.c, shnbsd-nat.c: Update.
* solib-aix5.c, solib-svr4.c, solib.c, source.c: Update.
* sparc-nat.c, stabsread.c, stack.c, symfile.c, symtab.c: Update.
* symtab.h, target.c, tracepoint.c, ui-file.c, ui-out.c: Update.
* utils.c, valops.c, valprint.c, vax-nat.c, vaxbsd-nat.c: Update.
* win32-nat.c, xcoffread.c, xstormy16-tdep.c: Update.
* cli/cli-cmds.c, cli/cli-logging.c, cli/cli-script.c: Update.
* cli/cli-setshow.c, mi/mi-cmd-break.c, mi/mi-cmds.c: Update.
* mi/mi-console.c, mi/mi-getopt.c, mi/mi-out.c: Update.
* tui/tui-file.c, tui/tui-interp.c: Update.
2005-02-11 18:13:55 +00:00
|
|
|
|
error_no_arg (_("process-id to attach"));
|
2004-09-12 13:04:41 +00:00
|
|
|
|
|
|
|
|
|
dummy = args;
|
|
|
|
|
pid = strtol (args, &dummy, 0);
|
2004-11-20 17:03:38 +00:00
|
|
|
|
/* Some targets don't set errno on errors, grrr! */
|
2004-09-25 12:32:01 +00:00
|
|
|
|
if (pid == 0 && args == dummy)
|
2005-02-10 Andrew Cagney <cagney@gnu.org>
Mark up all error and warning messages.
* ada-lang.c, amd64-tdep.c, arch-utils.c, breakpoint.c: Update.
* bsd-kvm.c, bsd-uthread.c, coff-solib.h, coffread.c: Update.
* core-aout.c, core-regset.c, corefile.c, corelow.c: Update.
* cp-abi.c, cp-support.c, cp-valprint.c, cris-tdep.c: Update.
* dbxread.c, demangle.c, doublest.c, dsrec.c: Update.
* dve3900-rom.c, dwarf2expr.c, dwarf2loc.c: Update.
* dwarf2read.c, dwarfread.c, elfread.c, eval.c: Update.
* event-top.c, exec.c, expprint.c, f-lang.c: Update.
* f-typeprint.c, f-valprint.c, fbsd-nat.c, findvar.c: Update.
* frame.c, frv-linux-tdep.c, gcore.c, gdbtypes.c: Update.
* gnu-nat.c, gnu-v2-abi.c, gnu-v3-abi.c, go32-nat.c: Update.
* hpacc-abi.c, hppa-hpux-nat.c, hppa-hpux-tdep.c: Update.
* hppa-linux-nat.c, hppa-linux-tdep.c, hppa-tdep.c: Update.
* hpread.c, hpux-thread.c, i386-linux-nat.c: Update.
* i386-linux-tdep.c, i386-tdep.c, i386bsd-nat.c: Update.
* i386gnu-nat.c, i387-tdep.c, ia64-linux-nat.c: Update.
* ia64-tdep.c, inf-child.c, inf-ptrace.c, inf-ttrace.c: Update.
* infcall.c, infcmd.c, inflow.c, infptrace.c, infrun.c: Update.
* inftarg.c, interps.c, irix5-nat.c, jv-lang.c: Update.
* kod-cisco.c, kod.c, language.c, libunwind-frame.c: Update.
* linespec.c, linux-nat.c, linux-thread-db.c, m2-lang.c: Update.
* m32r-rom.c, m68hc11-tdep.c, m68k-tdep.c: Update.
* m68klinux-nat.c, macrocmd.c, macroexp.c, main.c: Update.
* maint.c, mdebugread.c, mem-break.c, memattr.c: Update.
* mips-linux-tdep.c, mips-tdep.c, mipsread.c, monitor.c: Update.
* nlmread.c, nto-procfs.c, objc-lang.c, objfiles.c: Update.
* observer.c, ocd.c, p-lang.c, p-typeprint.c: Update.
* p-valprint.c, pa64solib.c, parse.c, ppc-linux-tdep.c: Update.
* ppcnbsd-tdep.c, printcmd.c, procfs.c, remote-e7000.c: Update.
* remote-fileio.c, remote-m32r-sdi.c, remote-rdi.c: Update.
* remote-rdp.c, remote-sim.c, remote-st.c: Update.
* remote-utils.c, remote-utils.h, remote.c: Update.
* rom68k-rom.c, rs6000-nat.c, s390-tdep.c, scm-lang.c: Update.
* ser-e7kpc.c, ser-tcp.c, ser-unix.c, sh-tdep.c: Update.
* sh3-rom.c, shnbsd-tdep.c, sol-thread.c, solib-aix5.c: Update.
* solib-frv.c, solib-irix.c, solib-osf.c, solib-pa64.c: Update.
* solib-som.c, solib-sunos.c, solib-svr4.c, solib.c: Update.
* somread.c, somsolib.c, source.c, stabsread.c: Update.
* stack.c, std-regs.c, symfile-mem.c, symfile.c: Update.
* symmisc.c, symtab.c, target.c, thread.c, top.c: Update.
* tracepoint.c, trad-frame.c, typeprint.c, utils.c: Update.
* uw-thread.c, valarith.c, valops.c, valprint.c: Update.
* value.c, varobj.c, version.in, win32-nat.c, wince.c: Update.
* xcoffread.c, xcoffsolib.c, cli/cli-cmds.c: Update.
* cli/cli-decode.c, cli/cli-dump.c, cli/cli-logging.c: Update.
* cli/cli-script.c, cli/cli-setshow.c, mi/mi-cmd-break.c: Update.
* mi/mi-cmd-disas.c, mi/mi-cmd-env.c, mi/mi-cmd-file.c: Update.
* mi/mi-cmd-stack.c, mi/mi-cmd-var.c, mi/mi-getopt.c: Update.
* mi/mi-symbol-cmds.c, tui/tui-layout.c, tui/tui-stack.c: Update.
* tui/tui-win.c: Update.
2005-02-11 04:06:14 +00:00
|
|
|
|
error (_("Illegal process-id: %s."), args);
|
2004-09-12 13:04:41 +00:00
|
|
|
|
|
2004-11-20 17:03:38 +00:00
|
|
|
|
if (pid == getpid ()) /* Trying to masturbate? */
|
2005-02-10 Andrew Cagney <cagney@gnu.org>
Mark up all error and warning messages.
* ada-lang.c, amd64-tdep.c, arch-utils.c, breakpoint.c: Update.
* bsd-kvm.c, bsd-uthread.c, coff-solib.h, coffread.c: Update.
* core-aout.c, core-regset.c, corefile.c, corelow.c: Update.
* cp-abi.c, cp-support.c, cp-valprint.c, cris-tdep.c: Update.
* dbxread.c, demangle.c, doublest.c, dsrec.c: Update.
* dve3900-rom.c, dwarf2expr.c, dwarf2loc.c: Update.
* dwarf2read.c, dwarfread.c, elfread.c, eval.c: Update.
* event-top.c, exec.c, expprint.c, f-lang.c: Update.
* f-typeprint.c, f-valprint.c, fbsd-nat.c, findvar.c: Update.
* frame.c, frv-linux-tdep.c, gcore.c, gdbtypes.c: Update.
* gnu-nat.c, gnu-v2-abi.c, gnu-v3-abi.c, go32-nat.c: Update.
* hpacc-abi.c, hppa-hpux-nat.c, hppa-hpux-tdep.c: Update.
* hppa-linux-nat.c, hppa-linux-tdep.c, hppa-tdep.c: Update.
* hpread.c, hpux-thread.c, i386-linux-nat.c: Update.
* i386-linux-tdep.c, i386-tdep.c, i386bsd-nat.c: Update.
* i386gnu-nat.c, i387-tdep.c, ia64-linux-nat.c: Update.
* ia64-tdep.c, inf-child.c, inf-ptrace.c, inf-ttrace.c: Update.
* infcall.c, infcmd.c, inflow.c, infptrace.c, infrun.c: Update.
* inftarg.c, interps.c, irix5-nat.c, jv-lang.c: Update.
* kod-cisco.c, kod.c, language.c, libunwind-frame.c: Update.
* linespec.c, linux-nat.c, linux-thread-db.c, m2-lang.c: Update.
* m32r-rom.c, m68hc11-tdep.c, m68k-tdep.c: Update.
* m68klinux-nat.c, macrocmd.c, macroexp.c, main.c: Update.
* maint.c, mdebugread.c, mem-break.c, memattr.c: Update.
* mips-linux-tdep.c, mips-tdep.c, mipsread.c, monitor.c: Update.
* nlmread.c, nto-procfs.c, objc-lang.c, objfiles.c: Update.
* observer.c, ocd.c, p-lang.c, p-typeprint.c: Update.
* p-valprint.c, pa64solib.c, parse.c, ppc-linux-tdep.c: Update.
* ppcnbsd-tdep.c, printcmd.c, procfs.c, remote-e7000.c: Update.
* remote-fileio.c, remote-m32r-sdi.c, remote-rdi.c: Update.
* remote-rdp.c, remote-sim.c, remote-st.c: Update.
* remote-utils.c, remote-utils.h, remote.c: Update.
* rom68k-rom.c, rs6000-nat.c, s390-tdep.c, scm-lang.c: Update.
* ser-e7kpc.c, ser-tcp.c, ser-unix.c, sh-tdep.c: Update.
* sh3-rom.c, shnbsd-tdep.c, sol-thread.c, solib-aix5.c: Update.
* solib-frv.c, solib-irix.c, solib-osf.c, solib-pa64.c: Update.
* solib-som.c, solib-sunos.c, solib-svr4.c, solib.c: Update.
* somread.c, somsolib.c, source.c, stabsread.c: Update.
* stack.c, std-regs.c, symfile-mem.c, symfile.c: Update.
* symmisc.c, symtab.c, target.c, thread.c, top.c: Update.
* tracepoint.c, trad-frame.c, typeprint.c, utils.c: Update.
* uw-thread.c, valarith.c, valops.c, valprint.c: Update.
* value.c, varobj.c, version.in, win32-nat.c, wince.c: Update.
* xcoffread.c, xcoffsolib.c, cli/cli-cmds.c: Update.
* cli/cli-decode.c, cli/cli-dump.c, cli/cli-logging.c: Update.
* cli/cli-script.c, cli/cli-setshow.c, mi/mi-cmd-break.c: Update.
* mi/mi-cmd-disas.c, mi/mi-cmd-env.c, mi/mi-cmd-file.c: Update.
* mi/mi-cmd-stack.c, mi/mi-cmd-var.c, mi/mi-getopt.c: Update.
* mi/mi-symbol-cmds.c, tui/tui-layout.c, tui/tui-stack.c: Update.
* tui/tui-win.c: Update.
2005-02-11 04:06:14 +00:00
|
|
|
|
error (_("I refuse to debug myself!"));
|
2004-09-12 13:04:41 +00:00
|
|
|
|
|
|
|
|
|
if (from_tty)
|
|
|
|
|
{
|
2005-07-25 20:42:29 +00:00
|
|
|
|
exec_file = get_exec_file (0);
|
2004-09-12 13:04:41 +00:00
|
|
|
|
|
|
|
|
|
if (exec_file)
|
2005-02-11 Andrew Cagney <cagney@gnu.org>
Mark up some of printf_filtered and printf_unfiltered.
* ada-lang.c, annotate.c, arch-utils.c, breakpoint.c: Update.
* corelow.c, cp-namespace.c, cp-support.c, dcache.c: Update.
* demangle.c, dsrec.c, dwarf2read.c, dwarfread.c: Update.
* event-loop.c, event-top.c, exec.c, f-valprint.c: Update.
* gdbtypes.c, inf-loop.c, inf-ptrace.c, inf-ttrace.c: Update.
* infcmd.c, inflow.c, infrun.c, inftarg.c, language.c: Update.
* linespec.c, linux-nat.c, linux-thread-db.c, maint.c: Update.
* mdebugread.c, memattr.c, monitor.c, objc-lang.c: Update.
* ocd.c, osabi.c, printcmd.c, procfs.c, regcache.c: Update.
* remote.c, solib-som.c, solib.c, somsolib.c, source.c: Update.
* stack.c, symfile.c, symmisc.c, target.c, thread.c: Update.
* top.c, utils.c, valprint.c, value.c, cli/cli-cmds.c: Update.
* cli/cli-dump.c, cli/cli-logging.c, tui/tui-hooks.c: Update.
* tui/tui-regs.c, tui/tui-win.c: Update.
2005-02-12 00:39:24 +00:00
|
|
|
|
printf_unfiltered (_("Attaching to program: %s, %s\n"), exec_file,
|
2004-09-12 13:04:41 +00:00
|
|
|
|
target_pid_to_str (pid_to_ptid (pid)));
|
|
|
|
|
else
|
2005-02-11 Andrew Cagney <cagney@gnu.org>
Mark up some of printf_filtered and printf_unfiltered.
* ada-lang.c, annotate.c, arch-utils.c, breakpoint.c: Update.
* corelow.c, cp-namespace.c, cp-support.c, dcache.c: Update.
* demangle.c, dsrec.c, dwarf2read.c, dwarfread.c: Update.
* event-loop.c, event-top.c, exec.c, f-valprint.c: Update.
* gdbtypes.c, inf-loop.c, inf-ptrace.c, inf-ttrace.c: Update.
* infcmd.c, inflow.c, infrun.c, inftarg.c, language.c: Update.
* linespec.c, linux-nat.c, linux-thread-db.c, maint.c: Update.
* mdebugread.c, memattr.c, monitor.c, objc-lang.c: Update.
* ocd.c, osabi.c, printcmd.c, procfs.c, regcache.c: Update.
* remote.c, solib-som.c, solib.c, somsolib.c, source.c: Update.
* stack.c, symfile.c, symmisc.c, target.c, thread.c: Update.
* top.c, utils.c, valprint.c, value.c, cli/cli-cmds.c: Update.
* cli/cli-dump.c, cli/cli-logging.c, tui/tui-hooks.c: Update.
* tui/tui-regs.c, tui/tui-win.c: Update.
2005-02-12 00:39:24 +00:00
|
|
|
|
printf_unfiltered (_("Attaching to %s\n"),
|
2004-09-12 13:04:41 +00:00
|
|
|
|
target_pid_to_str (pid_to_ptid (pid)));
|
|
|
|
|
|
|
|
|
|
gdb_flush (gdb_stdout);
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-25 12:32:01 +00:00
|
|
|
|
#ifdef PT_ATTACH
|
|
|
|
|
errno = 0;
|
2005-07-25 20:42:29 +00:00
|
|
|
|
ptrace (PT_ATTACH, pid, (PTRACE_TYPE_ARG3)0, 0);
|
2004-09-25 12:32:01 +00:00
|
|
|
|
if (errno != 0)
|
2005-02-11 Andrew Cagney <cagney@gnu.org>
Mark up error_no_arg, query, perror_with_name, complaint, and
internal_error.
* breakpoint.c, cp-abi.c, cp-namespace.c, cp-support.c: Update.
* cris-tdep.c, dbxread.c, dictionary.c, dsrec.c: Update.
* dummy-frame.c, dve3900-rom.c, dwarf2-frame.c, dwarf2expr.c: Update.
* dwarf2read.c, dwarfread.c, elfread.c, event-loop.c: Update.
* exceptions.c, exec.c, f-lang.c, findvar.c, fork-child.c: Update.
* frame-unwind.c, frame.c, frv-linux-tdep.c, frv-tdep.c: Update.
* gdb_assert.h, gdbarch.c, gdbtypes.c, gnu-nat.c: Update.
* go32-nat.c, hppa-tdep.c, hppabsd-nat.c, hpread.c: Update.
* i386-linux-nat.c, i386-nat.c, i386-tdep.c, i386bsd-nat.c: Update.
* i386fbsd-nat.c, inf-ptrace.c, inf-ttrace.c, infcall.c: Update.
* infcmd.c, inflow.c, infptrace.c, infrun.c, inftarg.c: Update.
* interps.c, language.c, linespec.c, linux-nat.c: Update.
* m32r-linux-nat.c, m68k-tdep.c, m68kbsd-nat.c: Update.
* m68klinux-nat.c, m88kbsd-nat.c, macroexp.c, macroscope.c: Update.
* macrotab.c, maint.c, mdebugread.c, memattr.c: Update.
* mips-linux-tdep.c, mips-tdep.c, mips64obsd-nat.c: Update.
* mipsnbsd-nat.c, mn10300-tdep.c, monitor.c, nto-procfs.c: Update.
* objc-lang.c, objfiles.c, objfiles.h, ocd.c, osabi.c: Update.
* parse.c, ppc-bdm.c, ppc-linux-nat.c, ppc-sysv-tdep.c: Update.
* ppcnbsd-nat.c, ppcobsd-nat.c, printcmd.c, procfs.c: Update.
* regcache.c, reggroups.c, remote-e7000.c, remote-mips.c: Update.
* remote-rdp.c, remote-sds.c, remote-sim.c, remote-st.c: Update.
* remote-utils.c, remote.c, rs6000-nat.c, rs6000-tdep.c: Update.
* s390-nat.c, s390-tdep.c, sentinel-frame.c, serial.c: Update.
* sh-tdep.c, sh3-rom.c, sh64-tdep.c, shnbsd-nat.c: Update.
* solib-aix5.c, solib-svr4.c, solib.c, source.c: Update.
* sparc-nat.c, stabsread.c, stack.c, symfile.c, symtab.c: Update.
* symtab.h, target.c, tracepoint.c, ui-file.c, ui-out.c: Update.
* utils.c, valops.c, valprint.c, vax-nat.c, vaxbsd-nat.c: Update.
* win32-nat.c, xcoffread.c, xstormy16-tdep.c: Update.
* cli/cli-cmds.c, cli/cli-logging.c, cli/cli-script.c: Update.
* cli/cli-setshow.c, mi/mi-cmd-break.c, mi/mi-cmds.c: Update.
* mi/mi-console.c, mi/mi-getopt.c, mi/mi-out.c: Update.
* tui/tui-file.c, tui/tui-interp.c: Update.
2005-02-11 18:13:55 +00:00
|
|
|
|
perror_with_name (("ptrace"));
|
2004-09-25 12:32:01 +00:00
|
|
|
|
attach_flag = 1;
|
|
|
|
|
#else
|
2005-02-10 Andrew Cagney <cagney@gnu.org>
Mark up all error and warning messages.
* ada-lang.c, amd64-tdep.c, arch-utils.c, breakpoint.c: Update.
* bsd-kvm.c, bsd-uthread.c, coff-solib.h, coffread.c: Update.
* core-aout.c, core-regset.c, corefile.c, corelow.c: Update.
* cp-abi.c, cp-support.c, cp-valprint.c, cris-tdep.c: Update.
* dbxread.c, demangle.c, doublest.c, dsrec.c: Update.
* dve3900-rom.c, dwarf2expr.c, dwarf2loc.c: Update.
* dwarf2read.c, dwarfread.c, elfread.c, eval.c: Update.
* event-top.c, exec.c, expprint.c, f-lang.c: Update.
* f-typeprint.c, f-valprint.c, fbsd-nat.c, findvar.c: Update.
* frame.c, frv-linux-tdep.c, gcore.c, gdbtypes.c: Update.
* gnu-nat.c, gnu-v2-abi.c, gnu-v3-abi.c, go32-nat.c: Update.
* hpacc-abi.c, hppa-hpux-nat.c, hppa-hpux-tdep.c: Update.
* hppa-linux-nat.c, hppa-linux-tdep.c, hppa-tdep.c: Update.
* hpread.c, hpux-thread.c, i386-linux-nat.c: Update.
* i386-linux-tdep.c, i386-tdep.c, i386bsd-nat.c: Update.
* i386gnu-nat.c, i387-tdep.c, ia64-linux-nat.c: Update.
* ia64-tdep.c, inf-child.c, inf-ptrace.c, inf-ttrace.c: Update.
* infcall.c, infcmd.c, inflow.c, infptrace.c, infrun.c: Update.
* inftarg.c, interps.c, irix5-nat.c, jv-lang.c: Update.
* kod-cisco.c, kod.c, language.c, libunwind-frame.c: Update.
* linespec.c, linux-nat.c, linux-thread-db.c, m2-lang.c: Update.
* m32r-rom.c, m68hc11-tdep.c, m68k-tdep.c: Update.
* m68klinux-nat.c, macrocmd.c, macroexp.c, main.c: Update.
* maint.c, mdebugread.c, mem-break.c, memattr.c: Update.
* mips-linux-tdep.c, mips-tdep.c, mipsread.c, monitor.c: Update.
* nlmread.c, nto-procfs.c, objc-lang.c, objfiles.c: Update.
* observer.c, ocd.c, p-lang.c, p-typeprint.c: Update.
* p-valprint.c, pa64solib.c, parse.c, ppc-linux-tdep.c: Update.
* ppcnbsd-tdep.c, printcmd.c, procfs.c, remote-e7000.c: Update.
* remote-fileio.c, remote-m32r-sdi.c, remote-rdi.c: Update.
* remote-rdp.c, remote-sim.c, remote-st.c: Update.
* remote-utils.c, remote-utils.h, remote.c: Update.
* rom68k-rom.c, rs6000-nat.c, s390-tdep.c, scm-lang.c: Update.
* ser-e7kpc.c, ser-tcp.c, ser-unix.c, sh-tdep.c: Update.
* sh3-rom.c, shnbsd-tdep.c, sol-thread.c, solib-aix5.c: Update.
* solib-frv.c, solib-irix.c, solib-osf.c, solib-pa64.c: Update.
* solib-som.c, solib-sunos.c, solib-svr4.c, solib.c: Update.
* somread.c, somsolib.c, source.c, stabsread.c: Update.
* stack.c, std-regs.c, symfile-mem.c, symfile.c: Update.
* symmisc.c, symtab.c, target.c, thread.c, top.c: Update.
* tracepoint.c, trad-frame.c, typeprint.c, utils.c: Update.
* uw-thread.c, valarith.c, valops.c, valprint.c: Update.
* value.c, varobj.c, version.in, win32-nat.c, wince.c: Update.
* xcoffread.c, xcoffsolib.c, cli/cli-cmds.c: Update.
* cli/cli-decode.c, cli/cli-dump.c, cli/cli-logging.c: Update.
* cli/cli-script.c, cli/cli-setshow.c, mi/mi-cmd-break.c: Update.
* mi/mi-cmd-disas.c, mi/mi-cmd-env.c, mi/mi-cmd-file.c: Update.
* mi/mi-cmd-stack.c, mi/mi-cmd-var.c, mi/mi-getopt.c: Update.
* mi/mi-symbol-cmds.c, tui/tui-layout.c, tui/tui-stack.c: Update.
* tui/tui-win.c: Update.
2005-02-11 04:06:14 +00:00
|
|
|
|
error (_("This system does not support attaching to a process"));
|
2004-09-25 12:32:01 +00:00
|
|
|
|
#endif
|
2004-09-12 13:04:41 +00:00
|
|
|
|
|
2005-07-25 21:11:02 +00:00
|
|
|
|
#ifdef PT_GET_PROCESS_STATE
|
|
|
|
|
{
|
|
|
|
|
ptrace_event_t pe;
|
|
|
|
|
|
|
|
|
|
/* Set the initial event mask. */
|
|
|
|
|
memset (&pe, 0, sizeof pe);
|
|
|
|
|
pe.pe_set_event |= PTRACE_FORK;
|
|
|
|
|
if (ptrace (PT_SET_EVENT_MASK, pid,
|
|
|
|
|
(PTRACE_TYPE_ARG3)&pe, sizeof pe) == -1)
|
|
|
|
|
perror_with_name (("ptrace"));
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2004-09-12 13:04:41 +00:00
|
|
|
|
inferior_ptid = pid_to_ptid (pid);
|
|
|
|
|
push_target (ptrace_ops_hack);
|
2004-11-07 21:33:29 +00:00
|
|
|
|
|
|
|
|
|
/* Do this first, before anything has had a chance to query the
|
|
|
|
|
inferior's symbol table or similar. */
|
|
|
|
|
observer_notify_inferior_created (¤t_target, from_tty);
|
2004-09-12 13:04:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-07-25 20:42:29 +00:00
|
|
|
|
/* Detach from the inferior, optionally passing it the signal
|
|
|
|
|
specified ARGS. If FROM_TTY is non-zero, be chatty about it. */
|
2004-09-12 13:04:41 +00:00
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
inf_ptrace_detach (char *args, int from_tty)
|
|
|
|
|
{
|
2005-07-25 20:42:29 +00:00
|
|
|
|
pid_t pid = ptid_get_pid (inferior_ptid);
|
2004-09-25 12:32:01 +00:00
|
|
|
|
int sig = 0;
|
2004-09-12 13:04:41 +00:00
|
|
|
|
|
|
|
|
|
if (from_tty)
|
|
|
|
|
{
|
|
|
|
|
char *exec_file = get_exec_file (0);
|
|
|
|
|
if (exec_file == 0)
|
|
|
|
|
exec_file = "";
|
2005-02-11 Andrew Cagney <cagney@gnu.org>
Mark up some of printf_filtered and printf_unfiltered.
* ada-lang.c, annotate.c, arch-utils.c, breakpoint.c: Update.
* corelow.c, cp-namespace.c, cp-support.c, dcache.c: Update.
* demangle.c, dsrec.c, dwarf2read.c, dwarfread.c: Update.
* event-loop.c, event-top.c, exec.c, f-valprint.c: Update.
* gdbtypes.c, inf-loop.c, inf-ptrace.c, inf-ttrace.c: Update.
* infcmd.c, inflow.c, infrun.c, inftarg.c, language.c: Update.
* linespec.c, linux-nat.c, linux-thread-db.c, maint.c: Update.
* mdebugread.c, memattr.c, monitor.c, objc-lang.c: Update.
* ocd.c, osabi.c, printcmd.c, procfs.c, regcache.c: Update.
* remote.c, solib-som.c, solib.c, somsolib.c, source.c: Update.
* stack.c, symfile.c, symmisc.c, target.c, thread.c: Update.
* top.c, utils.c, valprint.c, value.c, cli/cli-cmds.c: Update.
* cli/cli-dump.c, cli/cli-logging.c, tui/tui-hooks.c: Update.
* tui/tui-regs.c, tui/tui-win.c: Update.
2005-02-12 00:39:24 +00:00
|
|
|
|
printf_unfiltered (_("Detaching from program: %s, %s\n"), exec_file,
|
2004-09-12 13:04:41 +00:00
|
|
|
|
target_pid_to_str (pid_to_ptid (pid)));
|
|
|
|
|
gdb_flush (gdb_stdout);
|
|
|
|
|
}
|
|
|
|
|
if (args)
|
2004-09-25 12:32:01 +00:00
|
|
|
|
sig = atoi (args);
|
2004-09-12 13:04:41 +00:00
|
|
|
|
|
2004-09-25 12:32:01 +00:00
|
|
|
|
#ifdef PT_DETACH
|
2005-07-25 20:42:29 +00:00
|
|
|
|
/* We'd better not have left any breakpoints in the program or it'll
|
|
|
|
|
die when it hits one. Alsno note that this may only work if we
|
|
|
|
|
previously attached to the inferior. It *might* work if we
|
|
|
|
|
started the process ourselves. */
|
2004-09-25 12:32:01 +00:00
|
|
|
|
errno = 0;
|
2005-07-25 20:42:29 +00:00
|
|
|
|
ptrace (PT_DETACH, pid, (PTRACE_TYPE_ARG3)1, sig);
|
2004-09-25 12:32:01 +00:00
|
|
|
|
if (errno != 0)
|
2005-02-11 Andrew Cagney <cagney@gnu.org>
Mark up error_no_arg, query, perror_with_name, complaint, and
internal_error.
* breakpoint.c, cp-abi.c, cp-namespace.c, cp-support.c: Update.
* cris-tdep.c, dbxread.c, dictionary.c, dsrec.c: Update.
* dummy-frame.c, dve3900-rom.c, dwarf2-frame.c, dwarf2expr.c: Update.
* dwarf2read.c, dwarfread.c, elfread.c, event-loop.c: Update.
* exceptions.c, exec.c, f-lang.c, findvar.c, fork-child.c: Update.
* frame-unwind.c, frame.c, frv-linux-tdep.c, frv-tdep.c: Update.
* gdb_assert.h, gdbarch.c, gdbtypes.c, gnu-nat.c: Update.
* go32-nat.c, hppa-tdep.c, hppabsd-nat.c, hpread.c: Update.
* i386-linux-nat.c, i386-nat.c, i386-tdep.c, i386bsd-nat.c: Update.
* i386fbsd-nat.c, inf-ptrace.c, inf-ttrace.c, infcall.c: Update.
* infcmd.c, inflow.c, infptrace.c, infrun.c, inftarg.c: Update.
* interps.c, language.c, linespec.c, linux-nat.c: Update.
* m32r-linux-nat.c, m68k-tdep.c, m68kbsd-nat.c: Update.
* m68klinux-nat.c, m88kbsd-nat.c, macroexp.c, macroscope.c: Update.
* macrotab.c, maint.c, mdebugread.c, memattr.c: Update.
* mips-linux-tdep.c, mips-tdep.c, mips64obsd-nat.c: Update.
* mipsnbsd-nat.c, mn10300-tdep.c, monitor.c, nto-procfs.c: Update.
* objc-lang.c, objfiles.c, objfiles.h, ocd.c, osabi.c: Update.
* parse.c, ppc-bdm.c, ppc-linux-nat.c, ppc-sysv-tdep.c: Update.
* ppcnbsd-nat.c, ppcobsd-nat.c, printcmd.c, procfs.c: Update.
* regcache.c, reggroups.c, remote-e7000.c, remote-mips.c: Update.
* remote-rdp.c, remote-sds.c, remote-sim.c, remote-st.c: Update.
* remote-utils.c, remote.c, rs6000-nat.c, rs6000-tdep.c: Update.
* s390-nat.c, s390-tdep.c, sentinel-frame.c, serial.c: Update.
* sh-tdep.c, sh3-rom.c, sh64-tdep.c, shnbsd-nat.c: Update.
* solib-aix5.c, solib-svr4.c, solib.c, source.c: Update.
* sparc-nat.c, stabsread.c, stack.c, symfile.c, symtab.c: Update.
* symtab.h, target.c, tracepoint.c, ui-file.c, ui-out.c: Update.
* utils.c, valops.c, valprint.c, vax-nat.c, vaxbsd-nat.c: Update.
* win32-nat.c, xcoffread.c, xstormy16-tdep.c: Update.
* cli/cli-cmds.c, cli/cli-logging.c, cli/cli-script.c: Update.
* cli/cli-setshow.c, mi/mi-cmd-break.c, mi/mi-cmds.c: Update.
* mi/mi-console.c, mi/mi-getopt.c, mi/mi-out.c: Update.
* tui/tui-file.c, tui/tui-interp.c: Update.
2005-02-11 18:13:55 +00:00
|
|
|
|
perror_with_name (("ptrace"));
|
2004-09-25 12:32:01 +00:00
|
|
|
|
attach_flag = 0;
|
|
|
|
|
#else
|
2005-02-10 Andrew Cagney <cagney@gnu.org>
Mark up all error and warning messages.
* ada-lang.c, amd64-tdep.c, arch-utils.c, breakpoint.c: Update.
* bsd-kvm.c, bsd-uthread.c, coff-solib.h, coffread.c: Update.
* core-aout.c, core-regset.c, corefile.c, corelow.c: Update.
* cp-abi.c, cp-support.c, cp-valprint.c, cris-tdep.c: Update.
* dbxread.c, demangle.c, doublest.c, dsrec.c: Update.
* dve3900-rom.c, dwarf2expr.c, dwarf2loc.c: Update.
* dwarf2read.c, dwarfread.c, elfread.c, eval.c: Update.
* event-top.c, exec.c, expprint.c, f-lang.c: Update.
* f-typeprint.c, f-valprint.c, fbsd-nat.c, findvar.c: Update.
* frame.c, frv-linux-tdep.c, gcore.c, gdbtypes.c: Update.
* gnu-nat.c, gnu-v2-abi.c, gnu-v3-abi.c, go32-nat.c: Update.
* hpacc-abi.c, hppa-hpux-nat.c, hppa-hpux-tdep.c: Update.
* hppa-linux-nat.c, hppa-linux-tdep.c, hppa-tdep.c: Update.
* hpread.c, hpux-thread.c, i386-linux-nat.c: Update.
* i386-linux-tdep.c, i386-tdep.c, i386bsd-nat.c: Update.
* i386gnu-nat.c, i387-tdep.c, ia64-linux-nat.c: Update.
* ia64-tdep.c, inf-child.c, inf-ptrace.c, inf-ttrace.c: Update.
* infcall.c, infcmd.c, inflow.c, infptrace.c, infrun.c: Update.
* inftarg.c, interps.c, irix5-nat.c, jv-lang.c: Update.
* kod-cisco.c, kod.c, language.c, libunwind-frame.c: Update.
* linespec.c, linux-nat.c, linux-thread-db.c, m2-lang.c: Update.
* m32r-rom.c, m68hc11-tdep.c, m68k-tdep.c: Update.
* m68klinux-nat.c, macrocmd.c, macroexp.c, main.c: Update.
* maint.c, mdebugread.c, mem-break.c, memattr.c: Update.
* mips-linux-tdep.c, mips-tdep.c, mipsread.c, monitor.c: Update.
* nlmread.c, nto-procfs.c, objc-lang.c, objfiles.c: Update.
* observer.c, ocd.c, p-lang.c, p-typeprint.c: Update.
* p-valprint.c, pa64solib.c, parse.c, ppc-linux-tdep.c: Update.
* ppcnbsd-tdep.c, printcmd.c, procfs.c, remote-e7000.c: Update.
* remote-fileio.c, remote-m32r-sdi.c, remote-rdi.c: Update.
* remote-rdp.c, remote-sim.c, remote-st.c: Update.
* remote-utils.c, remote-utils.h, remote.c: Update.
* rom68k-rom.c, rs6000-nat.c, s390-tdep.c, scm-lang.c: Update.
* ser-e7kpc.c, ser-tcp.c, ser-unix.c, sh-tdep.c: Update.
* sh3-rom.c, shnbsd-tdep.c, sol-thread.c, solib-aix5.c: Update.
* solib-frv.c, solib-irix.c, solib-osf.c, solib-pa64.c: Update.
* solib-som.c, solib-sunos.c, solib-svr4.c, solib.c: Update.
* somread.c, somsolib.c, source.c, stabsread.c: Update.
* stack.c, std-regs.c, symfile-mem.c, symfile.c: Update.
* symmisc.c, symtab.c, target.c, thread.c, top.c: Update.
* tracepoint.c, trad-frame.c, typeprint.c, utils.c: Update.
* uw-thread.c, valarith.c, valops.c, valprint.c: Update.
* value.c, varobj.c, version.in, win32-nat.c, wince.c: Update.
* xcoffread.c, xcoffsolib.c, cli/cli-cmds.c: Update.
* cli/cli-decode.c, cli/cli-dump.c, cli/cli-logging.c: Update.
* cli/cli-script.c, cli/cli-setshow.c, mi/mi-cmd-break.c: Update.
* mi/mi-cmd-disas.c, mi/mi-cmd-env.c, mi/mi-cmd-file.c: Update.
* mi/mi-cmd-stack.c, mi/mi-cmd-var.c, mi/mi-getopt.c: Update.
* mi/mi-symbol-cmds.c, tui/tui-layout.c, tui/tui-stack.c: Update.
* tui/tui-win.c: Update.
2005-02-11 04:06:14 +00:00
|
|
|
|
error (_("This system does not support detaching from a process"));
|
2004-09-25 12:32:01 +00:00
|
|
|
|
#endif
|
2004-09-12 13:04:41 +00:00
|
|
|
|
|
|
|
|
|
inferior_ptid = null_ptid;
|
|
|
|
|
unpush_target (ptrace_ops_hack);
|
|
|
|
|
}
|
|
|
|
|
|
2005-07-25 20:42:29 +00:00
|
|
|
|
/* Kill the inferior. */
|
|
|
|
|
|
2004-09-12 13:04:41 +00:00
|
|
|
|
static void
|
2005-07-25 20:42:29 +00:00
|
|
|
|
inf_ptrace_kill (void)
|
2004-09-12 13:04:41 +00:00
|
|
|
|
{
|
2005-07-25 20:42:29 +00:00
|
|
|
|
pid_t pid = ptid_get_pid (inferior_ptid);
|
* inf-ptrace.c: Reorder functions.
(inf_ptrace_open, inf_ptrace_reported_exec_events_per_call)
(inf_ptrace_can_run, inf_ptrace_post_attach): Removed.
(inf_ptrace_target): Don't set to_open,
to_reported_exec_events_per_call, to_can_run, to_post_attach,
to_stratum, to_has_all_memory, to_has_memory, to_has_stack,
to_has_registers, to_has_execution, to_magic. Reorder remaining
initializations.
2005-07-25 20:19:37 +00:00
|
|
|
|
int status;
|
|
|
|
|
|
|
|
|
|
if (pid == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
2005-07-25 20:42:29 +00:00
|
|
|
|
ptrace (PT_KILL, pid, (PTRACE_TYPE_ARG3)0, 0);
|
|
|
|
|
waitpid (pid, &status, 0);
|
|
|
|
|
|
* inf-ptrace.c: Reorder functions.
(inf_ptrace_open, inf_ptrace_reported_exec_events_per_call)
(inf_ptrace_can_run, inf_ptrace_post_attach): Removed.
(inf_ptrace_target): Don't set to_open,
to_reported_exec_events_per_call, to_can_run, to_post_attach,
to_stratum, to_has_all_memory, to_has_memory, to_has_stack,
to_has_registers, to_has_execution, to_magic. Reorder remaining
initializations.
2005-07-25 20:19:37 +00:00
|
|
|
|
target_mourn_inferior ();
|
2004-09-12 13:04:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-07-25 20:42:29 +00:00
|
|
|
|
/* Stop the inferior. */
|
* inf-ptrace.c: Reorder functions.
(inf_ptrace_open, inf_ptrace_reported_exec_events_per_call)
(inf_ptrace_can_run, inf_ptrace_post_attach): Removed.
(inf_ptrace_target): Don't set to_open,
to_reported_exec_events_per_call, to_can_run, to_post_attach,
to_stratum, to_has_all_memory, to_has_memory, to_has_stack,
to_has_registers, to_has_execution, to_magic. Reorder remaining
initializations.
2005-07-25 20:19:37 +00:00
|
|
|
|
|
2004-09-12 13:04:41 +00:00
|
|
|
|
static void
|
* inf-ptrace.c: Reorder functions.
(inf_ptrace_open, inf_ptrace_reported_exec_events_per_call)
(inf_ptrace_can_run, inf_ptrace_post_attach): Removed.
(inf_ptrace_target): Don't set to_open,
to_reported_exec_events_per_call, to_can_run, to_post_attach,
to_stratum, to_has_all_memory, to_has_memory, to_has_stack,
to_has_registers, to_has_execution, to_magic. Reorder remaining
initializations.
2005-07-25 20:19:37 +00:00
|
|
|
|
inf_ptrace_stop (void)
|
2004-09-12 13:04:41 +00:00
|
|
|
|
{
|
2005-07-25 20:42:29 +00:00
|
|
|
|
/* Send a SIGINT to the process group. This acts just like the user
|
|
|
|
|
typed a ^C on the controlling terminal. Note that using a
|
|
|
|
|
negative process number in kill() is a System V-ism. The proper
|
|
|
|
|
BSD interface is killpg(). However, all modern BSDs support the
|
|
|
|
|
System V interface too. */
|
* inf-ptrace.c: Reorder functions.
(inf_ptrace_open, inf_ptrace_reported_exec_events_per_call)
(inf_ptrace_can_run, inf_ptrace_post_attach): Removed.
(inf_ptrace_target): Don't set to_open,
to_reported_exec_events_per_call, to_can_run, to_post_attach,
to_stratum, to_has_all_memory, to_has_memory, to_has_stack,
to_has_registers, to_has_execution, to_magic. Reorder remaining
initializations.
2005-07-25 20:19:37 +00:00
|
|
|
|
kill (-inferior_process_group, SIGINT);
|
2004-09-12 13:04:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-07-25 20:42:29 +00:00
|
|
|
|
/* Resume execution of thread PTID, or all threads if PTID is -1. If
|
|
|
|
|
STEP is nonzero, single-step it. If SIGNAL is nonzero, give it
|
|
|
|
|
that signal. */
|
2004-09-12 13:04:41 +00:00
|
|
|
|
|
|
|
|
|
static void
|
* inf-ptrace.c: Reorder functions.
(inf_ptrace_open, inf_ptrace_reported_exec_events_per_call)
(inf_ptrace_can_run, inf_ptrace_post_attach): Removed.
(inf_ptrace_target): Don't set to_open,
to_reported_exec_events_per_call, to_can_run, to_post_attach,
to_stratum, to_has_all_memory, to_has_memory, to_has_stack,
to_has_registers, to_has_execution, to_magic. Reorder remaining
initializations.
2005-07-25 20:19:37 +00:00
|
|
|
|
inf_ptrace_resume (ptid_t ptid, int step, enum target_signal signal)
|
2004-09-12 13:04:41 +00:00
|
|
|
|
{
|
2005-07-25 20:42:29 +00:00
|
|
|
|
pid_t pid = ptid_get_pid (ptid);
|
* inf-ptrace.c: Reorder functions.
(inf_ptrace_open, inf_ptrace_reported_exec_events_per_call)
(inf_ptrace_can_run, inf_ptrace_post_attach): Removed.
(inf_ptrace_target): Don't set to_open,
to_reported_exec_events_per_call, to_can_run, to_post_attach,
to_stratum, to_has_all_memory, to_has_memory, to_has_stack,
to_has_registers, to_has_execution, to_magic. Reorder remaining
initializations.
2005-07-25 20:19:37 +00:00
|
|
|
|
int request = PT_CONTINUE;
|
|
|
|
|
|
|
|
|
|
if (pid == -1)
|
2005-07-25 20:42:29 +00:00
|
|
|
|
/* Resume all threads. Traditionally ptrace() only supports
|
|
|
|
|
single-threaded processes, so simply resume the inferior. */
|
|
|
|
|
pid = ptid_get_pid (inferior_ptid);
|
* inf-ptrace.c: Reorder functions.
(inf_ptrace_open, inf_ptrace_reported_exec_events_per_call)
(inf_ptrace_can_run, inf_ptrace_post_attach): Removed.
(inf_ptrace_target): Don't set to_open,
to_reported_exec_events_per_call, to_can_run, to_post_attach,
to_stratum, to_has_all_memory, to_has_memory, to_has_stack,
to_has_registers, to_has_execution, to_magic. Reorder remaining
initializations.
2005-07-25 20:19:37 +00:00
|
|
|
|
|
|
|
|
|
if (step)
|
|
|
|
|
{
|
|
|
|
|
/* If this system does not support PT_STEP, a higher level
|
|
|
|
|
function will have called single_step() to transmute the step
|
|
|
|
|
request into a continue request (by setting breakpoints on
|
|
|
|
|
all possible successor instructions), so we don't have to
|
|
|
|
|
worry about that here. */
|
|
|
|
|
request = PT_STEP;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* An address of (PTRACE_TYPE_ARG3)1 tells ptrace to continue from
|
|
|
|
|
where it was. If GDB wanted it to start some other way, we have
|
2005-07-25 20:42:29 +00:00
|
|
|
|
already written a new program counter value to the child. */
|
* inf-ptrace.c: Reorder functions.
(inf_ptrace_open, inf_ptrace_reported_exec_events_per_call)
(inf_ptrace_can_run, inf_ptrace_post_attach): Removed.
(inf_ptrace_target): Don't set to_open,
to_reported_exec_events_per_call, to_can_run, to_post_attach,
to_stratum, to_has_all_memory, to_has_memory, to_has_stack,
to_has_registers, to_has_execution, to_magic. Reorder remaining
initializations.
2005-07-25 20:19:37 +00:00
|
|
|
|
errno = 0;
|
2005-07-25 20:42:29 +00:00
|
|
|
|
ptrace (request, pid, (PTRACE_TYPE_ARG3)1, target_signal_to_host (signal));
|
* inf-ptrace.c: Reorder functions.
(inf_ptrace_open, inf_ptrace_reported_exec_events_per_call)
(inf_ptrace_can_run, inf_ptrace_post_attach): Removed.
(inf_ptrace_target): Don't set to_open,
to_reported_exec_events_per_call, to_can_run, to_post_attach,
to_stratum, to_has_all_memory, to_has_memory, to_has_stack,
to_has_registers, to_has_execution, to_magic. Reorder remaining
initializations.
2005-07-25 20:19:37 +00:00
|
|
|
|
if (errno != 0)
|
|
|
|
|
perror_with_name (("ptrace"));
|
2004-09-12 13:04:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-07-25 20:42:29 +00:00
|
|
|
|
/* Wait for the child specified by PTID to do something. Return the
|
|
|
|
|
process ID of the child, or MINUS_ONE_PTID in case of error; store
|
|
|
|
|
the status in *OURSTATUS. */
|
2004-09-12 13:04:41 +00:00
|
|
|
|
|
* inf-ptrace.c: Reorder functions.
(inf_ptrace_open, inf_ptrace_reported_exec_events_per_call)
(inf_ptrace_can_run, inf_ptrace_post_attach): Removed.
(inf_ptrace_target): Don't set to_open,
to_reported_exec_events_per_call, to_can_run, to_post_attach,
to_stratum, to_has_all_memory, to_has_memory, to_has_stack,
to_has_registers, to_has_execution, to_magic. Reorder remaining
initializations.
2005-07-25 20:19:37 +00:00
|
|
|
|
static ptid_t
|
|
|
|
|
inf_ptrace_wait (ptid_t ptid, struct target_waitstatus *ourstatus)
|
2004-09-12 13:04:41 +00:00
|
|
|
|
{
|
2005-07-25 20:42:29 +00:00
|
|
|
|
pid_t pid;
|
|
|
|
|
int status, save_errno;
|
2004-09-12 13:04:41 +00:00
|
|
|
|
|
* inf-ptrace.c: Reorder functions.
(inf_ptrace_open, inf_ptrace_reported_exec_events_per_call)
(inf_ptrace_can_run, inf_ptrace_post_attach): Removed.
(inf_ptrace_target): Don't set to_open,
to_reported_exec_events_per_call, to_can_run, to_post_attach,
to_stratum, to_has_all_memory, to_has_memory, to_has_stack,
to_has_registers, to_has_execution, to_magic. Reorder remaining
initializations.
2005-07-25 20:19:37 +00:00
|
|
|
|
do
|
|
|
|
|
{
|
2005-07-25 20:42:29 +00:00
|
|
|
|
set_sigint_trap ();
|
* inf-ptrace.c: Reorder functions.
(inf_ptrace_open, inf_ptrace_reported_exec_events_per_call)
(inf_ptrace_can_run, inf_ptrace_post_attach): Removed.
(inf_ptrace_target): Don't set to_open,
to_reported_exec_events_per_call, to_can_run, to_post_attach,
to_stratum, to_has_all_memory, to_has_memory, to_has_stack,
to_has_registers, to_has_execution, to_magic. Reorder remaining
initializations.
2005-07-25 20:19:37 +00:00
|
|
|
|
set_sigio_trap ();
|
2004-09-12 13:04:41 +00:00
|
|
|
|
|
2005-07-25 20:42:29 +00:00
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
pid = waitpid (ptid_get_pid (ptid), &status, 0);
|
|
|
|
|
save_errno = errno;
|
|
|
|
|
}
|
|
|
|
|
while (pid == -1 && errno == EINTR);
|
2004-09-12 13:04:41 +00:00
|
|
|
|
|
* inf-ptrace.c: Reorder functions.
(inf_ptrace_open, inf_ptrace_reported_exec_events_per_call)
(inf_ptrace_can_run, inf_ptrace_post_attach): Removed.
(inf_ptrace_target): Don't set to_open,
to_reported_exec_events_per_call, to_can_run, to_post_attach,
to_stratum, to_has_all_memory, to_has_memory, to_has_stack,
to_has_registers, to_has_execution, to_magic. Reorder remaining
initializations.
2005-07-25 20:19:37 +00:00
|
|
|
|
clear_sigio_trap ();
|
|
|
|
|
clear_sigint_trap ();
|
2004-09-12 13:04:41 +00:00
|
|
|
|
|
* inf-ptrace.c: Reorder functions.
(inf_ptrace_open, inf_ptrace_reported_exec_events_per_call)
(inf_ptrace_can_run, inf_ptrace_post_attach): Removed.
(inf_ptrace_target): Don't set to_open,
to_reported_exec_events_per_call, to_can_run, to_post_attach,
to_stratum, to_has_all_memory, to_has_memory, to_has_stack,
to_has_registers, to_has_execution, to_magic. Reorder remaining
initializations.
2005-07-25 20:19:37 +00:00
|
|
|
|
if (pid == -1)
|
|
|
|
|
{
|
|
|
|
|
fprintf_unfiltered (gdb_stderr,
|
2005-07-25 20:42:29 +00:00
|
|
|
|
_("Child process unexpectedly missing: %s.\n"),
|
* inf-ptrace.c: Reorder functions.
(inf_ptrace_open, inf_ptrace_reported_exec_events_per_call)
(inf_ptrace_can_run, inf_ptrace_post_attach): Removed.
(inf_ptrace_target): Don't set to_open,
to_reported_exec_events_per_call, to_can_run, to_post_attach,
to_stratum, to_has_all_memory, to_has_memory, to_has_stack,
to_has_registers, to_has_execution, to_magic. Reorder remaining
initializations.
2005-07-25 20:19:37 +00:00
|
|
|
|
safe_strerror (save_errno));
|
|
|
|
|
|
|
|
|
|
/* Claim it exited with unknown signal. */
|
|
|
|
|
ourstatus->kind = TARGET_WAITKIND_SIGNALLED;
|
|
|
|
|
ourstatus->value.sig = TARGET_SIGNAL_UNKNOWN;
|
2005-07-25 20:42:29 +00:00
|
|
|
|
return minus_one_ptid;
|
* inf-ptrace.c: Reorder functions.
(inf_ptrace_open, inf_ptrace_reported_exec_events_per_call)
(inf_ptrace_can_run, inf_ptrace_post_attach): Removed.
(inf_ptrace_target): Don't set to_open,
to_reported_exec_events_per_call, to_can_run, to_post_attach,
to_stratum, to_has_all_memory, to_has_memory, to_has_stack,
to_has_registers, to_has_execution, to_magic. Reorder remaining
initializations.
2005-07-25 20:19:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-07-25 20:42:29 +00:00
|
|
|
|
/* Ignore terminated detached child processes. */
|
|
|
|
|
if (!WIFSTOPPED (status) && pid != ptid_get_pid (inferior_ptid))
|
|
|
|
|
pid = -1;
|
* inf-ptrace.c: Reorder functions.
(inf_ptrace_open, inf_ptrace_reported_exec_events_per_call)
(inf_ptrace_can_run, inf_ptrace_post_attach): Removed.
(inf_ptrace_target): Don't set to_open,
to_reported_exec_events_per_call, to_can_run, to_post_attach,
to_stratum, to_has_all_memory, to_has_memory, to_has_stack,
to_has_registers, to_has_execution, to_magic. Reorder remaining
initializations.
2005-07-25 20:19:37 +00:00
|
|
|
|
}
|
2005-07-25 20:42:29 +00:00
|
|
|
|
while (pid == -1);
|
* inf-ptrace.c: Reorder functions.
(inf_ptrace_open, inf_ptrace_reported_exec_events_per_call)
(inf_ptrace_can_run, inf_ptrace_post_attach): Removed.
(inf_ptrace_target): Don't set to_open,
to_reported_exec_events_per_call, to_can_run, to_post_attach,
to_stratum, to_has_all_memory, to_has_memory, to_has_stack,
to_has_registers, to_has_execution, to_magic. Reorder remaining
initializations.
2005-07-25 20:19:37 +00:00
|
|
|
|
|
2005-07-25 21:11:02 +00:00
|
|
|
|
#ifdef PT_GET_PROCESS_STATE
|
|
|
|
|
if (WIFSTOPPED (status))
|
|
|
|
|
{
|
|
|
|
|
ptrace_state_t pe;
|
|
|
|
|
pid_t fpid;
|
|
|
|
|
|
|
|
|
|
if (ptrace (PT_GET_PROCESS_STATE, pid,
|
|
|
|
|
(PTRACE_TYPE_ARG3)&pe, sizeof pe) == -1)
|
|
|
|
|
perror_with_name (("ptrace"));
|
|
|
|
|
|
|
|
|
|
switch (pe.pe_report_event)
|
|
|
|
|
{
|
|
|
|
|
case PTRACE_FORK:
|
|
|
|
|
ourstatus->kind = TARGET_WAITKIND_FORKED;
|
|
|
|
|
ourstatus->value.related_pid = pe.pe_other_pid;
|
|
|
|
|
|
|
|
|
|
/* Make sure the other end of the fork is stopped too. */
|
|
|
|
|
fpid = waitpid (pe.pe_other_pid, &status, 0);
|
|
|
|
|
if (fpid == -1)
|
|
|
|
|
perror_with_name (("waitpid"));
|
|
|
|
|
|
|
|
|
|
if (ptrace (PT_GET_PROCESS_STATE, fpid,
|
|
|
|
|
(PTRACE_TYPE_ARG3)&pe, sizeof pe) == -1)
|
|
|
|
|
perror_with_name (("ptrace"));
|
|
|
|
|
|
|
|
|
|
gdb_assert (pe.pe_report_event == PTRACE_FORK);
|
|
|
|
|
gdb_assert (pe.pe_other_pid == pid);
|
|
|
|
|
if (fpid == ptid_get_pid (inferior_ptid))
|
|
|
|
|
{
|
|
|
|
|
ourstatus->value.related_pid = pe.pe_other_pid;
|
|
|
|
|
return pid_to_ptid (fpid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return pid_to_ptid (pid);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
* inf-ptrace.c: Reorder functions.
(inf_ptrace_open, inf_ptrace_reported_exec_events_per_call)
(inf_ptrace_can_run, inf_ptrace_post_attach): Removed.
(inf_ptrace_target): Don't set to_open,
to_reported_exec_events_per_call, to_can_run, to_post_attach,
to_stratum, to_has_all_memory, to_has_memory, to_has_stack,
to_has_registers, to_has_execution, to_magic. Reorder remaining
initializations.
2005-07-25 20:19:37 +00:00
|
|
|
|
store_waitstatus (ourstatus, status);
|
|
|
|
|
return pid_to_ptid (pid);
|
2004-09-12 13:04:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-07-25 20:42:29 +00:00
|
|
|
|
/* Attempt a transfer all LEN bytes starting at OFFSET between the
|
|
|
|
|
inferior's OBJECT:ANNEX space and GDB's READBUF/WRITEBUF buffer.
|
|
|
|
|
Return the number of bytes actually transferred. */
|
2004-09-12 13:04:41 +00:00
|
|
|
|
|
|
|
|
|
static LONGEST
|
|
|
|
|
inf_ptrace_xfer_partial (struct target_ops *ops, enum target_object object,
|
2005-05-16 16:36:24 +00:00
|
|
|
|
const char *annex, gdb_byte *readbuf,
|
|
|
|
|
const gdb_byte *writebuf,
|
|
|
|
|
ULONGEST offset, LONGEST len)
|
2004-09-12 13:04:41 +00:00
|
|
|
|
{
|
2005-07-25 20:42:29 +00:00
|
|
|
|
pid_t pid = ptid_get_pid (inferior_ptid);
|
|
|
|
|
|
2004-09-12 13:04:41 +00:00
|
|
|
|
switch (object)
|
|
|
|
|
{
|
|
|
|
|
case TARGET_OBJECT_MEMORY:
|
2004-09-30 15:47:30 +00:00
|
|
|
|
#ifdef PT_IO
|
|
|
|
|
/* OpenBSD 3.1, NetBSD 1.6 and FreeBSD 5.0 have a new PT_IO
|
|
|
|
|
request that promises to be much more efficient in reading
|
|
|
|
|
and writing data in the traced process's address space. */
|
|
|
|
|
{
|
|
|
|
|
struct ptrace_io_desc piod;
|
2005-07-25 20:42:29 +00:00
|
|
|
|
|
2004-09-30 15:47:30 +00:00
|
|
|
|
/* NOTE: We assume that there are no distinct address spaces
|
|
|
|
|
for instruction and data. */
|
|
|
|
|
piod.piod_op = writebuf ? PIOD_WRITE_D : PIOD_READ_D;
|
|
|
|
|
piod.piod_addr = writebuf ? (void *) writebuf : readbuf;
|
|
|
|
|
piod.piod_offs = (void *) (long) offset;
|
|
|
|
|
piod.piod_len = len;
|
|
|
|
|
|
|
|
|
|
errno = 0;
|
2005-07-25 20:42:29 +00:00
|
|
|
|
if (ptrace (PT_IO, pid, (caddr_t)&piod, 0) == 0)
|
2004-09-30 15:47:30 +00:00
|
|
|
|
/* Return the actual number of bytes read or written. */
|
|
|
|
|
return piod.piod_len;
|
|
|
|
|
/* If the PT_IO request is somehow not supported, fallback on
|
|
|
|
|
using PT_WRITE_D/PT_READ_D. Otherwise we will return zero
|
|
|
|
|
to indicate failure. */
|
|
|
|
|
if (errno != EINVAL)
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
{
|
|
|
|
|
union
|
|
|
|
|
{
|
|
|
|
|
PTRACE_TYPE_RET word;
|
2005-07-25 20:42:29 +00:00
|
|
|
|
gdb_byte byte[sizeof (PTRACE_TYPE_RET)];
|
2004-09-30 15:47:30 +00:00
|
|
|
|
} buffer;
|
|
|
|
|
ULONGEST rounded_offset;
|
|
|
|
|
LONGEST partial_len;
|
2005-07-25 20:42:29 +00:00
|
|
|
|
|
2004-10-01 16:12:26 +00:00
|
|
|
|
/* Round the start offset down to the next long word
|
|
|
|
|
boundary. */
|
2004-09-30 15:47:30 +00:00
|
|
|
|
rounded_offset = offset & -(ULONGEST) sizeof (PTRACE_TYPE_RET);
|
2005-07-25 20:42:29 +00:00
|
|
|
|
|
2004-10-01 16:12:26 +00:00
|
|
|
|
/* Since ptrace will transfer a single word starting at that
|
|
|
|
|
rounded_offset the partial_len needs to be adjusted down to
|
|
|
|
|
that (remember this function only does a single transfer).
|
|
|
|
|
Should the required length be even less, adjust it down
|
|
|
|
|
again. */
|
|
|
|
|
partial_len = (rounded_offset + sizeof (PTRACE_TYPE_RET)) - offset;
|
|
|
|
|
if (partial_len > len)
|
2004-09-30 15:47:30 +00:00
|
|
|
|
partial_len = len;
|
2005-07-25 20:42:29 +00:00
|
|
|
|
|
2004-09-30 15:47:30 +00:00
|
|
|
|
if (writebuf)
|
|
|
|
|
{
|
2004-10-01 16:12:26 +00:00
|
|
|
|
/* If OFFSET:PARTIAL_LEN is smaller than
|
|
|
|
|
ROUNDED_OFFSET:WORDSIZE then a read/modify write will
|
|
|
|
|
be needed. Read in the entire word. */
|
2004-09-30 15:47:30 +00:00
|
|
|
|
if (rounded_offset < offset
|
2004-10-01 16:12:26 +00:00
|
|
|
|
|| (offset + partial_len
|
|
|
|
|
< rounded_offset + sizeof (PTRACE_TYPE_RET)))
|
2004-09-30 15:47:30 +00:00
|
|
|
|
/* Need part of initial word -- fetch it. */
|
2005-07-25 20:42:29 +00:00
|
|
|
|
buffer.word = ptrace (PT_READ_I, pid,
|
|
|
|
|
(PTRACE_TYPE_ARG3)(long)rounded_offset, 0);
|
|
|
|
|
|
2004-09-30 15:47:30 +00:00
|
|
|
|
/* Copy data to be written over corresponding part of
|
|
|
|
|
buffer. */
|
2004-11-20 17:03:38 +00:00
|
|
|
|
memcpy (buffer.byte + (offset - rounded_offset),
|
|
|
|
|
writebuf, partial_len);
|
2005-07-25 20:42:29 +00:00
|
|
|
|
|
2004-09-30 15:47:30 +00:00
|
|
|
|
errno = 0;
|
2005-07-25 20:42:29 +00:00
|
|
|
|
ptrace (PT_WRITE_D, pid,
|
|
|
|
|
(PTRACE_TYPE_ARG3)(long)rounded_offset, buffer.word);
|
2004-09-30 15:47:30 +00:00
|
|
|
|
if (errno)
|
|
|
|
|
{
|
|
|
|
|
/* Using the appropriate one (I or D) is necessary for
|
|
|
|
|
Gould NP1, at least. */
|
|
|
|
|
errno = 0;
|
2005-07-25 20:42:29 +00:00
|
|
|
|
ptrace (PT_WRITE_I, pid,
|
|
|
|
|
(PTRACE_TYPE_ARG3)(long)rounded_offset, buffer.word);
|
2004-09-30 15:47:30 +00:00
|
|
|
|
if (errno)
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2005-07-25 20:42:29 +00:00
|
|
|
|
|
2004-09-30 15:47:30 +00:00
|
|
|
|
if (readbuf)
|
|
|
|
|
{
|
|
|
|
|
errno = 0;
|
2005-07-25 20:42:29 +00:00
|
|
|
|
buffer.word = ptrace (PT_READ_I, pid,
|
|
|
|
|
(PTRACE_TYPE_ARG3)(long)rounded_offset, 0);
|
2004-09-30 15:47:30 +00:00
|
|
|
|
if (errno)
|
|
|
|
|
return 0;
|
|
|
|
|
/* Copy appropriate bytes out of the buffer. */
|
|
|
|
|
memcpy (readbuf, buffer.byte + (offset - rounded_offset),
|
|
|
|
|
partial_len);
|
|
|
|
|
}
|
2005-07-25 20:42:29 +00:00
|
|
|
|
|
2004-09-30 15:47:30 +00:00
|
|
|
|
return partial_len;
|
|
|
|
|
}
|
2004-09-12 13:04:41 +00:00
|
|
|
|
|
|
|
|
|
case TARGET_OBJECT_UNWIND_TABLE:
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
case TARGET_OBJECT_AUXV:
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
case TARGET_OBJECT_WCOOKIE:
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-07-25 20:42:29 +00:00
|
|
|
|
/* Return non-zero if the thread specified by PTID is alive. */
|
* inf-ptrace.c: Reorder functions.
(inf_ptrace_open, inf_ptrace_reported_exec_events_per_call)
(inf_ptrace_can_run, inf_ptrace_post_attach): Removed.
(inf_ptrace_target): Don't set to_open,
to_reported_exec_events_per_call, to_can_run, to_post_attach,
to_stratum, to_has_all_memory, to_has_memory, to_has_stack,
to_has_registers, to_has_execution, to_magic. Reorder remaining
initializations.
2005-07-25 20:19:37 +00:00
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
inf_ptrace_thread_alive (ptid_t ptid)
|
|
|
|
|
{
|
2005-07-25 20:42:29 +00:00
|
|
|
|
/* ??? Is kill the right way to do this? */
|
|
|
|
|
return (kill (ptid_get_pid (ptid), 0) != -1);
|
* inf-ptrace.c: Reorder functions.
(inf_ptrace_open, inf_ptrace_reported_exec_events_per_call)
(inf_ptrace_can_run, inf_ptrace_post_attach): Removed.
(inf_ptrace_target): Don't set to_open,
to_reported_exec_events_per_call, to_can_run, to_post_attach,
to_stratum, to_has_all_memory, to_has_memory, to_has_stack,
to_has_registers, to_has_execution, to_magic. Reorder remaining
initializations.
2005-07-25 20:19:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Print status information about what we're accessing. */
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
inf_ptrace_files_info (struct target_ops *ignore)
|
|
|
|
|
{
|
2005-07-25 20:42:29 +00:00
|
|
|
|
printf_filtered (_("\tUsing the running image of %s %s.\n"),
|
|
|
|
|
attach_flag ? "attached" : "child",
|
|
|
|
|
target_pid_to_str (inferior_ptid));
|
2004-09-12 13:04:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-01-10 20:36:38 +00:00
|
|
|
|
/* Create a prototype ptrace target. The client can override it with
|
|
|
|
|
local methods. */
|
|
|
|
|
|
2004-09-12 13:04:41 +00:00
|
|
|
|
struct target_ops *
|
|
|
|
|
inf_ptrace_target (void)
|
|
|
|
|
{
|
|
|
|
|
struct target_ops *t = inf_child_target ();
|
2005-01-10 20:36:38 +00:00
|
|
|
|
|
2004-09-12 13:04:41 +00:00
|
|
|
|
t->to_attach = inf_ptrace_attach;
|
|
|
|
|
t->to_detach = inf_ptrace_detach;
|
|
|
|
|
t->to_resume = inf_ptrace_resume;
|
|
|
|
|
t->to_wait = inf_ptrace_wait;
|
|
|
|
|
t->to_files_info = inf_ptrace_files_info;
|
2005-07-25 20:42:29 +00:00
|
|
|
|
t->to_kill = inf_ptrace_kill;
|
2004-09-12 13:04:41 +00:00
|
|
|
|
t->to_create_inferior = inf_ptrace_create_inferior;
|
2005-07-25 21:11:02 +00:00
|
|
|
|
#ifdef PT_GET_PROCESS_STATE
|
|
|
|
|
t->to_follow_fork = inf_ptrace_follow_fork;
|
|
|
|
|
#endif
|
2004-09-12 13:04:41 +00:00
|
|
|
|
t->to_mourn_inferior = inf_ptrace_mourn_inferior;
|
|
|
|
|
t->to_thread_alive = inf_ptrace_thread_alive;
|
2005-07-25 20:42:29 +00:00
|
|
|
|
t->to_pid_to_str = normal_pid_to_str;
|
2004-09-12 13:04:41 +00:00
|
|
|
|
t->to_stop = inf_ptrace_stop;
|
* inf-ptrace.c: Reorder functions.
(inf_ptrace_open, inf_ptrace_reported_exec_events_per_call)
(inf_ptrace_can_run, inf_ptrace_post_attach): Removed.
(inf_ptrace_target): Don't set to_open,
to_reported_exec_events_per_call, to_can_run, to_post_attach,
to_stratum, to_has_all_memory, to_has_memory, to_has_stack,
to_has_registers, to_has_execution, to_magic. Reorder remaining
initializations.
2005-07-25 20:19:37 +00:00
|
|
|
|
t->to_xfer_partial = inf_ptrace_xfer_partial;
|
2005-01-10 20:36:38 +00:00
|
|
|
|
|
* inf-ptrace.c: Reorder functions.
(inf_ptrace_open, inf_ptrace_reported_exec_events_per_call)
(inf_ptrace_can_run, inf_ptrace_post_attach): Removed.
(inf_ptrace_target): Don't set to_open,
to_reported_exec_events_per_call, to_can_run, to_post_attach,
to_stratum, to_has_all_memory, to_has_memory, to_has_stack,
to_has_registers, to_has_execution, to_magic. Reorder remaining
initializations.
2005-07-25 20:19:37 +00:00
|
|
|
|
ptrace_ops_hack = t;
|
2005-01-10 20:36:38 +00:00
|
|
|
|
return t;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-07-25 20:42:29 +00:00
|
|
|
|
/* Pointer to a function that returns the offset within the user area
|
2005-01-10 20:36:38 +00:00
|
|
|
|
where a particular register is stored. */
|
|
|
|
|
static CORE_ADDR (*inf_ptrace_register_u_offset)(int);
|
|
|
|
|
|
|
|
|
|
/* Fetch register REGNUM from the inferior. */
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
inf_ptrace_fetch_register (int regnum)
|
|
|
|
|
{
|
|
|
|
|
CORE_ADDR addr;
|
|
|
|
|
size_t size;
|
|
|
|
|
PTRACE_TYPE_RET *buf;
|
|
|
|
|
int pid, i;
|
|
|
|
|
|
|
|
|
|
/* Cater for systems like GNU/Linux, that implement threads as
|
|
|
|
|
seperate processes. */
|
|
|
|
|
pid = ptid_get_lwp (inferior_ptid);
|
|
|
|
|
if (pid == 0)
|
|
|
|
|
pid = ptid_get_pid (inferior_ptid);
|
|
|
|
|
|
|
|
|
|
/* This isn't really an address, but ptrace thinks of it as one. */
|
|
|
|
|
addr = inf_ptrace_register_u_offset (regnum);
|
|
|
|
|
size = register_size (current_gdbarch, regnum);
|
|
|
|
|
|
|
|
|
|
gdb_assert ((size % sizeof (PTRACE_TYPE_RET)) == 0);
|
|
|
|
|
buf = alloca (size);
|
|
|
|
|
|
|
|
|
|
/* Read the register contents from the inferior a chuck at the time. */
|
|
|
|
|
for (i = 0; i < size / sizeof (PTRACE_TYPE_RET); i++)
|
|
|
|
|
{
|
|
|
|
|
errno = 0;
|
2005-07-25 20:42:29 +00:00
|
|
|
|
buf[i] = ptrace (PT_READ_U, pid, (PTRACE_TYPE_ARG3)addr, 0);
|
2005-01-10 20:36:38 +00:00
|
|
|
|
if (errno != 0)
|
2005-07-25 20:42:29 +00:00
|
|
|
|
error (_("Couldn't read register %s (#%d): %s."),
|
|
|
|
|
REGISTER_NAME (regnum), regnum, safe_strerror (errno));
|
2005-01-10 20:36:38 +00:00
|
|
|
|
|
|
|
|
|
addr += sizeof (PTRACE_TYPE_RET);
|
|
|
|
|
}
|
|
|
|
|
regcache_raw_supply (current_regcache, regnum, buf);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Fetch register REGNUM from the inferior. If REGNUM is -1, do this
|
|
|
|
|
for all registers. */
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
inf_ptrace_fetch_registers (int regnum)
|
|
|
|
|
{
|
|
|
|
|
if (regnum == -1)
|
|
|
|
|
for (regnum = 0; regnum < NUM_REGS; regnum++)
|
|
|
|
|
inf_ptrace_fetch_register (regnum);
|
|
|
|
|
else
|
|
|
|
|
inf_ptrace_fetch_register (regnum);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Store register REGNUM into the inferior. */
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
inf_ptrace_store_register (int regnum)
|
|
|
|
|
{
|
|
|
|
|
CORE_ADDR addr;
|
|
|
|
|
size_t size;
|
|
|
|
|
PTRACE_TYPE_RET *buf;
|
|
|
|
|
int pid, i;
|
|
|
|
|
|
|
|
|
|
/* Cater for systems like GNU/Linux, that implement threads as
|
|
|
|
|
seperate processes. */
|
|
|
|
|
pid = ptid_get_lwp (inferior_ptid);
|
|
|
|
|
if (pid == 0)
|
|
|
|
|
pid = ptid_get_pid (inferior_ptid);
|
|
|
|
|
|
|
|
|
|
/* This isn't really an address, but ptrace thinks of it as one. */
|
|
|
|
|
addr = inf_ptrace_register_u_offset (regnum);
|
|
|
|
|
size = register_size (current_gdbarch, regnum);
|
|
|
|
|
|
|
|
|
|
gdb_assert ((size % sizeof (PTRACE_TYPE_RET)) == 0);
|
|
|
|
|
buf = alloca (size);
|
|
|
|
|
|
|
|
|
|
/* Write the register contents into the inferior a chunk at the time. */
|
|
|
|
|
regcache_raw_collect (current_regcache, regnum, buf);
|
|
|
|
|
for (i = 0; i < size / sizeof (PTRACE_TYPE_RET); i++)
|
|
|
|
|
{
|
|
|
|
|
errno = 0;
|
2005-07-25 20:42:29 +00:00
|
|
|
|
ptrace (PT_WRITE_U, pid, (PTRACE_TYPE_ARG3)addr, buf[i]);
|
2005-01-10 20:36:38 +00:00
|
|
|
|
if (errno != 0)
|
2005-07-25 20:42:29 +00:00
|
|
|
|
error (_("Couldn't write register %s (#%d): %s."),
|
|
|
|
|
REGISTER_NAME (regnum), regnum, safe_strerror (errno));
|
2005-01-10 20:36:38 +00:00
|
|
|
|
|
|
|
|
|
addr += sizeof (PTRACE_TYPE_RET);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Store register REGNUM back into the inferior. If REGNUM is -1, do
|
|
|
|
|
this for all registers. */
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
inf_ptrace_store_registers (int regnum)
|
|
|
|
|
{
|
|
|
|
|
if (regnum == -1)
|
|
|
|
|
for (regnum = 0; regnum < NUM_REGS; regnum++)
|
|
|
|
|
inf_ptrace_store_register (regnum);
|
|
|
|
|
else
|
|
|
|
|
inf_ptrace_store_register (regnum);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Create a "traditional" ptrace target. REGISTER_U_OFFSET should be
|
|
|
|
|
a function returning the offset within the user area where a
|
|
|
|
|
particular register is stored. */
|
|
|
|
|
|
|
|
|
|
struct target_ops *
|
|
|
|
|
inf_ptrace_trad_target (CORE_ADDR (*register_u_offset)(int))
|
|
|
|
|
{
|
|
|
|
|
struct target_ops *t = inf_ptrace_target();
|
|
|
|
|
|
|
|
|
|
gdb_assert (register_u_offset);
|
|
|
|
|
inf_ptrace_register_u_offset = register_u_offset;
|
|
|
|
|
t->to_fetch_registers = inf_ptrace_fetch_registers;
|
|
|
|
|
t->to_store_registers = inf_ptrace_store_registers;
|
|
|
|
|
|
2004-09-12 13:04:41 +00:00
|
|
|
|
return t;
|
|
|
|
|
}
|