* [PATCH v5] gdb: set filename-display shortpath support
@ 2013-12-09 21:21 Azat Khuzhin
2013-12-10 21:04 ` Tom Tromey
0 siblings, 1 reply; 4+ messages in thread
From: Azat Khuzhin @ 2013-12-09 21:21 UTC (permalink / raw)
To: gdb-patches; +Cc: eliz, brobecker, palves, Azat Khuzhin
Display only non-common part of filename and compilation directory
This will be useful for projects that use separate build directory
inside project (like build/cmake and others).
gdb/ChangeLog
2013-12-00 Azat Khuzhin <a3at.mail@gmail.com>
* source.h (symtab_to_shortpath): Add it.
* source.c (filename_display): Add shortpath display.
* (symtab_to_filename_for_display): Use symtab_to_shortpath.
---
V2: fixed coding style issues (thanks to Joel)
V3: fixed typo in initial condition for symtab_to_shortpath
V4: add changelog into message (lost because of --annotate)
V5: use helpers from filenames.h instead of strncmp and SLASH_STRING.
(Thanks to Eli, who pointed me out to this.)
gdb/source.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++---
gdb/source.h | 3 +++
2 files changed, 54 insertions(+), 3 deletions(-)
diff --git a/gdb/source.c b/gdb/source.c
index 6234bfc..0ea3f88 100644
--- a/gdb/source.c
+++ b/gdb/source.c
@@ -111,11 +111,13 @@ show_lines_to_list (struct ui_file *file, int from_tty,
static const char filename_display_basename[] = "basename";
static const char filename_display_relative[] = "relative";
static const char filename_display_absolute[] = "absolute";
+static const char filename_display_shortpath[] = "shortpath";
static const char *const filename_display_kind_names[] = {
filename_display_basename,
filename_display_relative,
filename_display_absolute,
+ filename_display_shortpath,
NULL
};
@@ -1137,6 +1139,48 @@ symtab_to_fullname (struct symtab *s)
/* See commentary in source.h. */
const char *
+symtab_to_shortpath (struct symtab *symtab)
+{
+ const char *prev_slash_name = symtab->filename;
+ const char *prev_slash_dir = symtab->dirname;
+ const char *slash_name = symtab->filename;
+ const char *slash_dir = symtab->dirname;
+ const char *shortpath = slash_name;
+
+ if (slash_dir == NULL)
+ return shortpath;
+
+ for (; *slash_name && *slash_dir; slash_name++, slash_dir++)
+ {
+ size_t min_part_len;
+
+ if (IS_DIR_SEPARATOR (*slash_name) != IS_DIR_SEPARATOR (*slash_dir))
+ break;
+ if (!IS_DIR_SEPARATOR (*slash_name))
+ continue;
+
+ ++slash_name;
+ ++slash_dir;
+ if (!*slash_name || !*slash_dir)
+ break;
+
+ min_part_len = min (slash_name - prev_slash_name,
+ slash_dir - prev_slash_dir);
+ if (filename_ncmp (slash_name, slash_dir, min_part_len))
+ break;
+
+ shortpath = slash_name;
+
+ prev_slash_name = slash_name;
+ prev_slash_dir = slash_dir;
+ }
+
+ return shortpath;
+}
+
+/* See commentary in source.h. */
+
+const char *
symtab_to_filename_for_display (struct symtab *symtab)
{
if (filename_display_string == filename_display_basename)
@@ -1145,6 +1189,8 @@ symtab_to_filename_for_display (struct symtab *symtab)
return symtab_to_fullname (symtab);
else if (filename_display_string == filename_display_relative)
return symtab->filename;
+ else if (filename_display_string == filename_display_shortpath)
+ return symtab_to_shortpath (symtab);
else
internal_error (__FILE__, __LINE__, _("invalid filename_display_string"));
}
@@ -2093,9 +2139,11 @@ is not specified, print all substitution rules."),
Set how to display filenames."), _("\
Show how to display filenames."), _("\
filename-display can be:\n\
- basename - display only basename of a filename\n\
- relative - display a filename relative to the compilation directory\n\
- absolute - display an absolute filename\n\
+ basename - display only basename of a filename\n\
+ relative - display a filename relative to the compilation directory\n\
+ absolute - display an absolute filename\n\
+ shortpath - display only non-common part of filenames and compilation \
+directory\n\
By default, relative filenames are displayed."),
NULL,
show_filename_display_string,
diff --git a/gdb/source.h b/gdb/source.h
index 33cad09..79e3565 100644
--- a/gdb/source.h
+++ b/gdb/source.h
@@ -52,6 +52,9 @@ extern char *rewrite_source_path (const char *path);
extern const char *symtab_to_fullname (struct symtab *s);
+/* Returns only non-common part of filename and compilation directory. */
+extern const char *symtab_to_shortpath(struct symtab *symtab);
+
/* Returns filename without the compile directory part, basename or absolute
filename. It depends on 'set filename-display' value. */
extern const char *symtab_to_filename_for_display (struct symtab *symtab);
--
1.8.4.3
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH v5] gdb: set filename-display shortpath support
2013-12-09 21:21 [PATCH v5] gdb: set filename-display shortpath support Azat Khuzhin
@ 2013-12-10 21:04 ` Tom Tromey
2013-12-10 21:23 ` Azat Khuzhin
0 siblings, 1 reply; 4+ messages in thread
From: Tom Tromey @ 2013-12-10 21:04 UTC (permalink / raw)
To: Azat Khuzhin; +Cc: gdb-patches, eliz, brobecker, palves
>>>>> "Azat" == Azat Khuzhin <a3at.mail@gmail.com> writes:
Azat> Display only non-common part of filename and compilation directory
Azat> This will be useful for projects that use separate build directory
Azat> inside project (like build/cmake and others).
Thanks for doing this.
Azat> 2013-12-00 Azat Khuzhin <a3at.mail@gmail.com>
Azat> * source.h (symtab_to_shortpath): Add it.
Azat> * source.c (filename_display): Add shortpath display.
Azat> * (symtab_to_filename_for_display): Use symtab_to_shortpath.
That final line doesn't need the "* ".
Silly ChangeLogs.
I think this patch needs at least a documentation patch and a NEWS
entry.
A test case would be nice, an addition to an existing test would be
sufficient.
Do you have copyright assignment paperwork in place?
If not then please contact me off-list so I can get you started.
Azat> +/* Returns only non-common part of filename and compilation directory. */
Azat> +extern const char *symtab_to_shortpath(struct symtab *symtab);
Space before the open paren here.
Tom
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v5] gdb: set filename-display shortpath support
2013-12-10 21:04 ` Tom Tromey
@ 2013-12-10 21:23 ` Azat Khuzhin
2013-12-10 21:50 ` Tom Tromey
0 siblings, 1 reply; 4+ messages in thread
From: Azat Khuzhin @ 2013-12-10 21:23 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches, Eli Zaretskii, Joel Brobecker, Pedro Alves
On Wed, Dec 11, 2013 at 1:04 AM, Tom Tromey <tromey@redhat.com> wrote:
>>>>>> "Azat" == Azat Khuzhin <a3at.mail@gmail.com> writes:
>
> Azat> Display only non-common part of filename and compilation directory
> Azat> This will be useful for projects that use separate build directory
> Azat> inside project (like build/cmake and others).
>
> Thanks for doing this.
>
> Azat> 2013-12-00 Azat Khuzhin <a3at.mail@gmail.com>
> Azat> * source.h (symtab_to_shortpath): Add it.
> Azat> * source.c (filename_display): Add shortpath display.
> Azat> * (symtab_to_filename_for_display): Use symtab_to_shortpath.
>
> That final line doesn't need the "* ".
> Silly ChangeLogs.
>
> I think this patch needs at least a documentation patch and a NEWS
> entry.
Should I do this? If yes, into which file I must add this info?
>
> A test case would be nice, an addition to an existing test would be
> sufficient.
I will add it later.
>
> Do you have copyright assignment paperwork in place?
Yes, I already sign it.
> If not then please contact me off-list so I can get you started.
>
> Azat> +/* Returns only non-common part of filename and compilation directory. */
> Azat> +extern const char *symtab_to_shortpath(struct symtab *symtab);
>
> Space before the open paren here.
Oh, sorry. Fixed in new patch.
I will resent the patch with coding style fixes.
Thanks!
>
> Tom
--
Respectfully
Azat Khuzhin
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-12-10 21:50 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-09 21:21 [PATCH v5] gdb: set filename-display shortpath support Azat Khuzhin
2013-12-10 21:04 ` Tom Tromey
2013-12-10 21:23 ` Azat Khuzhin
2013-12-10 21:50 ` Tom Tromey
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox