From: Azat Khuzhin <a3at.mail@gmail.com>
To: gdb-patches@sourceware.org
Cc: Azat Khuzhin <a3at.mail@gmail.com>
Subject: [PATCH] gdb: set filename-display shortpath support
Date: Mon, 09 Dec 2013 09:21:00 -0000 [thread overview]
Message-ID: <1386580852-28006-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).
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)
gdb/source.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++---
gdb/source.h | 3 +++
2 files changed, 52 insertions(+), 3 deletions(-)
diff --git a/gdb/source.c b/gdb/source.c
index 6234bfc..2caeb32 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,46 @@ symtab_to_fullname (struct symtab *s)
/* See commentary in source.h. */
const char *
+symtab_to_shortpath (struct symtab *symtab)
+{
+ char *prev_slash_name = (char *) symtab->filename;
+ char *prev_slash_dir = (char *) symtab->dirname;
+ char *slash_name = (char *) symtab->filename;
+ char *slash_dir = (char *) symtab->dirname;
+ const char *shortpath = slash_name;
+
+ if (slash_dir == NULL)
+ return shortpath;
+
+ for (;;)
+ {
+ size_t min_part_len;
+
+ slash_name = strstr (slash_name, SLASH_STRING);
+ slash_dir = strstr (slash_dir, SLASH_STRING);
+ if (slash_name == NULL || slash_dir == NULL)
+ break;
+
+ slash_name++;
+ slash_dir++;
+
+ min_part_len = min (slash_name - prev_slash_name,
+ slash_dir - prev_slash_dir);
+ if (strncmp (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 +1187,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 +2137,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 filename 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
next reply other threads:[~2013-12-09 9:21 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-09 9:21 Azat Khuzhin [this message]
-- strict thread matches above, loose matches on Subject: below --
2013-12-09 9:01 Azat Khuzhin
2013-12-09 16:34 ` Eli Zaretskii
2013-12-09 21:25 ` Azat Khuzhin
2013-12-09 8:55 Azat Khuzhin
2013-12-08 21:29 Azat Khuzhin
2013-12-09 8:32 ` Joel Brobecker
2013-12-09 9:02 ` Azat Khuzhin
2013-12-09 13:04 ` Pedro Alves
2013-12-09 13:24 ` 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=1386580852-28006-1-git-send-email-a3at.mail@gmail.com \
--to=a3at.mail@gmail.com \
--cc=gdb-patches@sourceware.org \
/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