aclements / libelfin

C++11 ELF/DWARF parser
MIT License
317 stars 99 forks source link

Don't mandate that compilation units need a DW_AT_comp_dir #22

Closed TartanLlama closed 6 years ago

TartanLlama commented 7 years ago

dwarf::compilation_unit::get_line_table silently exits if the compilation unit does not have a DW_AT_comp_dir attribute due to this check: https://github.com/aclements/libelfin/blob/master/dwarf/dwarf.cc#L293

This causes line table parsing to fail in some cases when invoking GCC with absolute paths.

Minimal example:

min.cpp: int main(){}

g++ -g min.cpp

Produces the following DW_TAG_compile_unit DIE, which does have a DW_AT_comp_dir:

COMPILE_UNIT<header overall offset = 0x00000000>:
< 0><0x0000000b>  DW_TAG_compile_unit
                    DW_AT_producer              GNU C++14 6.3.1 20170109 -mtune=generic -march=x86-64 -g
                    DW_AT_language              DW_LANG_C_plus_plus
                    DW_AT_name                  min.cpp
                    DW_AT_comp_dir              /home/simon/play/MiniDbg/examples
                    DW_AT_low_pc                0x004004c6
                    DW_AT_high_pc               <offset-from-lowpc>11
                    DW_AT_stmt_list             0x00000000
g++ -g /path/to/min.cpp

Produces this, which does not have a DW_AT_comp_dir, but should still be allowed due to the absolute file name in DW_AT_name:

COMPILE_UNIT<header overall offset = 0x00000000>:
< 0><0x0000000b>  DW_TAG_compile_unit
                    DW_AT_producer              GNU C++14 6.3.1 20170109 -mtune=generic -march=x86-64 -g
                    DW_AT_language              DW_LANG_C_plus_plus
                    DW_AT_name                  /home/simon/play/MiniDbg/examples/min.cpp
                    DW_AT_low_pc                0x004004c6
                    DW_AT_high_pc               <offset-from-lowpc>11
                    DW_AT_stmt_list             0x00000000

With g++ version 6.3.1.

petterreinholdtsen commented 7 years ago

Any idea why the check for DW_AT_comp_dir is there in the first place?