* Makefile.in (linux-nat.o): Add rule.

* linux-nat.c: New file.
	* config/nm-linux.h (CHILD_INSERT_FORK_CATCHPOINT): Define.
	(CHILD_INSERT_VFORK_CATCHPOINT): Define.
	(CHILD_INSERT_EXEC_CATCHPOINT): Define.
	* config/alpha/alpha-linux.mh (NATDEPFILES): Add linux-nat.o.
	* config/arm/linux.mh (NATDEPFILES): Likewise.
	* config/i386/linux.mh (NATDEPFILES): Likewise.
	* config/i386/x86-64linux.mh (NATDEPFILES): Likewise.
	* config/ia64/linux.mh (NATDEPFILES): Likewise.
	* config/m68k/linux.mh (NATDEPFILES): Likewise.
	* config/mips/linux.mh (NATDEPFILES): Likewise.
	* config/powerpc/linux.mh (NATDEPFILES): Likewise.
	* config/s390/s390.mh (NATDEPFILES): Likewise.
	* config/sparc/linux.mh (NATDEPFILES): Likewise.
This commit is contained in:
Daniel Jacobowitz 2003-06-15 20:56:48 +00:00
parent a92feac0ae
commit 3993f6b15a
14 changed files with 212 additions and 9 deletions

View File

@ -1,3 +1,21 @@
2003-06-15 Daniel Jacobowitz <drow@mvista.com>
* Makefile.in (linux-nat.o): Add rule.
* linux-nat.c: New file.
* config/nm-linux.h (CHILD_INSERT_FORK_CATCHPOINT): Define.
(CHILD_INSERT_VFORK_CATCHPOINT): Define.
(CHILD_INSERT_EXEC_CATCHPOINT): Define.
* config/alpha/alpha-linux.mh (NATDEPFILES): Add linux-nat.o.
* config/arm/linux.mh (NATDEPFILES): Likewise.
* config/i386/linux.mh (NATDEPFILES): Likewise.
* config/i386/x86-64linux.mh (NATDEPFILES): Likewise.
* config/ia64/linux.mh (NATDEPFILES): Likewise.
* config/m68k/linux.mh (NATDEPFILES): Likewise.
* config/mips/linux.mh (NATDEPFILES): Likewise.
* config/powerpc/linux.mh (NATDEPFILES): Likewise.
* config/s390/s390.mh (NATDEPFILES): Likewise.
* config/sparc/linux.mh (NATDEPFILES): Likewise.
2003-06-15 Mark Kettenis <kettenis@gnu.org>
* i387-tdep.c: Reorder includes, fix some whitespace issues and

View File

@ -1916,6 +1916,7 @@ lin-lwp.o: lin-lwp.c $(defs_h) $(gdb_assert_h) $(gdb_string_h) $(gdb_wait_h) \
linespec.o: linespec.c $(defs_h) $(symtab_h) $(frame_h) $(command_h) \
$(symfile_h) $(objfiles_h) $(source_h) $(demangle_h) $(value_h) \
$(completer_h) $(cp_abi_h) $(parser_defs_h) $(block_h) $(objc_lang_h)
linux-nat.o: linux-nat.c $(defs_h) $(inferior_h) $(target_h) $(gdb_wait_h)
linux-proc.o: linux-proc.c $(defs_h) $(inferior_h) $(regcache_h) \
$(gregset_h) $(gdbcore_h) $(gdbthread_h) $(elf_bfd_h) \
$(cli_decode_h) $(gdb_string_h)

View File

@ -2,7 +2,8 @@
XM_FILE= xm-alphalinux.h
NAT_FILE= nm-linux.h
NATDEPFILES= infptrace.o inftarg.o corelow.o alpha-nat.o linux-proc.o \
fork-child.o proc-service.o thread-db.o lin-lwp.o gcore.o
fork-child.o proc-service.o thread-db.o lin-lwp.o gcore.o \
linux-nat.o
LOADLIBES = -ldl -rdynamic

View File

@ -5,7 +5,7 @@ XM_FILE= xm-linux.h
NAT_FILE= nm-linux.h
NATDEPFILES= infptrace.o inftarg.o fork-child.o corelow.o \
core-regset.o arm-linux-nat.o linux-proc.o gcore.o \
proc-service.o thread-db.o lin-lwp.o
proc-service.o thread-db.o lin-lwp.o linux-nat.o
LOADLIBES= -ldl -rdynamic

View File

