public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb: set filename-display shortpath support
@ 2013-12-09  8:55 Azat Khuzhin
  0 siblings, 0 replies; 10+ messages in thread
From: Azat Khuzhin @ 2013-12-09  8:55 UTC (permalink / raw)
  To: gdb-patches; +Cc: 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).
---
V2: fixed coding style issues (thanks to Joel)

 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..5b03e29 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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] gdb: set filename-display shortpath support
  2013-12-09 16:34 ` Eli Zaretskii
@ 2013-12-09 21:25   ` Azat Khuzhin
  0 siblings, 0 replies; 10+ messages in thread
From: Azat Khuzhin @ 2013-12-09 21:25 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: gdb-patches

On Mon, Dec 9, 2013 at 8:33 PM, Eli Zaretskii <eliz@gnu.org> wrote:
>> From: Azat Khuzhin <a3at.mail@gmail.com>
>> Cc: Azat Khuzhin <a3at.mail@gmail.com>
>> Date: Mon,  9 Dec 2013 13:01:36 +0400
>>
>> Display only non-common part of filename and compilation directory
>
> Thanks.
>
>> +  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;
>
> It is wrong to use SLASH_STRING to search for directory separators;
> that is non-portable.  SLASH_STRING is for constructing file names
> from directories and the basename.
>
> To look for directory separators, please use lbasename, ldirname, or
> similar functions, which already know about possible separators on
> each supported platform.

Now i see that SLASH_STRING can have only '/' value.
So I replaced it by IS_DIR_SEPARATOR in v5 patch.
Thanks.

>
>> @@ -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\
>
> This should use "filenames", not "a filename", since the option
> affects any displayed file name, not just one of them.

Agree.

>
>>  By default, relative filenames are displayed."),
>
> This is ambiguous.  I suggest to say "The default is \"relative\"."

I think that this is not part of "shortpath" patch, I can another one to fix it.

>
> Sorry for not paying attention when you first posted the patch.

No problems. Thanks.



-- 
Respectfully
Azat Khuzhin

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] gdb: set filename-display shortpath support
  2013-12-09  9:01 Azat Khuzhin
@ 2013-12-09 16:34 ` Eli Zaretskii
  2013-12-09 21:25   ` Azat Khuzhin
  0 siblings, 1 reply; 10+ messages in thread
From: Eli Zaretskii @ 2013-12-09 16:34 UTC (permalink / raw)
  To: Azat Khuzhin; +Cc: gdb-patches

> From: Azat Khuzhin <a3at.mail@gmail.com>
> Cc: Azat Khuzhin <a3at.mail@gmail.com>
> Date: Mon,  9 Dec 2013 13:01:36 +0400
> 
> Display only non-common part of filename and compilation directory

Thanks.

> +  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;

It is wrong to use SLASH_STRING to search for directory separators;
that is non-portable.  SLASH_STRING is for constructing file names
from directories and the basename.

To look for directory separators, please use lbasename, ldirname, or
similar functions, which already know about possible separators on
each supported platform.

> @@ -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\

This should use "filenames", not "a filename", since the option
affects any displayed file name, not just one of them.

>  By default, relative filenames are displayed."),

This is ambiguous.  I suggest to say "The default is \"relative\"."

Sorry for not paying attention when you first posted the patch.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] gdb: set filename-display shortpath support
  2013-12-09 13:04     ` Pedro Alves
@ 2013-12-09 13:24       ` Azat Khuzhin
  0 siblings, 0 replies; 10+ messages in thread
From: Azat Khuzhin @ 2013-12-09 13:24 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Joel Brobecker, gdb-patches

On Mon, Dec 9, 2013 at 5:03 PM, Pedro Alves <palves@redhat.com> wrote:
> On 12/09/2013 09:02 AM, Azat Khuzhin wrote:
>> Thanks for you review.
>> I resent new patch with coding style issues resolved. (V2)
>
> If there will be further versions, please identify the patch
> version in the subject line too: e.g., [PATCH v5].  It gets
> confusing to have several similar threads with the same
> subject.

