From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6393 invoked by alias); 4 Jan 2008 17:04:30 -0000 Received: (qmail 6384 invoked by uid 22791); 4 Jan 2008 17:04:29 -0000 X-Spam-Check-By: sourceware.org Received: from qnxmail.qnx.com (HELO nimbus.ott.qnx.com) (209.226.137.76) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 04 Jan 2008 17:04:12 +0000 Received: by nimbus.ott.qnx.com with Internet Mail Service (5.5.2653.19) id ; Fri, 4 Jan 2008 12:03:52 -0500 Message-ID: <2F6320727174C448A52CEB63D85D11F40A4A@nova.ott.qnx.com> From: Aleksandar Ristovski To: Daniel Jacobowitz Cc: gdb@sourceware.org, Ryan Mansfield Subject: RE: gdb_realpath: dealing with ./ and ../ Date: Fri, 04 Jan 2008 17:04:00 -0000 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: multipart/mixed; boundary="----_=_NextPart_000_01C84EF0.47D762F6" X-IsSubscribed: yes Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2008-01/txt/msg00020.txt.bz2 This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ------_=_NextPart_000_01C84EF0.47D762F6 Content-Type: text/plain Content-length: 2491 > On Thu, Jan 03, 2008 at 01:25:55PM -0500, Aleksandar Ristovski wrote: > > 1. Problem one - relative NAME and absolute subfile->name case not > covered: > > I think you're right, but I can't tell for sure. I am pretty sure this is real problem as this is what I am seeing with our case (the instrumentation I posted proves it). This is easy and I think straight forward to fix. (please see the attachement buildsym.c.patch1). BUT... This does not solve all my problems. In fact, when debugging on linux a binary cross-compiled on windows, it won't work: IS_ABSOLUTE_PATH macro will differ depending on the configured gdb host. The problem with this is when one is debugging binary cross-compiled on windows, on a unix host, IS_ABSOLUTE_PATH will return 0 on "C:.." style paths which is not correct. Looking at the code, in many places we concatenate directory and file name if IS_ABSOLUTE_PATH returns zero so in case of cross-compiled binary I suspect there will be many issues. > > > 2. Problem two - one physical file is specified with two pathnames. > > The specific case that's important here is associating the main file > from a dwarf2 CU DIE with the right lines from .debug_line. When we > go to create that subfile we haven't created the other subfiles yet. > So what we need, I think, is to handle this in dwarf2read.c by walking > through the filename / directory table. dwarf2read.c calls start_subfile or start_symtab which in turn calls start_subfile. I think we should let our readers deal with "compiled" paths (i.e. as found in the binary), without conversion. In start_subfile, however, we can do something with paths. Currently, we do not try to substitute-path on paths coming from the binary, even though they are clearly our source paths and should be dealt with the same as with any other source path. My attempt would be patch2 attached (start_subfile.patch). Please take a look. This should solve both problems. Note: IS_ABSOLUTE_PATH issue will still exist since we deal with compiled paths throughout gdb code. Wherever IS_ABSOLUTE_PATH is used on a windows style path (and gdb was configured for *ix) it will return 0 leading to problems. Note2: for some reason, my post to gdb-patches didn't go through even after two attempts. There I submitted only source.c change dealing with rewriting source path in case when NAME is an absolute path and at the same time DIRNAME is not NULL (which can happen). Aleksandar Ristovski QNX Software Systems ------_=_NextPart_000_01C84EF0.47D762F6 Content-Type: application/octet-stream; name="buildsym.c.patch1" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="buildsym.c.patch1" Content-length: 2085 Index: gdb/buildsym.c=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= RCS file: /cvs/src/src/gdb/buildsym.c,v=0A= retrieving revision 1.59=0A= diff -u -3 -p -r1.59 buildsym.c=0A= --- gdb/buildsym.c 1 Jan 2008 22:53:09 -0000 1.59=0A= +++ gdb/buildsym.c 4 Jan 2008 14:41:44 -0000=0A= @@ -583,6 +583,13 @@ void=0A= start_subfile (char *name, char *dirname)=0A= {=0A= struct subfile *subfile;=0A= + char *absname; /* Absolute NAME. */=0A= +=0A= + if (!IS_ABSOLUTE_PATH (name)=20=0A= + && dirname !=3D NULL)=0A= + absname =3D concat (dirname, SLASH_STRING, name, NULL);=0A= + else=0A= + absname =3D name;=0A= =20=0A= /* See if this subfile is already known as a subfile of the current=0A= main source file. */=0A= @@ -590,6 +597,7 @@ start_subfile (char *name, char *dirname=0A= for (subfile =3D subfiles; subfile; subfile =3D subfile->next)=0A= {=0A= char *subfile_name;=0A= + char *aname;=0A= =20=0A= /* If NAME is an absolute path, and this subfile is not, then=0A= attempt to create an absolute path to compare. */=0A= @@ -601,7 +609,13 @@ start_subfile (char *name, char *dirname=0A= else=0A= subfile_name =3D subfile->name;=0A= =20=0A= - if (FILENAME_CMP (subfile_name, name) =3D=3D 0)=0A= + if (!IS_ABSOLUTE_PATH (name)=0A= + && IS_ABSOLUTE_PATH (subfile->name))=0A= + aname =3D absname;=0A= + else=0A= + aname =3D name;=0A= +=0A= + if (FILENAME_CMP (subfile_name, aname) =3D=3D 0)=0A= {=0A= current_subfile =3D subfile;=0A= if (subfile_name !=3D subfile->name)=0A= @@ -612,6 +626,9 @@ start_subfile (char *name, char *dirname=0A= xfree (subfile_name);=0A= }=0A= =20=0A= + if (absname !=3D name)=0A= + xfree (absname);=0A= +=0A= /* This subfile is not known. Add an entry for it. Make an entry=0A= for this subfile in the list of all subfiles of the current main=0A= source file. */=0A= ------_=_NextPart_000_01C84EF0.47D762F6 Content-Type: application/octet-stream; name="start_subfile.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="start_subfile.patch" Content-length: 7061 Index: gdb/buildsym.c=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= RCS file: /cvs/src/src/gdb/buildsym.c,v=0A= retrieving revision 1.59=0A= diff -u -3 -p -r1.59 buildsym.c=0A= --- gdb/buildsym.c 1 Jan 2008 22:53:09 -0000 1.59=0A= +++ gdb/buildsym.c 4 Jan 2008 16:28:40 -0000=0A= @@ -44,6 +44,7 @@=0A= #include "cp-support.h"=0A= #include "dictionary.h"=0A= #include "addrmap.h"=0A= +#include "source.h"=0A= =20=0A= /* Ask buildsym.h to define the vars it normally declares `extern'. */=0A= #define EXTERN=0A= @@ -574,15 +575,57 @@ make_blockvector (struct objfile *objfil=0A= return (blockvector);=0A= }=0A= =0C=0A= +=0A= +/* Workaround for IS_ABSOLUTE_PATH issue. When gdb is configured for=0A= + *ix, and we are debugging binary cross-compiled on windows, the origina= l=0A= + IS_ABSOLUTE_PATH will always return 0. This is not good. */=0A= +#undef IS_ABSOLUTE_PATH=0A= +#undef IS_DIR_SEPARATOR=0A= +=0A= +#define IS_DIR_SEPARATOR(c) ((c) =3D=3D '/' || (c) =3D=3D '\\')=0A= +/* Note that IS_ABSOLUTE_PATH accepts d:foo as well, although it is=0A= + only semi-absolute. This is because the users of IS_ABSOLUTE_PATH=0A= + want to know whether to prepend the current working directory to=0A= + a file name, which should not be done with a name like d:foo. */=0A= +#define IS_ABSOLUTE_PATH(f) (IS_DIR_SEPARATOR((f)[0]) || (((f)[0]) && ((f)= [1] =3D=3D ':')))=0A= +=0A= /* Start recording information about source code that came from an=0A= included (or otherwise merged-in) source file with a different=0A= name. NAME is the name of the file (cannot be NULL), DIRNAME is=0A= the directory in which the file was compiled (or NULL if not known). *= /=0A= =20=0A= void=0A= -start_subfile (char *name, char *dirname)=0A= +start_subfile (char *name, char *dirname)=20=0A= {=0A= struct subfile *subfile;=0A= + char *absname; /* Rewritten absolute NAME. */=0A= +=0A= + if (IS_ABSOLUTE_PATH (name))=0A= + {=0A= + char *rwname;=0A= + rwname =3D rewrite_source_path (name);=0A= + if (rwname !=3D NULL)=0A= + {=0A= + make_cleanup (xfree, rwname);=0A= + name =3D rwname;=0A= + }=0A= + absname =3D name;=0A= + }=0A= + else=0A= + {=0A= + if (dirname !=3D NULL)=0A= + {=0A= + char *rwdirname =3D rewrite_source_path (dirname);=0A= + if (rwdirname =3D=3D NULL)=0A= + rwdirname =3D dirname;=0A= + absname =3D concat (rwdirname, SLASH_STRING, name, NULL);=0A= + if (rwdirname !=3D dirname)=0A= + xfree (rwdirname);=0A= + make_cleanup (xfree, absname);=0A= + }=0A= + else=0A= + absname =3D name;=0A= + }=0A= =20=0A= /* See if this subfile is already known as a subfile of the current=0A= main source file. */=0A= @@ -590,18 +633,36 @@ start_subfile (char *name, char *dirname=0A= for (subfile =3D subfiles; subfile; subfile =3D subfile->next)=0A= {=0A= char *subfile_name;=0A= + char *aname;=0A= =20=0A= /* If NAME is an absolute path, and this subfile is not, then=0A= attempt to create an absolute path to compare. */=0A= if (IS_ABSOLUTE_PATH (name)=0A= && !IS_ABSOLUTE_PATH (subfile->name)=0A= && subfile->dirname !=3D NULL)=0A= - subfile_name =3D concat (subfile->dirname, SLASH_STRING,=0A= + {=0A= + char *rwsubfile_dirname =3D rewrite_source_path (subfile->dirname);=0A= + if (rwsubfile_dirname =3D=3D NULL)=0A= + rwsubfile_dirname =3D subfile->dirname;=0A= + subfile_name =3D concat (rwsubfile_dirname, SLASH_STRING,=0A= subfile->name, NULL);=0A= + if (rwsubfile_dirname !=3D subfile->dirname)=0A= + xfree (rwsubfile_dirname);=0A= + }=0A= + else=0A= + {=0A= + subfile_name =3D rewrite_source_path (subfile->name);=0A= + if (subfile_name =3D=3D NULL)=0A= + subfile_name =3D subfile->name;=0A= + }=0A= +=0A= + if (!IS_ABSOLUTE_PATH (name)=0A= + && IS_ABSOLUTE_PATH (subfile->name))=0A= + aname =3D absname;=0A= else=0A= - subfile_name =3D subfile->name;=0A= + aname =3D name;=0A= =20=0A= - if (FILENAME_CMP (subfile_name, name) =3D=3D 0)=0A= + if (FILENAME_CMP (subfile_name, aname) =3D=3D 0)=0A= {=0A= current_subfile =3D subfile;=0A= if (subfile_name !=3D subfile->name)=0A= Index: gdb/source.c=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= RCS file: /cvs/src/src/gdb/source.c,v=0A= retrieving revision 1.83=0A= diff -u -3 -p -r1.83 source.c=0A= --- gdb/source.c 1 Jan 2008 22:53:13 -0000 1.83=0A= +++ gdb/source.c 4 Jan 2008 16:28:40 -0000=0A= @@ -895,10 +895,12 @@ get_substitute_path_rule (const char *pa=0A= Return NULL if no substitution rule was specified by the user,=0A= or if no rule applied to the given PATH. */=0A= =20=20=20=20=0A= -static char *=0A= +char *=0A= rewrite_source_path (const char *path)=0A= {=0A= - const struct substitute_path_rule *rule =3D get_substitute_path_rule (pa= th);=0A= + const struct substitute_path_rule *rule =3D (path !=3D NULL) ?=20=0A= + get_substitute_path_rule (path):=0A= + NULL;=0A= char *new_path;=0A= int from_len;=0A= =20=20=20=0A= @@ -999,10 +1001,11 @@ find_and_open_source (struct objfile *ob=0A= strcat (path + len, source_path + len + cdir_len); /* After $cdir */=0A= }=0A= }=0A= - else=0A= +=20=20=0A= + if (IS_ABSOLUTE_PATH (filename))=0A= {=0A= - /* If dirname is NULL, chances are the path is embedded in=0A= - the filename. Try the source path substitution on it. */=0A= + /* If filename is absolute path, try the source path=20=0A= + substitution on it. */=0A= char *rewritten_filename =3D rewrite_source_path (filename);=0A= =20=0A= if (rewritten_filename !=3D NULL)=0A= Index: gdb/source.h=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= RCS file: /cvs/src/src/gdb/source.h,v=0A= retrieving revision 1.9=0A= diff -u -3 -p -r1.9 source.h=0A= --- gdb/source.h 1 Jan 2008 22:53:13 -0000 1.9=0A= +++ gdb/source.h 4 Jan 2008 16:28:40 -0000=0A= @@ -66,4 +66,14 @@ extern struct symtab_and_line set_curren=0A= =20=0A= /* Reset any information stored about a default file and line to print. */= =0A= extern void clear_current_source_symtab_and_line (void);=0A= +=0A= +/* If the user specified a source path substitution rule that applies=0A= + to PATH, then apply it and return the new path. This new path must=0A= + be deallocated afterwards.=20=20=0A= +=20=20=20=0A= + Return NULL if no substitution rule was specified by the user,=0A= + or if no rule applied to the given PATH. */=0A= +=20=20=20=0A= +extern char *rewrite_source_path (const char *path);=0A= +=0A= #endif=0A= ------_=_NextPart_000_01C84EF0.47D762F6--