Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: iam ahal <hal9000ed2k@gmail.com>
To: Tom Tromey <tromey@redhat.com>
Cc: Eli Zaretskii <eliz@gnu.org>,
	Jan Kratochvil <jan.kratochvil@redhat.com>,
	palves@redhat.com, 	dje@google.com, gdb-patches@sourceware.org,
	pmuldoon@redhat.com, 	brobecker@adacore.com, drow@false.org,
	asmwarrior <asmwarrior@gmail.com>
Subject: Re: [patch] GDB 7.2: new feature for "backtrace" that cuts path to file (remain filename)
Date: Sun, 18 Mar 2012 18:30:00 -0000	[thread overview]
Message-ID: <CAA18ubJ0X4_VS0UjJ2DGx3zMd7ynMw_dg3Eti99O+X4+3dF6hQ@mail.gmail.com> (raw)
In-Reply-To: <20120315224504.GA24829@host2.jankratochvil.net>

[-- Attachment #1: Type: text/plain, Size: 573 bytes --]

I've fixed patch and news carefully by your notes.

To Jan Kratochvil, Yuanhui Zhang:

I've included absolute filename option to my patch.
	
Eli Zaretskii:

Here is an example of working with "relative filename" option:

$ gcc -Wall -g ~/Downloads/contrib/prog.c
$ ./gdb-7.4/gdb/gdb ./a.out

(gdb) backtrace
#0  main () at /home/unknown/Downloads/contrib/prog.c:3
(gdb) set backtrace filename-display relative
(gdb) backtrace
#0  main () at prog.c:3

As I remember the difference between "basename" and "relative" option
was explained some time ago in this thread.

~Eldar

[-- Attachment #2: ChangeLog --]
[-- Type: application/octet-stream, Size: 796 bytes --]

2011-10-30  Eldar Gaynetdinov <hal9000ed2k@gmail.com>

	Add a new variable that controls a way in which filenames in
	backtraces is displayed.
	* frame.c: Added including of a header file.
	(filename_display_full): New global variable.
	(filename_display_basename): New global variable.
	(filename_display_without_comp_directory): New global variable.
	(filename_display_kind_names): New global array.
	(show_filename_display_string): New function.
	(get_filename_display_from_sal): New function.
	(_initialize_frame): Added initialization of 'filename-display'
	variable.
	* frame.h (get_filename_display_from_sal): Added declaration.
	* stack.c (print_frame): Added new variable and calling of a new
	function and condition with this variable. Changed third argument of
	calling of a function.

[-- Attachment #3: ChangeLog-doc --]
[-- Type: application/octet-stream, Size: 166 bytes --]

2011-10-30  Eldar Gaynetdinov <hal9000ed2k@gmail.com>

	* gdb.texinfo (Backtrace): Added description of 'filename-display'
	variable in 'set/show backtrace' section.

[-- Attachment #4: gdb-filename-display.patch --]
[-- Type: text/x-patch, Size: 6730 bytes --]

diff -rup gdb-7.4-orig/gdb/doc/gdb.texinfo gdb-7.4/gdb/doc/gdb.texinfo
--- gdb-7.4-orig/gdb/doc/gdb.texinfo	2012-01-06 08:43:35.000000000 +0400
+++ gdb-7.4/gdb/doc/gdb.texinfo	2012-03-18 22:00:06.259580346 +0400
@@ -6191,6 +6191,29 @@ unlimited.
 Display the current limit on backtrace levels.
 @end table
 
+If backtraces isn't easy to read due to a long absolute filename record and
+you just want to see only a basename or a relative filename,
+you can change this behavior:
+
+@table @code
+@item set backtrace filename-display
+@itemx set backtrace filename-display as-recorded
+@cindex backtrace filename-display
+Display a filename exactly as recorded at compile time.  This is the default.
+
+@item set backtrace filename-display basename
+Display only basename of a filename.
+
+@item set backtrace filename-display relative
+Display a filename without the compilation directory part.
+
+@item set backtrace filename-display absolute
+Display an absolute filename.
+
+@item show backtrace filename-display
+Show the current way to display a filename in backtraces.
+@end table
+
 @node Selection
 @section Selecting a Frame
 
diff -rup gdb-7.4-orig/gdb/frame.c gdb-7.4/gdb/frame.c
--- gdb-7.4-orig/gdb/frame.c	2012-01-06 08:43:12.000000000 +0400
+++ gdb-7.4/gdb/frame.c	2012-03-18 22:00:06.259580346 +0400
@@ -43,7 +43,9 @@
 #include "gdbthread.h"
 #include "block.h"
 #include "inline-frame.h"
-#include  "tracepoint.h"
+#include "tracepoint.h"
+#include "filenames.h"
+#include "source.h"
 
 static struct frame_info *get_prev_frame_1 (struct frame_info *this_frame);
 static struct frame_info *get_prev_frame_raw (struct frame_info *this_frame);
@@ -135,6 +137,20 @@ struct frame_info
    sufficient for now.  */
 static struct frame_info *frame_stash = NULL;
 
+/* Possible values of 'set backtrace filename-display'.  */
+static const char filename_display_as_recorded[] = "as-recorded";
+static const char filename_display_basename[] = "basename";
+static const char filename_display_relative_directory[] = "relative";
+static const char filename_display_absolute[] = "absolute";
+
+static const char *const filename_display_kind_names[] = {
+  filename_display_as_recorded,
+  filename_display_basename,
+  filename_display_relative_directory,
+  filename_display_absolute,
+  NULL
+};
+
 /* Add the following FRAME to the frame stash.  */
 
 static void
@@ -207,6 +223,16 @@ show_backtrace_limit (struct ui_file *fi
 		    value);
 }
 
+static const char *filename_display_string = filename_display_as_recorded;
+
+static void
+show_filename_display_string (struct ui_file *file, int from_tty,
+			      struct cmd_list_element *c, const char *value)
+{
+  fprintf_filtered (file,
+		    _("A filename is displayed in backtrace as \"%s\".\n"),
+		    value);
+}
 
 static void
 fprint_field (struct ui_file *file, const char *name, int p, CORE_ADDR addr)
@@ -2118,6 +2144,45 @@ find_frame_sal (struct frame_info *frame
   (*sal) = find_pc_line (pc, notcurrent);
 }
 
+/* See commentary in frame.h.  */
+
+const char *
+get_filename_display_from_sal (const struct symtab_and_line *sal)
+{
+  const char *filename = sal->symtab->filename;
+  const char *dirname = sal->symtab->dirname;
+  size_t dlen = dirname ? strlen (dirname) : 0;
+
+  if (filename == NULL)
+      return NULL;
+  else if (filename_display_string == filename_display_basename)
+      return lbasename (filename);
+  else if (filename_display_string == filename_display_relative_directory
+	   && dirname && dlen && dlen <= strlen (filename)
+	   && !filename_ncmp (filename, dirname, dlen))
+    {
+      const char *start = filename + dlen;
+      const char *result = start;
+
+      while (IS_DIR_SEPARATOR (*result))
+	result++;
+
+      if (IS_DIR_SEPARATOR (dirname[dlen - 1]))
+	return result;
+      else
+	return result == start ? filename : result;
+    }
+  else if (filename_display_string == filename_display_absolute)
+    {
+      const char *retval = symtab_to_fullname (sal->symtab);
+
+      if (retval != NULL)
+	return retval;
+    }
+
+  return filename;
+}
+
 /* Per "frame.h", return the ``address'' of the frame.  Code should
    really be using get_frame_id().  */
 CORE_ADDR
@@ -2477,6 +2542,22 @@ Zero is unlimited."),
 			   &set_backtrace_cmdlist,
 			   &show_backtrace_cmdlist);
 
+  add_setshow_enum_cmd ("filename-display", class_obscure,
+			filename_display_kind_names,
+			&filename_display_string, _("\
+Set how to display filenames in backtraces."), _("\
+Show how to display filenames in backtraces."), _("\
+filename-display can be:\n\
+  as-recorded    - display a filename exactly as recorded at compile time\n\
+  basename       - display only basename of a filename\n\
+  relative       - display a filename without the compilation directory part\n\
+  absolute       - display an absolute filename\n\
+By default, as-recorded filename is displayed."),
+			NULL,
+			show_filename_display_string,
+			&set_backtrace_cmdlist,
+			&show_backtrace_cmdlist);
+
   /* Debug this files internals.  */
   add_setshow_zinteger_cmd ("frame", class_maintenance, &frame_debug,  _("\
 Set frame debugging."), _("\
diff -rup gdb-7.4-orig/gdb/frame.h gdb-7.4/gdb/frame.h
--- gdb-7.4-orig/gdb/frame.h	2012-01-06 08:43:12.000000000 +0400
+++ gdb-7.4/gdb/frame.h	2012-03-18 22:00:06.259580346 +0400
@@ -353,6 +353,13 @@ extern int get_frame_func_if_available (
 extern void find_frame_sal (struct frame_info *frame,
 			    struct symtab_and_line *sal);
 
+/* Returns either exactly as recorded filename or basename or filename
+   without the compile directory part or absolute filename.
+   It depends on 'set backtrace filename-display' value.  */
+
+extern const char *
+get_filename_display_from_sal (const struct symtab_and_line *sal);
+
 /* Set the current source and line to the location given by frame
    FRAME, if possible.  When CENTER is true, adjust so the relevant
    line is in the center of the next 'list'.  */
diff -rup gdb-7.4-orig/gdb/stack.c gdb-7.4/gdb/stack.c
--- gdb-7.4-orig/gdb/stack.c	2012-01-06 08:43:31.000000000 +0400
+++ gdb-7.4/gdb/stack.c	2012-03-18 22:01:04.115579942 +0400
@@ -1173,11 +1173,13 @@ print_frame (struct frame_info *frame, i
   ui_out_text (uiout, ")");
   if (sal.symtab && sal.symtab->filename)
     {
+      const char *filename_display = get_filename_display_from_sal (&sal);
+
       annotate_frame_source_begin ();
       ui_out_wrap_hint (uiout, "   ");
       ui_out_text (uiout, " at ");
       annotate_frame_source_file ();
-      ui_out_field_string (uiout, "file", sal.symtab->filename);
+      ui_out_field_string (uiout, "file", filename_display);
       if (ui_out_is_mi_like_p (uiout))
 	{
 	  const char *fullname = symtab_to_fullname (sal.symtab);

[-- Attachment #5: NEWS --]
[-- Type: application/octet-stream, Size: 173 bytes --]

* New options

set backtrace filename-display as-recorded|basename|relative
show backtrace filename-display
  Control the way in which filenames is displayed in backtraces.

  reply	other threads:[~2012-03-18 18:30 UTC|newest]

Thread overview: 69+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-26 20:00 iam ahal
2011-06-26 20:49 ` Phil Muldoon
2011-06-27 16:00   ` Joel Brobecker
2011-06-27 16:18     ` Phil Muldoon
2011-06-28 20:08     ` Tom Tromey
2011-06-28 22:36       ` Phil Muldoon
2011-07-03 18:12         ` iam ahal
2011-07-03 21:13           ` Eli Zaretskii
2011-07-04 11:26             ` iam ahal
2011-07-04 12:05               ` Eli Zaretskii
2011-07-04 21:47                 ` Joel Brobecker
2011-07-05  4:35                   ` Eli Zaretskii
2011-07-19 14:43                     ` Pedro Alves
2011-07-05  8:38                   ` iam ahal
2011-07-19 14:19                   ` Pedro Alves
2011-07-17 19:24                 ` iam ahal
2011-07-19 13:28                   ` iam ahal
2011-07-19 17:04                     ` Eli Zaretskii
2011-07-24 21:12                       ` iam ahal
2011-07-26 14:17                         ` iam ahal
2011-07-28 15:34                         ` Tom Tromey
2011-07-28 15:57                           ` Tom Tromey
2011-07-28 16:36                             ` Joel Brobecker
2011-07-28 17:39                               ` Tom Tromey
2011-07-28 17:51                           ` Tom Tromey
2011-07-29 12:01                             ` Joel Brobecker
2011-07-29 12:36                             ` Eli Zaretskii
2011-08-02 19:41                           ` iam ahal
2011-08-03 17:45                             ` Tom Tromey
2011-10-30 19:52                               ` iam ahal
2011-11-02 19:06                                 ` Tom Tromey
2011-11-02 22:53                                 ` Doug Evans
2011-12-04 15:52                                   ` iam ahal
2011-12-04 16:55                                     ` Eli Zaretskii
2011-12-04 18:41                                       ` iam ahal
2011-12-04 19:01                                         ` Pedro Alves
2011-12-04 19:56                                           ` Eli Zaretskii
2011-12-04 21:00                                             ` Pedro Alves
2011-12-05  3:54                                               ` Eli Zaretskii
2011-12-05  5:17                                                 ` Eli Zaretskii
2011-12-06 13:03                                                   ` Pedro Alves
2011-12-06 14:04                                                     ` Eli Zaretskii
2011-12-06 18:00                                                       ` Doug Evans
2011-12-06 20:45                                                       ` Tom Tromey
2011-12-07  8:00                                                         ` Eli Zaretskii
2012-03-10 20:15                                                           ` iam ahal
2012-03-11  1:22                                                             ` asmwarrior
2012-03-12 13:10                                                               ` iam ahal
2012-03-14 16:11                                                             ` Tom Tromey
2012-03-14 16:27                                                             ` Jan Kratochvil
2012-03-14 17:40                                                             ` Eli Zaretskii
2012-03-15 22:46                                                             ` Jan Kratochvil
2012-03-18 18:30                                                               ` iam ahal [this message]
2012-03-18 18:35                                                                 ` Jan Kratochvil
2012-04-06 14:22                                                                   ` Jan Kratochvil
2012-03-18 20:46                                                                 ` Eli Zaretskii
2012-03-25 19:27                                                                   ` iam ahal
2012-03-25 19:31                                                                     ` Jan Kratochvil
2012-03-25 21:23                                                                     ` Eli Zaretskii
2011-12-06 12:50                                                 ` Pedro Alves
2011-12-06 20:40                                     ` Tom Tromey
2011-12-06 23:02                                     ` Jan Kratochvil
2011-07-29 13:35                         ` Jan Kratochvil
2011-08-01 18:04                           ` Tom Tromey
2011-06-29 10:09       ` Andrew Burgess
2011-06-29 16:06       ` Joel Brobecker
2011-07-03 18:15     ` Daniel Jacobowitz
2011-06-28 20:08   ` Tom Tromey
2012-04-09 15:39 ` Jan Kratochvil

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=CAA18ubJ0X4_VS0UjJ2DGx3zMd7ynMw_dg3Eti99O+X4+3dF6hQ@mail.gmail.com \
    --to=hal9000ed2k@gmail.com \
    --cc=asmwarrior@gmail.com \
    --cc=brobecker@adacore.com \
    --cc=dje@google.com \
    --cc=drow@false.org \
    --cc=eliz@gnu.org \
    --cc=gdb-patches@sourceware.org \
    --cc=jan.kratochvil@redhat.com \
    --cc=palves@redhat.com \
    --cc=pmuldoon@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