From: "Doug Evans" <dje@google.com>
To: "Aleksandar Ristovski" <ARistovski@qnx.com>
Cc: "Daniel Jacobowitz" <drow@false.org>,
gdb@sourceware.org, "Ryan Mansfield" <RMansfield@qnx.com>,
"Joel Brobecker" <brobecker@adacore.com>
Subject: Re: gdb_realpath: dealing with ./ and ../
Date: Fri, 04 Jan 2008 20:30:00 -0000 [thread overview]
Message-ID: <e394668d0801041230x31dc4e76g92dd6661f9ef13b3@mail.gmail.com> (raw)
In-Reply-To: <2F6320727174C448A52CEB63D85D11F40A4E@nova.ott.qnx.com>
[-- Attachment #1: Type: text/plain, Size: 767 bytes --]
[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?
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: rewrite-path-2.patch --]
[-- Type: text/x-patch; name=rewrite-path-2.patch, Size: 3610 bytes --]
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;
\f
+ static char *rewrite_subfile_path (char *name, char* dirname);
static int compare_line_numbers (const void *ln1p, const void *ln2p);
\f
*************** 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
next prev parent reply other threads:[~2008-01-04 20:30 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-01-04 19:52 Aleksandar Ristovski
2008-01-04 20:30 ` Doug Evans [this message]
-- strict thread matches above, loose matches on Subject: below --
2008-01-08 19:21 Aleksandar Ristovski
2008-01-08 16:12 Aleksandar Ristovski
2008-01-08 16:40 ` Mark Kettenis
2008-01-04 22:09 Aleksandar Ristovski
2008-01-04 20:16 Aleksandar Ristovski
2008-01-04 17:04 Aleksandar Ristovski
2008-01-04 17:42 ` Daniel Jacobowitz
2008-01-04 18:25 ` Joel Brobecker
2008-01-04 21:40 ` Doug Evans
2008-01-04 21:48 ` Daniel Jacobowitz
2008-01-04 22:23 ` Doug Evans
2008-01-03 18:30 Aleksandar Ristovski
2008-01-04 12:52 ` Daniel Jacobowitz
2008-01-03 17:07 Aleksandar Ristovski
2008-01-03 17:13 ` Daniel Jacobowitz
2008-01-07 14:33 ` Joel Brobecker
2008-01-07 17:00 ` Doug Evans
2008-01-08 5:46 ` Joel Brobecker
2008-01-08 19:54 ` Doug Evans
2008-01-03 16:39 Aleksandar Ristovski
2008-01-03 16:52 ` Daniel Jacobowitz
2008-01-03 15:25 Aleksandar Ristovski
2008-01-03 16:00 ` Daniel Jacobowitz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e394668d0801041230x31dc4e76g92dd6661f9ef13b3@mail.gmail.com \
--to=dje@google.com \
--cc=ARistovski@qnx.com \
--cc=RMansfield@qnx.com \
--cc=brobecker@adacore.com \
--cc=drow@false.org \
--cc=gdb@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox