This is the mail archive of the gdb-patches@sources.redhat.com 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]

[RFA/dwarf2] Fix name of include psymtabs, avoid duplicates


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  <brobecker@gnat.com>

        * dwarf2read.c (dwarf_decode_lines): Use the complete filename
        when creating include psymtabs.

Tested on x86-linux, no regression.
OK to apply?

Thanks,
-- 
Joel

Attachment: dwarf2read.c.diff
Description: Text document


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