gdb/source.c: Fix matching path substitute rule listing
Commit Message
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 (or NULL). 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)
Also included is a couple of tests added to subst.exp to verify this behavior
in the test suite.
2014-05-28 Brad Mouring <brad.mouring@ni.com>
* source.c (show_substitute_path_command): Fix display of matching
substitution rules
* subst.exp: Add tests to verify changes in source.c
---
gdb/source.c | 4 +++-
gdb/testsuite/gdb.base/subst.exp | 8 ++++++++
2 files changed, 11 insertions(+), 1 deletion(-)
Comments
Hi Brad,
> 2014-05-28 Brad Mouring <brad.mouring@ni.com>
>
> * source.c (show_substitute_path_command): Fix display of matching
> substitution rules
> * subst.exp: Add tests to verify changes in source.c
Much better, thank you!
You are still missing a couple of elements:
* You patch needs two ChangeLog entries, one in gdb/ChangeLog,
and one in gdb/testsuite/ChangeLog. The revision log should
have both at the end. Here is an example of another patch
where both GDB and testsuite where changed thus resulting
in 2 CL entries: 938f0e2f6766e90a5ddc5df00e97a68873fd1252
* You forgot to tell us on which platform you tested your patch.
Comment about the patch itself below...
Please don't be discouraged, you have very close to getting it in!
> ---
> gdb/source.c | 4 +++-
> gdb/testsuite/gdb.base/subst.exp | 8 ++++++++
> 2 files changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/gdb/source.c b/gdb/source.c
> index c112765..240062c 100644
> --- a/gdb/source.c
> +++ b/gdb/source.c
> @@ -1857,6 +1857,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);
> @@ -1879,7 +1880,8 @@ 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 || substitute_path_rule_matches (rule, from) != 0)
> printf_filtered (" `%s' -> `%s'.\n", rule->from, rule->to);
> rule = rule->next;
You do not need "rule_from_len" anymore. The final patch for this file
should be a one-line change.
@@ -1857,6 +1857,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);
@@ -1879,7 +1880,8 @@ 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 || substitute_path_rule_matches (rule, from) != 0)
printf_filtered (" `%s' -> `%s'.\n", rule->from, rule->to);
rule = rule->next;
}
@@ -95,6 +95,14 @@ gdb_test "show substitute-path depuis" \
"Source path substitution rule matching `depuis':\r\n +`depuis' -> `vers'." \
"show substitute-path depuis, after all paths added"
+gdb_test "show substitute-path from/path" \
+ "Source path substitution rule matching `from/path':\r\n +`from' -> `to'." \
+ "show substitute-path from/path, after all paths added"
+
+gdb_test "show substitute-path from_a_bad_path" \
+ "Source path substitution rule matching `from_a_bad_path':" \
+ "show substitute-path from_a_bad_path, after all paths added"
+
gdb_test "show substitute-path garbage" \
"Source path substitution rule matching `garbage':" \
"show substitute-path garbage, after all paths added"