gdb/1922: `gdb -p' fails on FreeBSD unless procfs is mounted

Paul Gilliam pgilliam@us.ibm.com
Tue Apr 19 16:48:00 GMT 2005


The following reply was made to PR gdb/1922; it has been noted by GNATS.

From: Paul Gilliam <pgilliam@us.ibm.com>
To: gdb-prs@sources.redhat.com, das@FreeBSD.ORG
Cc: gdb-gnats@sources.redhat.com, marcel@FreeBSD.ORG
Subject: Re: gdb/1922: `gdb -p' fails on FreeBSD unless procfs is mounted
Date: Tue, 19 Apr 2005 08:47:23 -0800

 On Monday 18 April 2005 22:13, das@FreeBSD.ORG wrote:
 > 
 > >Number:         1922
 > >Category:       gdb
 > >Synopsis:       `gdb -p' fails on FreeBSD unless procfs is mounted
 > >Confidential:   no
 > >Severity:       serious
 > >Priority:       medium
 > >Responsible:    unassigned
 > >State:          open
 > >Class:          patch
 > >Submitter-Id:   net
 > >Arrival-Date:   Tue Apr 19 05:18:00 UTC 2005
 > >Closed-Date:
 > >Last-Modified:
 > >Originator:     das@FreeBSD.ORG
 > >Release:        6.1.1
 > >Organization:
 > >Environment:
 > FreeBSD VARK.MIT.EDU 6.0-CURRENT FreeBSD 6.0-CURRENT #7: Sun Apr 17 20:58:41 EDT 2005 das@VARK.MIT.EDU:/usr/scratch/vark/usr/home/t/freebsd/vark/src/sys/GENERIC  i386
 > >Description:
 > Invoking `gdb -p' on FreeBSD without procfs mounted causes gdb to crash because it can't find the process' executable file.  Subsequently, the target process is killed.  There are really two problems here:
 > 
 > (1) gdb should use a different mechanism to find the
 >     text file on FreeBSD.
 > 
 > (2) gdb should cleanly detach from the process when it
 >     detects an internal error such as this so the
 >     process isn't killed.
 
 This might not always be "The Right Thing".  The user should be able to choose: clean detach to kill.
 
 > 
 > The patch below solves problem (1).  However, it uses a feature that is only available in FreeBSD 6-CURRENT; gdb should fall back on procfs for older versions of FreeBSD.  (Note that on older versions of FreeBSD, the sysctl will simply return an error.)  Hopefully the patch will give someone with copyright assignment paperwork on file the necessary ideas to implement the complete solution (which requires fewer than 20 lines of code.)
 > 
 > Note that it isn't acceptable to simply say ``use procfs'', since procfs is disabled by default on FreeBSD due to its reputation for security problems.  I realize that there are other things in gdb that rely on procfs, but failure to attach to processes is perhaps the most glaring problem.
 > 
 > If someone can solve problem (2), that's great, although I'd be happy enough if someone simply addressed (1).  Thanks in advance!
 > >How-To-Repeat:
 > > gdb -p xxxx
 > solib-svr4.c:1307: internal-error: legacy_fetch_link_map_offsets called without legacy link_map support enabled.
 > A problem internal to GDB has been detected, further debugging may prove unreliable.
 > Quit this debugging session? (y or n) y
 > Create a core file of GDB? (y or n) n
 > [both gdb and process xxxx die]
 > >Fix:
 > Index: contrib/gdb/gdb/fbsd-proc.c
 > ===================================================================
 > RCS file: /cvs/src/contrib/gdb/gdb/fbsd-proc.c,v
 > retrieving revision 1.1.1.1
 > diff -u -r1.1.1.1 fbsd-proc.c
 > --- contrib/gdb/gdb/fbsd-proc.c 20 Jun 2004 18:16:56 -0000      1.1.1.1
 > +++ contrib/gdb/gdb/fbsd-proc.c 17 Apr 2005 01:40:58 -0000
 > @@ -26,6 +26,7 @@
 >  
 >  #include <sys/procfs.h>
 >  #include <sys/types.h>
 > +#include <sys/sysctl.h>
 >  
 >  #include "elf-bfd.h"
 >  
 > @@ -36,16 +37,20 @@
 >  {
 >    char *path;
 >    char *buf;
 > +  int oid[4];
 > +  size_t buflen;
 >  
 > -  xasprintf (&path, "/proc/%d/file", pid);
 >    buf = xcalloc (MAXPATHLEN, sizeof (char));
 > -  make_cleanup (xfree, path);
 > +  buflen = MAXPATHLEN;
 >    make_cleanup (xfree, buf);
 > -
 > -  if (readlink (path, buf, MAXPATHLEN) > 0)
 > +  oid[0] = CTL_KERN;
 > +  oid[1] = KERN_PROC;
 > +  oid[2] = KERN_PROC_PATHNAME;
 > +  oid[3] = pid;
 > +  if (sysctl(oid, 4, buf, &buflen, 0, 0) == 0)
 >      return buf;
 > -
 > -  return NULL;
 > +  else
 > +    return NULL;
 >  }
 >  
 >  static int
 > >Release-Note:
 > >Audit-Trail:
 > >Unformatted:
 > 
 > 



More information about the Gdb-prs mailing list