@ -5,7 +5,8 @@ XM_FILE= xm-i386.h
NAT_FILE= nm-linux.h
NATDEPFILES= infptrace.o inftarg.o fork-child.o corelow.o linux-proc.o \
core-aout.o i386-nat.o i386-linux-nat.o \
proc-service.o thread-db.o lin-lwp.o linux-proc.o gcore.o
proc-service.o thread-db.o lin-lwp.o linux-proc.o gcore.o \
linux-nat.o
# The dynamically loaded libthread_db needs access to symbols in the
# gdb executable.

View File

@ -5,6 +5,7 @@ XM_FILE= xm-i386.h
NAT_FILE= nm-x86-64linux.h
NATDEPFILES= infptrace.o inftarg.o fork-child.o corelow.o \
core-regset.o i386-nat.o x86-64-linux-nat.o \
linux-nat.o \
proc-service.o thread-db.o lin-lwp.o linux-proc.o gcore.o
# The dynamically loaded libthread_db needs access to symbols in the

View File

@ -5,6 +5,6 @@ XM_FILE= xm-linux.h
NAT_FILE= nm-linux.h
NATDEPFILES= infptrace.o inftarg.o fork-child.o corelow.o gcore.o \
core-aout.o core-regset.o ia64-linux-nat.o linux-proc.o \
proc-service.o thread-db.o lin-lwp.o
proc-service.o thread-db.o lin-lwp.o linux-nat.o
LOADLIBES = -ldl -rdynamic

View File

@ -5,7 +5,7 @@ XM_FILE= xm-linux.h
NAT_FILE= nm-linux.h
NATDEPFILES= infptrace.o inftarg.o fork-child.o \
corelow.o core-aout.o m68klinux-nat.o linux-proc.o gcore.o \
proc-service.o thread-db.o lin-lwp.o
proc-service.o thread-db.o lin-lwp.o linux-nat.o
# The dynamically loaded libthread_db needs access to symbols in the
# gdb executable.

View File

@ -2,6 +2,7 @@
XM_FILE= xm-linux.h
NAT_FILE= nm-linux.h
NATDEPFILES= infptrace.o inftarg.o fork-child.o mips-linux-nat.o \
thread-db.o lin-lwp.o proc-service.o linux-proc.o gcore.o
thread-db.o lin-lwp.o proc-service.o linux-proc.o gcore.o \
linux-nat.o
LOADLIBES = -ldl -rdynamic

View File

@ -77,3 +77,7 @@ struct mem_attrib;
extern int linux_proc_xfer_memory (CORE_ADDR addr, char *myaddr, int len,
int write, struct mem_attrib *attrib,
struct target_ops *target);
#define CHILD_INSERT_FORK_CATCHPOINT
#define CHILD_INSERT_VFORK_CATCHPOINT
#define CHILD_INSERT_EXEC_CATCHPOINT

View File

@ -6,7 +6,7 @@ XM_CLIBS=
NAT_FILE= nm-linux.h
NATDEPFILES= infptrace.o inftarg.o fork-child.o linux-proc.o \
ppc-linux-nat.o proc-service.o thread-db.o lin-lwp.o \
gcore.o
gcore.o linux-nat.o
LOADLIBES = -ldl -rdynamic

View File

@ -6,7 +6,7 @@ XM_CLIBS=
NAT_FILE= nm-linux.h
NATDEPFILES= infptrace.o inftarg.o fork-child.o corelow.o s390-nat.o \
core-aout.o core-regset.o linux-proc.o gcore.o thread-db.o lin-lwp.o \
proc-service.o
proc-service.o linux-nat.o
LOADLIBES = -ldl -rdynamic

View File

@ -5,7 +5,7 @@ XM_FILE= xm-linux.h
NAT_FILE= nm-linux.h
NATDEPFILES= fork-child.o infptrace.o inftarg.o corelow.o sparc-nat.o \
proc-service.o thread-db.o lin-lwp.o sparc-linux-nat.o \
linux-proc.o gcore.o
linux-proc.o gcore.o linux-nat.o
# The dynamically loaded libthread_db needs access to symbols in the
# gdb executable.

176
gdb/linux-nat.c Normal file
View File

