[PATCH 2/2] gdb/source.c: Fix matching path substitute rule listing
Brad Mouring
bmouring@ni.com
Wed May 28 22:42:00 GMT 2014
The check for the source (or "from") directory snippet in listing
matching path substitution rules currently will not match anything
other than a direct match of the "from" field in a substitution rule,
resulting in the incorrect behavior below
...
(gdb) set substitute-path /a/path /another/path
(gdb) show substitute-path
List of all source path substitution rules:
`/a/path' -> `/another/path'.
(gdb) show substitute-path /a/path/to/a/file.ext
Source path substitution rule matching `/a/path/to/a/file.ext':
(gdb) show substitute-path /a/path
Source path substitution rule matching `/a/path':
`/a/path' -> `/another/path'.
...
This change effects the following behavior by (sanely) checking
with the length of the "from" portion of a rule and ensuring that
the next character of the path considered for substitution is a path
delimiter. With this change, the following behavior is garnered
...
(gdb) set substitute-path /a/path /another/path
(gdb) show substitute-path
List of all source path substitution rules:
`/a/path' -> `/another/path'.
(gdb) show substitute-path /a/path/to/a/file.ext
Source path substitution rule matching `/a/path/to/a/file.ext':
`/a/path' -> `/another/path'.
(gdb) show substitute-path /a/pathological/case/that/should/fail.err
Source path substitution rule matching `/a/pathological/case/that/should/fail.err':
(gdb)
Signed-off-by: Brad Mouring <brad.mouring@ni.com>
---
gdb/source.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/gdb/source.c b/gdb/source.c
index c77a4f4..a32872f 100644
--- a/gdb/source.c
+++ b/gdb/source.c
@@ -1875,6 +1875,7 @@ show_substitute_path_command (char *args, int from_tty)
char **argv;
char *from = NULL;
struct cleanup *cleanup;
+ int rule_from_len;
argv = gdb_buildargv (args);
cleanup = make_cleanup_freeargv (argv);
@@ -1897,7 +1898,11 @@ show_substitute_path_command (char *args, int from_tty)
while (rule != NULL)
{
- if (from == NULL || FILENAME_CMP (rule->from, from) == 0)
+ rule_from_len = strlen(rule->from);
+ if (from == NULL ||
+ ((filename_ncmp (rule->from, from, rule_from_len) == 0) &&
+ (IS_DIR_SEPARATOR (from[rule_from_len]) ||
+ from[rule_from_len] == 0)))
printf_filtered (" `%s' -> `%s'.\n", rule->from, rule->to);
rule = rule->next;
}
--
1.8.3-rc3
More information about the Gdb-patches
mailing list