This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] GDB 7.2: new feature for "backtrace" that cuts path to file (remain filename)


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.
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);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]