@ -0,0 +1,176 @@
/* GNU/Linux native-dependent code common to multiple platforms.
Copyright (C) 2003 Free Software Foundation, Inc.
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 "inferior.h"
#include "target.h"
#include "gdb_wait.h"
#include <sys/ptrace.h>
/* If the system headers did not provide the constants, hard-code the normal
values. */
#ifndef PTRACE_EVENT_FORK
#define PTRACE_SETOPTIONS 0x4200
#define PTRACE_GETEVENTMSG 0x4201
/* options set using PTRACE_SETOPTIONS */
#define PTRACE_O_TRACESYSGOOD 0x00000001
#define PTRACE_O_TRACEFORK 0x00000002
#define PTRACE_O_TRACEVFORK 0x00000004
#define PTRACE_O_TRACECLONE 0x00000008
#define PTRACE_O_TRACEEXEC 0x00000010
/* Wait extended result codes for the above trace options. */
#define PTRACE_EVENT_FORK 1
#define PTRACE_EVENT_VFORK 2
#define PTRACE_EVENT_CLONE 3
#define PTRACE_EVENT_EXEC 4
#endif /* PTRACE_EVENT_FORK */
/* We can't always assume that this flag is available, but all systems
with the ptrace event handlers also have __WALL, so it's safe to use
here. */
#ifndef __WALL
#define __WALL 0x40000000 /* Wait for any child. */
#endif
/* This variable is a tri-state flag: -1 for unknown, 0 if PTRACE_O_TRACEFORK
can not be used, 1 if it can. */
static int linux_supports_tracefork_flag = -1;
/* A helper function for linux_test_for_tracefork, called after fork (). */
static void
linux_tracefork_child (void)
{
int ret;
ptrace (PTRACE_TRACEME, 0, 0, 0);
kill (getpid (), SIGSTOP);
fork ();
exit (0);
}
/* Determine if PTRACE_O_TRACEFORK can be used to follow fork events. We
create a child process, attach to it, use PTRACE_SETOPTIONS to enable
fork tracing, and let it fork. If the process exits, we assume that
we can't use TRACEFORK; if we get the fork notification, and we can
extract the new child's PID, then we assume that we can. */
static void
linux_test_for_tracefork (void)
{
int child_pid, ret, status;
long second_pid;
child_pid = fork ();
if (child_pid == -1)
perror_with_name ("linux_test_for_tracefork: fork");
if (child_pid == 0)
linux_tracefork_child ();
ret = waitpid (child_pid, &status, 0);
if (ret == -1)
perror_with_name ("linux_test_for_tracefork: waitpid");
else if (ret != child_pid)
error ("linux_test_for_tracefork: waitpid: unexpected result %d.", ret);
if (! WIFSTOPPED (status))
error ("linux_test_for_tracefork: waitpid: unexpected status %d.", status);
linux_supports_tracefork_flag = 0;
ret = ptrace (PTRACE_SETOPTIONS, child_pid, 0, PTRACE_O_TRACEFORK);
if (ret != 0)
{
ptrace (PTRACE_KILL, child_pid, 0, 0);
waitpid (child_pid, &status, 0);
return;
}
ptrace (PTRACE_CONT, child_pid, 0, 0);
ret = waitpid (child_pid, &status, 0);
if (ret == child_pid && WIFSTOPPED (status)
&& status >> 16 == PTRACE_EVENT_FORK)
{
second_pid = 0;
ret = ptrace (PTRACE_GETEVENTMSG, child_pid, 0, &second_pid);
if (ret == 0 && second_pid != 0)
{
int second_status;
linux_supports_tracefork_flag = 1;
waitpid (second_pid, &second_status, 0);
ptrace (PTRACE_DETACH, second_pid, 0, 0);
}
}
if (WIFSTOPPED (status))
{
ptrace (PTRACE_DETACH, child_pid, 0, 0);
waitpid (child_pid, &status, 0);
}
}
/* Return non-zero iff we have tracefork functionality available.
This function also sets linux_supports_tracefork_flag. */
static int
linux_supports_tracefork (void)
{
if (linux_supports_tracefork_flag == -1)
linux_test_for_tracefork ();
return linux_supports_tracefork_flag;
}
int
child_insert_fork_catchpoint (int pid)
{
if (linux_supports_tracefork ())
error ("Fork catchpoints have not been implemented yet.");
else
error ("Your system does not support fork catchpoints.");
}
int
child_insert_vfork_catchpoint (int pid)
{
if (linux_supports_tracefork ())
error ("Vfork catchpoints have not been implemented yet.");
else
error ("Your system does not support vfork catchpoints.");
}
int
child_insert_exec_catchpoint (int pid)
{
if (linux_supports_tracefork ())
error ("Exec catchpoints have not been implemented yet.");
else
error ("Your system does not support exec catchpoints.");
}