Sure, will do.
BTW, the latest patch version now is V4.

>
> Thanks!
>
> --
> Pedro Alves
>



-- 
Respectfully
Azat Khuzhin

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] gdb: set filename-display shortpath support
  2013-12-09  9:02   ` Azat Khuzhin
@ 2013-12-09 13:04     ` Pedro Alves
  2013-12-09 13:24       ` Azat Khuzhin
  0 siblings, 1 reply; 10+ messages in thread
From: Pedro Alves @ 2013-12-09 13:04 UTC (permalink / raw)
  To: Azat Khuzhin; +Cc: Joel Brobecker, gdb-patches

On 12/09/2013 09:02 AM, Azat Khuzhin wrote:
> Thanks for you review.
> I resent new patch with coding style issues resolved. (V2)

If there will be further versions, please identify the patch
version in the subject line too: e.g., [PATCH v5].  It gets
confusing to have several similar threads with the same
subject.

Thanks!

-- 
Pedro Alves

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH] gdb: set filename-display shortpath support
@ 2013-12-09  9:21 Azat Khuzhin
  0 siblings, 0 replies; 10+ messages in thread
From: Azat Khuzhin @ 2013-12-09  9:21 UTC (permalink / raw)
  To: gdb-patches; +Cc: 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)

 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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] gdb: set filename-display shortpath support
  2013-12-09  8:32 ` Joel Brobecker
@ 2013-12-09  9:02   ` Azat Khuzhin
  2013-12-09 13:04     ` Pedro Alves
  0 siblings, 1 reply; 10+ messages in thread
From: Azat Khuzhin @ 2013-12-09  9:02 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: gdb-patches

On Mon, Dec 9, 2013 at 12:32 PM, Joel Brobecker <brobecker@adacore.com> wrote:
> Hello,
>
> Thanks for the patch. I've only had a chance to scan the patch, so
> cannot comment deeply. But I can make a few comments...

Thanks for you review.
I resent new patch with coding style issues resolved. (V2)

>
>> +2013-12-00  Azat Khuzhin  <a3at.mail@gmail.com>
>> +
>> +     * source.h (symtab_to_shortpath): Add it.
>> +     * source.c (filename-display): Add shortpath display.
>> +     * source.c (symtab_to_filename_for_display): Use symtab_to_shortpath.
>
> You don't need to repeat the source filename. In your case, the last
> 2 lines of the CL become:
>
>         * source.c (filename_display): Add shortpath display.
>         (symtab_to_filename_for_display): Use symtab_to_shortpath.
>
> Note also the '-' incorrectly used instead of '_' in filename_display.
>
> One small request, also. It's customary to provide the ChangeLog
> as text, rather than make it a ChagneLog diff. If you take a look
> at a few random messages on this list, you'll probably understand.
> ChangeLog files are always getting new changes, and always at the
> same location, thus constantly generating sources of conflicts.
> Unless you have an automated conflict solver in your setup, it's
> fine to send the diff with the ChangeLog in the revision history,
> and then only add the entry just before pushing the change to
> our repository. Tom also posted some tips on how he was managing
> the ChangeLog entries (search for "ChangeLog management tip" in
> the gdb@sourceware.org mailing list archives, Oct 25th 2013).
>
> Overall, I don't remember if other commented, but this sounds like
> a useful idea.
>
>> +#undef MIN
>> +#define MIN(A, B) (((A) <= (B)) ? (A) : (B))
>
> You don't need that. Use "min", defined in defs.h if not already
> defined.

I searched by MIN (case-sensitive) that's why I didn't find it.
Thanks.

>
>> +const char *
>> +symtab_to_shortpath (struct symtab *symtab)
>
> Can you add a small comment explaining that the description of that
> function is in source.h? The usual form is something minimilistic
> such as:
>
> /* See source.h.  */

