This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH v6] gdb: set filename-display shortpath support
- From: Azat Khuzhin <a3at dot mail at gmail dot com>
- To: gdb-patches at sourceware dot org
- Cc: tromey at redhat dot com, eliz at gnu dot org, brobecker at adacore dot com, palves at redhat dot com, Azat Khuzhin <a3at dot mail at gmail dot com>
- Date: Wed, 11 Dec 2013 01:26:04 +0400
- Subject: [PATCH v6] gdb: set filename-display shortpath support
- Authentication-results: sourceware.org; auth=none
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.)
V6: conding style fixed in changelog and header file (thanks to Tom)
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..b94c88f 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