From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21403 invoked by alias); 14 Mar 2012 16:27:34 -0000 Received: (qmail 21386 invoked by uid 22791); 14 Mar 2012 16:27:30 -0000 X-SWARE-Spam-Status: No, hits=-6.7 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 14 Mar 2012 16:27:12 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q2EGQVGV029060 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 14 Mar 2012 12:26:53 -0400 Received: from host2.jankratochvil.net (ovpn-116-16.ams2.redhat.com [10.36.116.16]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q2EGD9WD011252 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Wed, 14 Mar 2012 12:13:12 -0400 Date: Wed, 14 Mar 2012 16:27:00 -0000 From: Jan Kratochvil To: iam ahal Cc: Eli Zaretskii , Tom Tromey , pedro@codesourcery.com, dje@google.com, gdb-patches@sourceware.org, pmuldoon@redhat.com, brobecker@adacore.com, drow@false.org Subject: Re: [patch] GDB 7.2: new feature for "backtrace" that cuts path to file (remain filename) Message-ID: <20120314161309.GA12400@host2.jankratochvil.net> References: <83fwgzbrp9.fsf@gnu.org> <201112061249.47758.pedro@codesourcery.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2012-03/txt/msg00487.txt.bz2 Hi, as I see ongoing reviews and I still work on the testcase posting this part. This is not ready for check-in as is, there will be needed mor eoptions for filename-display, which will be visible from the testcase and which was already discussed here in the list. Thanks, Jan On Sat, 10 Mar 2012 21:14:43 +0100, iam ahal wrote: > 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-10 23:10:42.432243654 +0400 > @@ -6191,6 +6191,26 @@ unlimited. > Display the current limit on backtrace levels. > @end table > > +If backtraces isn't easy to read due to a long absolute filename path recorded and > +you just want to see only a basename or a relative filename path, you can change this > +behaviour: Lines longer than 80 characters. > + > +@table @code > +@item set backtrace filename-display > +@itemx set backtrace filename-display as-recorded > +@cindex backtrace filename-display > +Display a filename recorded at the compilation 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 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-10 23:10:36.060243841 +0400 > @@ -44,6 +44,7 @@ > #include "block.h" > #include "inline-frame.h" > #include "tracepoint.h" > +#include "filenames.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 +136,18 @@ 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_kind_names[] = { more const: static const char *const filename_display_kind_names[] = { [obv] Code cleanup: add_setshow_enum_cmd: Make 1440 bytes of data segment read-only http://sourceware.org/ml/gdb-patches/2012-01/msg00973.html > + filename_display_as_recorded, > + filename_display_basename, > + filename_display_relative_directory, > + NULL > +}; > + > /* Add the following FRAME to the frame stash. */ > > static void > @@ -207,6 +220,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 +2141,42 @@ 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; > + } Excessive { }. > + else if (filename_display_string == filename_display_basename) > + { > + return lbasename (filename); > + } Excessive { }. > + else if (filename_display_string == filename_display_relative_directory && > + dirname && dlen && dlen <= strlen (filename) && > + !filename_ncmp (filename, dirname, dlen)) Operators should be leading, not trailing on the line. And matching components must match their right column from the preceding line: 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; > + } > + > + return filename; > +} > + > /* Per "frame.h", return the ``address'' of the frame. Code should > really be using get_frame_id(). */ > CORE_ADDR > @@ -2477,6 +2536,21 @@ 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 filename in backtraces."), _("\ > +Show how to display filename in backtraces."), _("\ > +filename-display can be:\n\ > + as-recorded - display a filename recorded at the compilation time\n\ > + basename - display only basename of a filename\n\ > + relative - display a filename without the compilation directory part\n\ Lines longer than 80 characters. > +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-10 23:13:36.452238567 +0400 > @@ -353,6 +353,12 @@ extern int get_frame_func_if_available ( > extern void find_frame_sal (struct frame_info *frame, > struct symtab_and_line *sal); > > +/* Returns either 'as recorded' filename or basename or filename > + without the compile directory part. > + It depends on 'set backtrace filename-display' value. */ > + > +extern const char *get_filename_display_from_sal (const struct symtab_and_line *sal); Lines longer than 80 characters. > + > /* 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-10 22:17:18.628337327 +0400 > @@ -1173,11 +1173,16 @@ 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); > + > + if (filename_display == NULL) > + filename_display = 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", filename_display); > if (ui_out_is_mi_like_p (uiout)) > { > const char *fullname = symtab_to_fullname (sal.symtab);