Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: iam ahal <hal9000ed2k@gmail.com>
To: gdb-patches@sourceware.org
Cc: eliz@gnu.org, pmuldoon@redhat.com, tromey@redhat.com,
		brobecker@adacore.com, pedro@codesourcery.com, drow@false.org
Subject: Re: [patch] GDB 7.2: new feature for "backtrace" that cuts path to file (remain filename)
Date: Sun, 24 Jul 2011 21:12:00 -0000	[thread overview]
Message-ID: <CAA18ub+ox5kmHu=1qvMkwNfzbCxMdy3M4Z8eKuheaiqyjxJvEg@mail.gmail.com> (raw)
In-Reply-To: <83bowq6x7f.fsf@gnu.org>

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

I've created new patch where I've added new option called
skip-compile-dir. Patch in attachment. I didn't make ChangeLog yet.
If you like this implementation I prepare ChangeLog and testsuite script.
I can change something if you want.

Here is example:

$ gcc -g -Wall /home/eldar/testdir/test.c
$ ./contrib/gdb-7.2/gdb/gdb ./a.out
...
(gdb) b main
...
(gdb) r
...
(gdb) backtrace
#0  main () at /home/eldar/testdir/test.c:4
...
(gdb) set backtrace
List of set backtrace subcommands:
...
set backtrace skip-compile-dir -- Set whether compile path should be
skipped in backtraces
...
(gdb) set backtrace skip-compile-dir on
(gdb) backtrace
#0  main () at testdir/test.c:4
(gdb) show backtrace
...
skip-compile-dir:  Whether compile path should be skipped in backtraces is on.
(gdb) show backtrace skip-compile-dir
Whether compile path should be skipped in backtraces is on.

[-- Attachment #2: gdb-7.2-skip-compile-dir.patch --]
[-- Type: text/x-patch, Size: 3523 bytes --]

diff -rup gdb-7.2-orig/gdb/frame.c gdb-7.2/gdb/frame.c
--- gdb-7.2-orig/gdb/frame.c	2010-07-01 19:36:15.000000000 +0400
+++ gdb-7.2/gdb/frame.c	2011-07-24 23:33:44.297616001 +0400
@@ -205,6 +205,15 @@ An upper bound on the number of backtrac
 		    value);
 }
 
+static int backtrace_skip_compile;
+static void
+show_backtrace_skip_compile (struct ui_file *file, int from_tty,
+			     struct cmd_list_element *c, const char *value)
+{
+  fprintf_filtered (file, _("\
+Whether compile path should be skipped in backtraces is %s.\n"),
+		    value);
+}
 
 static void
 fprint_field (struct ui_file *file, const char *name, int p, CORE_ADDR addr)
@@ -1900,6 +1909,22 @@ find_frame_sal (struct frame_info *frame
   (*sal) = find_pc_line (get_frame_pc (frame), notcurrent);
 }
 
+char *
+get_display_filename_from_sal (struct symtab_and_line *sal)
+{
+  const char *filename = sal->symtab->filename;
+  const char *dirname = sal->symtab->dirname;
+
+  if (backtrace_skip_compile && filename && dirname
+      && strstr(filename, dirname))
+    {
+      /* +1 means skip directory separator */
+      return filename + strlen(dirname) + 1;
+    }
+
+  return filename;
+}
+
 /* Per "frame.h", return the ``address'' of the frame.  Code should
    really be using get_frame_id().  */
 CORE_ADDR
@@ -2270,6 +2295,16 @@ Zero is unlimited."),
 			   &set_backtrace_cmdlist,
 			   &show_backtrace_cmdlist);
 
+  add_setshow_boolean_cmd ("skip-compile-dir", class_obscure,
+			   &backtrace_skip_compile, _("\
+Set whether compile path should be skipped in backtraces."), _("\
+Show whether compile path should be skipped in backtraces."), _("\
+Normally compile path is displayed if it's exists."),
+			   NULL,
+			   show_backtrace_skip_compile,
+			   &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.2-orig/gdb/frame.h gdb-7.2/gdb/frame.h
--- gdb-7.2-orig/gdb/frame.h	2010-01-01 10:31:32.000000000 +0300
+++ gdb-7.2/gdb/frame.h	2011-07-24 23:33:36.827616001 +0400
@@ -327,6 +327,11 @@ extern CORE_ADDR get_frame_func (struct
 extern void find_frame_sal (struct frame_info *frame,
 			    struct symtab_and_line *sal);
 
+/* Returns filename with or without compile path.
+   It depends on 'set backtrace skip-compile-dir'.  */
+
+extern char *get_display_filename_from_sal (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.2-orig/gdb/stack.c gdb-7.2/gdb/stack.c
--- gdb-7.2-orig/gdb/stack.c	2010-07-01 19:36:17.000000000 +0400
+++ gdb-7.2/gdb/stack.c	2011-07-24 23:33:44.437616001 +0400
@@ -810,11 +810,15 @@ print_frame (struct frame_info *frame, i
   ui_out_text (uiout, ")");
   if (sal.symtab && sal.symtab->filename)
     {
+      const char *display_filename = get_display_filename_from_sal(&sal);
+      if (display_filename == NULL)
+	  display_filename = sal.symtab->filename;
+
       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", display_filename);
       if (ui_out_is_mi_like_p (uiout))
 	{
 	  const char *fullname = symtab_to_fullname (sal.symtab);

  reply	other threads:[~2011-07-24 20:26 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 [this message]
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
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='CAA18ub+ox5kmHu=1qvMkwNfzbCxMdy3M4Z8eKuheaiqyjxJvEg@mail.gmail.com' \
    --to=hal9000ed2k@gmail.com \
    --cc=brobecker@adacore.com \
    --cc=drow@false.org \
    --cc=eliz@gnu.org \
    --cc=gdb-patches@sourceware.org \
    --cc=pedro@codesourcery.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