Subject: gdb attach
To: None <tech-toolchain@netbsd.org, tech-kern@netbsd.org>
From: Nick Hudson <nick.hudson@dsl.pipex.com>
List: tech-toolchain
Date: 11/17/2006 07:39:11
--Boundary-00=_fcWXFlxSnO60NkX
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Hi,
Here's a patch to make gdb6 attach work in a similar way to the fix I applied
to gdb5 for i386 only so far.
The difference is that gdb6 likes to have the filename to display and re-open
the filename after the process dies so I've added an exe symlink to procfs in
the same as Linux. I'm avoiding the discussion as to whether this is the best
way to get the filename from a pid. ;) FWIW, FreeBSD does this as well.
Any comments before I commit?
Thanks,
Nick
--Boundary-00=_fcWXFlxSnO60NkX
Content-Type: text/x-diff;
charset="us-ascii";
name="attach.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="attach.diff"
Index: sys/miscfs/procfs/procfs_vnops.c
===================================================================
RCS file: /cvsroot/src/sys/miscfs/procfs/procfs_vnops.c,v
retrieving revision 1.137
diff -u -p -u -r1.137 procfs_vnops.c
--- sys/miscfs/procfs/procfs_vnops.c 29 Oct 2006 22:35:35 -0000 1.137
+++ sys/miscfs/procfs/procfs_vnops.c 17 Nov 2006 07:22:29 -0000
@@ -142,7 +142,7 @@ static const struct proc_target {
{ DT_REG, N("map"), PFSmap, procfs_validmap },
{ DT_REG, N("maps"), PFSmaps, procfs_validmap },
{ DT_REG, N("cmdline"), PFScmdline, NULL },
- { DT_REG, N("exe"), PFSexe, procfs_validfile_linux },
+ { DT_REG, N("exe"), PFSexe, procfs_validfile },
{ DT_LNK, N("cwd"), PFScwd, NULL },
{ DT_LNK, N("root"), PFSchroot, NULL },
{ DT_LNK, N("emul"), PFSemul, NULL },
Index: gnu/dist/gdb6/gdb/Makefile.in
===================================================================
RCS file: /cvsroot/src/gnu/dist/gdb6/gdb/Makefile.in,v
retrieving revision 1.1.1.2
diff -u -p -u -r1.1.1.2 Makefile.in
--- gnu/dist/gdb6/gdb/Makefile.in 2 Jul 2006 20:13:07 -0000 1.1.1.2
+++ gnu/dist/gdb6/gdb/Makefile.in 17 Nov 2006 07:23:21 -0000
@@ -748,6 +748,7 @@ mipsnbsd_tdep_h = mipsnbsd-tdep.h
mips_tdep_h = mips-tdep.h
mn10300_tdep_h = mn10300-tdep.h
monitor_h = monitor.h
+nbsd_nat_h = nbsd-nat.h
nbsd_tdep_h = nbsd-tdep.h
nto_tdep_h = nto-tdep.h $(defs_h) $(solist_h) $(osabi_h) $(regset_h)
objc_lang_h = objc-lang.h
@@ -1439,7 +1440,7 @@ ALLDEPFILES = \
mips-tdep.c mipsv4-nat.c \
mipsnbsd-nat.c mipsnbsd-tdep.c \
mips64obsd-nat.c mips64obsd-tdep.c \
- nbsd-tdep.c obsd-tdep.c \
+ nbsd-nat.c nbsd-tdep.c obsd-tdep.c \
solib-osf.c \
somread.c solib-som.c $(HPREAD_SOURCE) \
posix-hdep.c \
@@ -2356,6 +2357,7 @@ ms1-tdep.o: ms1-tdep.c $(defs_h) $(frame
$(gdb_string_h) $(regcache_h) $(reggroups_h) $(gdbcore_h) \
$(trad_frame_h) $(inferior_h) $(dwarf2_frame_h) $(infcall_h) \
$(gdb_assert_h)
+nbsd-nat.o: nbsd-nat.c $(defs_h) $(nbsd_nat_h)
nbsd-tdep.o: nbsd-tdep.c $(defs_h) $(gdb_string_h) $(solib_svr4_h)
nlmread.o: nlmread.c $(defs_h) $(bfd_h) $(symtab_h) $(symfile_h) \
$(objfiles_h) $(buildsym_h) $(stabsread_h) $(block_h)
Index: gnu/dist/gdb6/gdb/i386nbsd-nat.c
===================================================================
RCS file: /cvsroot/src/gnu/dist/gdb6/gdb/i386nbsd-nat.c,v
retrieving revision 1.1.1.2
diff -u -p -u -r1.1.1.2 i386nbsd-nat.c
--- gnu/dist/gdb6/gdb/i386nbsd-nat.c 2 Jul 2006 20:14:16 -0000 1.1.1.2
+++ gnu/dist/gdb6/gdb/i386nbsd-nat.c 17 Nov 2006 07:23:22 -0000
@@ -33,6 +33,7 @@
#include <machine/frame.h>
#include <machine/pcb.h>
+#include "nbsd-nat.h"
#include "bsd-kvm.h"
static int
@@ -79,9 +80,13 @@ void _initialize_i386nbsd_nat (void);
void
_initialize_i386nbsd_nat (void)
{
- /* We've got nothing to add to the common *BSD/i386 target. */
- add_target (i386bsd_target ());
+ struct target_ops *t;
+ /* Add some extra features to the common *BSD/i386 target. */
+ t = i386bsd_target ();
+ t->to_pid_to_exec_file = nbsd_pid_to_exec_file;
+ add_target (t);
+
/* Support debugging kernel virtual memory images. */
bsd_kvm_add_target (i386nbsd_supply_pcb);
}
Index: gnu/dist/gdb6/gdb/config/i386/nbsdelf.mh
===================================================================
RCS file: /cvsroot/src/gnu/dist/gdb6/gdb/config/i386/nbsdelf.mh,v
retrieving revision 1.1.1.1
diff -u -p -u -r1.1.1.1 nbsdelf.mh
--- gnu/dist/gdb6/gdb/config/i386/nbsdelf.mh 15 May 2006 14:12:03 -0000 1.1.1.1
+++ gnu/dist/gdb6/gdb/config/i386/nbsdelf.mh 17 Nov 2006 07:23:25 -0000
@@ -1,6 +1,6 @@
# Host: NetBSD/i386 ELF
NATDEPFILES= fork-child.o inf-ptrace.o \
- i386bsd-nat.o i386nbsd-nat.o bsd-kvm.o
+ nbsd-nat.o i386bsd-nat.o i386nbsd-nat.o bsd-kvm.o
NAT_FILE= solib.h
LOADLIBES= -lkvm
--Boundary-00=_fcWXFlxSnO60NkX
Content-Type: text/x-csrc;
charset="us-ascii";
name="nbsd-nat.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="nbsd-nat.c"
/* NetBSD-specific methods for using the /proc file system.
Copyright 2006 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 <sys/param.h>
#include "defs.h"
#include "nbsd-nat.h"
char *
nbsd_pid_to_exec_file (int pid)
{
size_t len = MAXPATHLEN;
char *buf = xcalloc (len, sizeof (char));
char *path;
path = xstrprintf ("/proc/%d/exe", pid);
if (readlink (path, buf, MAXPATHLEN) == -1)
{
xfree (buf);
buf = NULL;
}
xfree (path);
return buf;
}
--Boundary-00=_fcWXFlxSnO60NkX
Content-Type: text/x-chdr;
charset="us-ascii";
name="nbsd-nat.h"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="nbsd-nat.h"
/* Native-dependent code for NetBSD.
Copyright (C) 2006 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., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. */
#ifndef NBSD_NAT_H
#define NBSD_NAT_H
/* Return a the name of file that can be opened to get the symbols for
the child process identified by PID. */
extern char *nbsd_pid_to_exec_file (int pid);
#endif /* nbsd-nat.h */
--Boundary-00=_fcWXFlxSnO60NkX--