This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH] Fix dir command for duplicated paths
- From: Edjunior Barbosa Machado <emachado at linux dot vnet dot ibm dot com>
- To: gdb-patches at sourceware dot org
- Cc: jan dot kratochvil at redhat dot com
- Date: Sun, 5 Jan 2014 23:50:55 -0200
- Subject: [PATCH] Fix dir command for duplicated paths
- Authentication-results: sourceware.org; auth=none
Hi,
noticed this issue with dir command for duplicated paths on upstream gdb:
$ ./gdb -q -ex "dir /tmp/a /tmp/b /tmp/c" -ex "dir /tmp/b /tmp/d /tmp/c"
Source directories searched: /tmp/a:/tmp/b:/tmp/c:$cdir:$cwd
Source directories searched: /tmp/b:/tmp/d:/tmp/c:/tmp/a:/tmp/b:/tmp/c:$cdir:$cwd
In gdb 7.4, the output used to be correct:
Source directories searched: /tmp/a:/tmp/b:/tmp/c:$cdir:$cwd
Source directories searched: /tmp/b:/tmp/d:/tmp/c:/tmp/a:$cdir:$cwd
This issue was introduced with a change on gdb/source.c from this patch:
https://sourceware.org/ml/gdb-patches/2012-04/msg00086.html
The patch below intends to fixes this regression using the original block of
code that checks for duplicated paths along the previously included paths.
Ok?
Thanks,
--
Edjunior
gdb/
2014-01-05 Edjunior Barbosa Machado <emachado@linux.vnet.ibm.com>
* source.c (add_path): Fix check for duplicated paths in the previously
included paths.
---
gdb/source.c | 32 ++++++++++++++++++++++----------
1 file changed, 22 insertions(+), 10 deletions(-)
diff --git a/gdb/source.c b/gdb/source.c
index b75a7b4..4da5a95 100644
--- a/gdb/source.c
+++ b/gdb/source.c
@@ -574,17 +574,29 @@ add_path (char *dirname, char **which_path, int parse_separators)
char tinybuf[2];
p = *which_path;
- /* FIXME: we should use realpath() or its work-alike
- before comparing. Then all the code above which
- removes excess slashes and dots could simply go away. */
- if (!filename_cmp (p, name))
+ while (1)
{
- /* Found it in the search path, remove old copy. */
- if (p > *which_path)
- p--; /* Back over leading separator. */
- if (prefix > p - *which_path)
- goto skip_dup; /* Same dir twice in one cmd. */
- memmove (p, &p[len + 1], strlen (&p[len + 1]) + 1); /* Copy from next \0 or : */
+ /* FIXME: we should use realpath() or its work-alike
+ before comparing. Then all the code above which
+ removes excess slashes and dots could simply go away. */
+ if (!filename_ncmp (p, name, len)
+ && (p[len] == '\0' || p[len] == DIRNAME_SEPARATOR))
+ {
+ /* Found it in the search path, remove old copy. */
+ if (p > *which_path)
+ /* Back over leading separator. */
+ p--;
+ if (prefix > p - *which_path)
+ /* Same dir twice in one cmd. */
+ goto skip_dup;
+ /* Copy from next '\0' or ':'. */
+ memmove (p, &p[len + 1], strlen (&p[len + 1]) + 1);
+ }
+ p = strchr (p, DIRNAME_SEPARATOR);
+ if (p != 0)
+ ++p;
+ else
+ break;
}
tinybuf[0] = DIRNAME_SEPARATOR;
--
1.7.9.5