Forgot that. Thanks.

>
> It just allows us to quickly know that this function is expected to be
> documented elsewhere.
>
>> +  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;
>
> Formatting nit: space after the ')'.
>
>> +  if (!slash_dir)
>> +    return shortpath;
>
> A recent Coding Style decision requires us to explicitly test against
> NULL -> if (slash_dir != NULL)
>
>> +
>> +  while ((slash_name = strstr(slash_name, SLASH_STRING)) &&
>> +         (slash_dir = strstr(slash_dir, SLASH_STRING)))
>
> Formatting nit: binary operators should be at the start of the next
> line, not at the end. Also, make sure to have a space before '('
> in function calls. There are other such violations in the rest of
> the code, which I will not repeat - can you fix the rest as well?
>
> But we also frown on assignments inside conditions. Can you rewrite
> the code to avoid that?
>> +    {
>> +      slash_name++;
>> +      slash_dir++;
>> +
>> +      if (strncmp(slash_name, slash_dir, MIN(slash_name - prev_slash_name, slash_dir - prev_slash_dir)))
>
> This should should be split to not exceed 80 chars (we like a soft limit
> of 70 characters, as long as practical).
>
>> +  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\
>
> This line is a little bit too long. It's a bit of  PIA to be breaking
> it; I think we should do it, for the sake of consistency, but it's not
> a strong opinion.

I think that there is no need in new line for breaking, so I just
break it in code.

>
> --
> Joel



-- 
Respectfully
Azat Khuzhin

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH] gdb: set filename-display shortpath support
@ 2013-12-09  9:01 Azat Khuzhin
  2013-12-09 16:34 ` Eli Zaretskii
  0 siblings, 1 reply; 10+ messages in thread
From: Azat Khuzhin @ 2013-12-09  9:01 UTC (permalink / raw)
  To: gdb-patches; +Cc: 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).
---
V2: fixed coding style issues (thanks to Joel)
V3: fixed typo in initial condition for symtab_to_shortpath

 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..5b03e29 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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] gdb: set filename-display shortpath support
  2013-12-08 21:29 Azat Khuzhin
@ 2013-12-09  8:32 ` Joel Brobecker
  2013-12-09  9:02   ` Azat Khuzhin
  0 siblings, 1 reply; 10+ messages in thread
From: Joel Brobecker @ 2013-12-09  8:32 UTC (permalink / raw)
  To: Azat Khuzhin; +Cc: gdb-patches

Hello,

Thanks for the patch. I've only had a chance to scan the patch, so
cannot comment deeply. But I can make a few comments...

> +2013-12-00  Azat Khuzhin  <a3at.mail@gmail.com>
> +
> +	* source.h (symtab_to_shortpath): Add it.
> +	* source.c (filename-display): Add shortpath display.
> +	* source.c (symtab_to_filename_for_display): Use symtab_to_shortpath.

You don't need to repeat the source filename. In your case, the last
2 lines of the CL become:

	* source.c (filename_display): Add shortpath display.
	(symtab_to_filename_for_display): Use symtab_to_shortpath.

Note also the '-' incorrectly used instead of '_' in filename_display.

One small request, also. It's customary to provide the ChangeLog
as text, rather than make it a ChagneLog diff. If you take a look
at a few random messages on this list, you'll probably understand.
ChangeLog files are always getting new changes, and always at the
same location, thus constantly generating sources of conflicts.
Unless you have an automated conflict solver in your setup, it's
fine to send the diff with the ChangeLog in the revision history,
and then only add the entry just before pushing the change to
our repository. Tom also posted some tips on how he was managing
the ChangeLog entries (search for "ChangeLog management tip" in
the gdb@sourceware.org mailing list archives, Oct 25th 2013).

Overall, I don't remember if other commented, but this sounds like
a useful idea.

> +#undef MIN
> +#define MIN(A, B) (((A) <= (B)) ? (A) : (B))

You don't need that. Use "min", defined in defs.h if not already
defined.

> +const char *
> +symtab_to_shortpath (struct symtab *symtab)

Can you add a small comment explaining that the description of that
function is in source.h? The usual form is something minimilistic
such as:

/* See source.h.  */

It just allows us to quickly know that this function is expected to be
documented elsewhere.

> +  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;

Formatting nit: space after the ')'.

> +  if (!slash_dir)
> +    return shortpath;

A recent Coding Style decision requires us to explicitly test against
NULL -> if (slash_dir != NULL)

> +
> +  while ((slash_name = strstr(slash_name, SLASH_STRING)) &&
> +         (slash_dir = strstr(slash_dir, SLASH_STRING)))

Formatting nit: binary operators should be at the start of the next
line, not at the end. Also, make sure to have a space before '('
in function calls. There are other such violations in the rest of
the code, which I will not repeat - can you fix the rest as well?

But we also frown on assignments inside conditions. Can you rewrite
the code to avoid that?
> +    {
> +      slash_name++;
> +      slash_dir++;
> +
> +      if (strncmp(slash_name, slash_dir, MIN(slash_name - prev_slash_name, slash_dir - prev_slash_dir)))

This should should be split to not exceed 80 chars (we like a soft limit
of 70 characters, as long as practical).

> +  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\

This line is a little bit too long. It's a bit of  PIA to be breaking
it; I think we should do it, for the sake of consistency, but it's not
a strong opinion.

-- 
Joel

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH] gdb: set filename-display shortpath support
@ 2013-12-08 21:29 Azat Khuzhin
  2013-12-09  8:32 ` Joel Brobecker
  0 siblings, 1 reply; 10+ messages in thread
