From: Azat Khuzhin <a3at.mail@gmail.com>
To: gdb-patches@sourceware.org
Cc: tromey@redhat.com, eliz@gnu.org, brobecker@adacore.com,
palves@redhat.com, Azat Khuzhin <a3at.mail@gmail.com>
Subject: [PATCH v7] gdb: set filename-display shortpath support
Date: Tue, 10 Dec 2013 22:07:00 -0000 [thread overview]
Message-ID: <1386713214-30200-1-git-send-email-a3at.mail@gmail.com> (raw)
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).
2013-12-00 Azat Khuzhin <a3at.mail@gmail.com>
gdb/ChangeLog
* source.h (symtab_to_shortpath): Add it.
* source.c (filename_display): Add shortpath display.
(symtab_to_filename_for_display): Use symtab_to_shortpath.
* NEWS (set filename-display shortpath): New entry.
gdb/doc/
* gdb.texinfo (Backtrace): Added description of
'filename-display shortpath' in 'set/show backtrace' section.
---
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)
V7: add NEWS and doc.
gdb/NEWS | 5 +++++
gdb/doc/gdb.texinfo | 3 +++
gdb/source.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++---
gdb/source.h | 3 +++
4 files changed, 62 insertions(+), 3 deletions(-)
diff --git a/gdb/NEWS b/gdb/NEWS
index ae84e00..76d8f29 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -3,6 +3,11 @@
*** Changes since GDB 7.6
+* New options
+
+set filename-display shortpath
+ Display only non-common part of filenames and compilation directory.
+
* GDB now supports Fission DWP file format version 2.
http://gcc.gnu.org/wiki/DebugFission
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 87d5145..f26d473 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -6852,6 +6852,9 @@ Display an absolute filename.
@item show filename-display
Show the current way to display filenames.
+
+@item set filename-display shortpath
+Display only non-common part of filenames and compilation directory.
@end table
@node Frame Filter Management
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
next reply other threads:[~2013-12-10 22:07 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-10 22:07 Azat Khuzhin [this message]
2013-12-11 16:31 ` Eli Zaretskii
2013-12-11 18:48 ` Azat Khuzhin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1386713214-30200-1-git-send-email-a3at.mail@gmail.com \
--to=a3at.mail@gmail.com \
--cc=brobecker@adacore.com \
--cc=eliz@gnu.org \
--cc=gdb-patches@sourceware.org \
--cc=palves@redhat.com \
--cc=tromey@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox