This is the mail archive of the 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]

[RFC/dwarf-2] Add support for included files


Ada95 defines the notion of "separates", which allows a developper
to write the implementation of either a function or a package in
a separate file. Here is a small example:

        package Foo is
           procedure Proc;
        end Foo;


        Package body Foo is
           procedure Proc is separate;
        End Foo;

And then the body for procedure "Proc", as a separate in foo-proc.adb:

        separate (Foo)
        procedure Proc is
        end Proc;

This capability can be reproduced in C as well, using #include.
The following example is somewhat ugly with respect to the usual
coding practices, but does reproduce well the capability above:


        say_hello (void)
          printf ("Hello world.\n");


        #include <stdio.h>
        #include "hello.c"    <--- Reproduces the "is separate"...
        main (void)
          say_hello ();
          return 0;

We have noticed that, if compiled with dwarf-2, GDB is unable to
set a breakpoint inside hello.c using the file:lineno syntax:

        % gcc -gdwarf-2 foo.c -o foo
        % gdb foo
        (gdb) b hello.c:4
        No source file named hello.c.
        (gdb) list hello.c:4
        No source file named hello.c.

However, we can set the breakpoint using the function name:

        (gdb) b say_hello
        Breakpoint 1 at 0x804833e: file hello.c, line 4.

And then once this breakpoint is set, we can now insert the
breakpoint using the source location:

        (gdb) b hello.c:4
        Note: breakpoint 1 also set at pc 0x804833e.
        Breakpoint 2 at 0x804833e: file hello.c, line 4.
        (gdb) list hello.c:4
        1       void
        2       say_hello (void)
        3       {
        4         printf ("Hello world.\n");
        5       }

In Dwarf-2, the list of included files is linked to the line table.
First, we have "Line Number Program Header" which contains the "file
names" table. And then the program itself which uses the DW_LNS_set_file
opcode to change from file to file. There is also the DW_LNE_defile_file
opcode that can be used to define new files instead of using the "file
names" table.

Our problem here is that we don't process this line table when building
the partial symbols. Hence, we miss the list of included files, and
therefore do not create any partial symtab for them. The problem does
not exist with stabs because the N_SOL and line number information
are embedded inside the rest of the stabs data.

If we want to support the case above, I don't see any other way but to
scan the line table as well. I suggest a fast scan, although I don't
see a simple way to skip the opcodes and their data that are ignored
during our scan without having a good knowledge of the opcode we are
skipping. This makes the function that does the quick scan of the line
table almost as fat as the one that is used to build the GDB line
table, almost a copy except that we ignore most of what we read.

Basically, I just copy/pasted the code from dwarf_decode_lines(),
simplified it for partial symtab processing, and then called it
right after the compilation unit psymtab has been built. Currently,
the function scans the line number program, and records which files
of the "file names" table have really been included in the line program
(that's the "file_included" array).

Here is a patch against GDB 6.0 that I used as a proof of concept.
It does not handle the case where the compiler uses DW_LNE_defile_file
instead of the the "file names" table yet, but that will be taken care
of.  Would that be an acceptable approach to suggest for inclusion?

2004-01-02  Joel Brobecker  <>

        * dwarf2read.c (read_partial_die): Add new parameter.
        (scan_partial_symbols): Update call to read_partial_die.
        (dwarf2_add_include_psymtab): New function.
        (dwarf2_build_include_psymtabs): New function.
        (dwarf2_build_psymtabs_hard): Build the psymtabs for the
        included files as well.
        (psymtab_to_symtab_1): Build the symtab of all dependencies
        as well.

Thank you.

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]