From: Azat Khuzhin @ 2013-12-08 21:29 UTC (permalink / raw)
  To: gdb-patches; +Cc: 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 |  6 ++++++
 gdb/source.c  | 44 +++++++++++++++++++++++++++++++++++++++++---
 gdb/source.h  |  3 +++
 3 files changed, 50 insertions(+), 3 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 788eaab..b098e04 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,9 @@
+2013-12-00  Azat Khuzhin  <a3at.mail@gmail.com>
+
+	* source.h (symtab_to_shortpath): Add it.
+	* source.c (filename-display): Add shortpath display.
+	* source.c (symtab_to_filename_for_display): Use symtab_to_shortpath.
+
 2013-12-08  Joel Brobecker  <brobecker@adacore.com>
 
 	GDB 7.6.2 released.
diff --git a/gdb/source.c b/gdb/source.c
index 6234bfc..505ee7d 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
 };
 
@@ -1134,6 +1136,39 @@ symtab_to_fullname (struct symtab *s)
   return s->fullname;
 }
 
+#undef MIN
+#define MIN(A, B) (((A) <= (B)) ? (A) : (B))
+
+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)
+    return shortpath;
+
+  while ((slash_name = strstr(slash_name, SLASH_STRING)) &&
+         (slash_dir = strstr(slash_dir, SLASH_STRING)))
+    {
+      slash_name++;
+      slash_dir++;
+
+      if (strncmp(slash_name, slash_dir, MIN(slash_name - prev_slash_name, slash_dir - prev_slash_dir)))
+        break;
+
+      shortpath = slash_name;
+
+      prev_slash_name = slash_name;
+      prev_slash_dir = slash_dir;
+    }
+
+  return shortpath;
+}
+
 /* See commentary in source.h.  */
 
 const char *
@@ -1145,6 +1180,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 +2130,10 @@ 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

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2013-12-09 21:25 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-09  8:55 [PATCH] gdb: set filename-display shortpath support Azat Khuzhin
  -- strict thread matches above, loose matches on Subject: below --
2013-12-09  9:21 Azat Khuzhin
2013-12-09  9:01 Azat Khuzhin
2013-12-09 16:34 ` Eli Zaretskii
2013-12-09 21:25   ` 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).