From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15273 invoked by alias); 1 Nov 2004 19:48:04 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 15263 invoked from network); 1 Nov 2004 19:48:02 -0000 Received: from unknown (HELO takamaka.act-europe.fr) (142.179.108.108) by sourceware.org with SMTP; 1 Nov 2004 19:48:02 -0000 Received: by takamaka.act-europe.fr (Postfix, from userid 507) id C63A247D9F; Mon, 1 Nov 2004 11:48:01 -0800 (PST) Date: Mon, 01 Nov 2004 19:48:00 -0000 From: Joel Brobecker To: gdb-patches@sources.redhat.com Subject: Re: [RFA/dwarf2] Fix name of include psymtabs, avoid duplicates Message-ID: <20041101194801.GI27334@gnat.com> References: <20041017010238.GD20779@gnat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20041017010238.GD20779@gnat.com> User-Agent: Mutt/1.4i X-SW-Source: 2004-11/txt/msg00020.txt.bz2 Ping? On Sat, Oct 16, 2004 at 06:02:38PM -0700, Joel Brobecker wrote: > Hello, > > This patch fixes a problem reported by David Lecomber (lost the URL, > and couldn't find it in the archives). Here is how to reproduce it. > You'll need a file in a subdirectory: > > % cat foo/main.c > int > main (void) > { > return 0; > } > > Then build this file with the following command: > > % gcc -gdwarf-2 -o main foo/main.c > > When GDB scans the dwarf2 data to create the psymtabs, it scans > the linetable for each CU and create "include psymtabs" for it. > These psymtabs correspond to the files included from that CU > (see call to dwarf2_build_include_psymtabs at the end of > dwarf2_build_psymtabs_hard). > > Unfortunately, a little omission in my part lead to a bug: > > (gdb) file main > (gdb) info sources > [...] > Source files for which symbols will be read in on demand: > [...], main.c, /home/brobecke/tmp/dup/foo/main.c, [...] > > As you see, main.c is duplicated... The problem comes from the > fact that the main.c CU is declared in the debug_info data as: > filename = foo/main.c, and comp_dir = /home/brobecke/tmp/dup. > > DW_AT_name : foo/main.c > DW_AT_comp_dir : /home/brobecke/tmp/dup > > However, in the line table, we see the following declaration: > > The Directory Table: > foo > > The File Name Table: > Entry Dir Time Size Name > 1 1 0 0 main.c > > So the name is main.c in the linetable, with a link to entry > number 1 in the directory table = foo. So the following check > in dwarf_decode_lines gets defeated: > > if (strcmp (include_name, pst->filename) != 0) > dwarf2_create_include_psymtab (include_name, pst, objfile); > > (include_name = "main.c" and pst->filename = "foo/main.c"); > > The fix is to concat the dir name and the file name to obtain > the proper name for the psymtab. As a consequence, the filename > check will also work, and avoid the duplication. > > Normally, to be completely accurate, one would expect the filename > > 2004-10-16 Joel Brobecker > > * dwarf2read.c (dwarf_decode_lines): Use the complete filename > when creating include psymtabs. > > Tested on x86-linux, no regression. > OK to apply? > > Thanks, > -- > Joel > Index: dwarf2read.c > =================================================================== > RCS file: /cvs/src/src/gdb/dwarf2read.c,v > retrieving revision 1.167 > diff -u -p -r1.167 dwarf2read.c > --- dwarf2read.c 16 Oct 2004 00:41:00 -0000 1.167 > +++ dwarf2read.c 17 Oct 2004 00:01:23 -0000 > @@ -6609,7 +6609,19 @@ dwarf_decode_lines (struct line_header * > for (file_index = 0; file_index < lh->num_file_names; file_index++) > if (lh->file_names[file_index].included_p == 1) > { > - char *include_name = lh->file_names [file_index].name; > + const struct file_entry fe = lh->file_names [file_index]; > + char *include_name = fe.name; > + char *dir_name = NULL; > + > + if (fe.dir_index) > + dir_name = lh->include_dirs[fe.dir_index - 1]; > + > + if (!IS_ABSOLUTE_PATH (include_name) && dir_name != NULL) > + { > + include_name = > + concat (dir_name, SLASH_STRING, include_name, NULL); > + make_cleanup (xfree, include_name); > + } > > if (strcmp (include_name, pst->filename) != 0) > dwarf2_create_include_psymtab (include_name, pst, objfile); -- Joel