This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Re: gdb_realpath: dealing with ./ and ../
- From: "Doug Evans" <dje at google dot com>
- To: "Aleksandar Ristovski" <ARistovski at qnx dot com>
- Cc: "Daniel Jacobowitz" <drow at false dot org>, gdb at sourceware dot org, "Ryan Mansfield" <RMansfield at qnx dot com>, "Joel Brobecker" <brobecker at adacore dot com>
- Date: Fri, 4 Jan 2008 12:30:11 -0800
- Subject: Re: gdb_realpath: dealing with ./ and ../
- References: <2F6320727174C448A52CEB63D85D11F40A4E@nova.ott.qnx.com>
[fwiw ...]
I wonder if things would be cleaner if the path argument to
start_subfile (name, dirname) was processed the same as each subfile's
path (subfile->name, subfile->dirname). Otherwise it seems like a
potential bug source (not necessarily now, but down the road). There
(apparently) have been edits to this area of the code in the past that
have introduced bugs.
i.e. how about writing a utility to process name,dirname and using
that utility for both the argument to start_subfile and each subfile
in the comparison loop? This patch is untested, I'm just providing a
definitive example of the suggestion.
Another question: In the case where dirname is prepended to name,
should the whole thing be passed to rewrite_source_path, instead of
just dirname?
Index: buildsym.c
===================================================================
RCS file: /cvs/src/src/gdb/buildsym.c,v
retrieving revision 1.59
diff -u -p -c -r1.59 buildsym.c
*** buildsym.c 1 Jan 2008 22:53:09 -0000 1.59
--- buildsym.c 4 Jan 2008 20:22:00 -0000
*************** static struct obstack pending_addrmap_ob
*** 86,91 ****
--- 87,93 ----
static int pending_addrmap_interesting;
+ static char *rewrite_subfile_path (char *name, char* dirname);
static int compare_line_numbers (const void *ln1p, const void *ln2p);
*************** void
*** 583,617 ****
start_subfile (char *name, char *dirname)
{
struct subfile *subfile;
/* See if this subfile is already known as a subfile of the current
main source file. */
for (subfile = subfiles; subfile; subfile = subfile->next)
{
! char *subfile_name;
!
! /* If NAME is an absolute path, and this subfile is not, then
! attempt to create an absolute path to compare. */
! if (IS_ABSOLUTE_PATH (name)
! && !IS_ABSOLUTE_PATH (subfile->name)
! && subfile->dirname != NULL)
! subfile_name = concat (subfile->dirname, SLASH_STRING,
! subfile->name, NULL);
! else
! subfile_name = subfile->name;
! if (FILENAME_CMP (subfile_name, name) == 0)
{
current_subfile = subfile;
! if (subfile_name != subfile->name)
! xfree (subfile_name);
return;
}
! if (subfile_name != subfile->name)
! xfree (subfile_name);
}
/* This subfile is not known. Add an entry for it. Make an entry
for this subfile in the list of all subfiles of the current main
source file. */
--- 599,630 ----
start_subfile (char *name, char *dirname)
{
struct subfile *subfile;
+ /* Rewritten NAME, typically an absolute path, that is used to detect
+ identical subfiles. */
+ char *comparable_name;
+
+ comparable_name = rewrite_subfile_path (name, dirname);
/* See if this subfile is already known as a subfile of the current
main source file. */
for (subfile = subfiles; subfile; subfile = subfile->next)
{
! char *subfile_name = rewrite_subfile_path (subfile->name,
! subfile->dirname);
! if (FILENAME_CMP (subfile_name, comparable_name) == 0)
{
current_subfile = subfile;
! xfree (comparable_name);
! xfree (subfile_name);
return;
}
! xfree (subfile_name);
}
+ xfree (comparable_name);
+
/* This subfile is not known. Add an entry for it. Make an entry
for this subfile in the list of all subfiles of the current main
source file. */
*************** start_subfile (char *name, char *dirname
*** 681,686 ****
--- 694,727 ----
}
}
+ /* Subroutine of start_subfile to simplify it.
+ Convert NAME, DIRNAME to a form that can be used to watch for
+ identical subfiles.
+ Space for the result is malloc'd, caller must free. */
+
+ static char *
+ rewrite_subfile_path (char *name, char *dirname)
+ {
+ char *p = name;
+ char *rwname;
+
+ if (! IS_ABSOLUTE_PATH (name)
+ && dirname != NULL)
+ p = concat (dirname, SLASH_STRING, name, NULL);
+
+ rwname = rewrite_source_path (p);
+
+ if (rwname != NULL)
+ {
+ if (p != name)
+ xfree (p);
+ return rwname;
+ }
+ if (p != name)
+ return p;
+ return xstrdup (name);
+ }
+
/* For stabs readers, the first N_SO symbol is assumed to be the
source file name, and the subfile struct is initialized using that
assumption. If another N_SO symbol is later seen, immediately