Re: [PATCH] Fix macro info lookup for binaries containing DWARFv5 line table

Simon Marchi via Gdb-patches
2021-05-14T20:56:24Z

> Thanks for sharing this, since both file0 and dir0 both are present, if possible, could you please share any behavior change or anything subtle you notice before/after
> applying patch ?

That gcc is in a container, so not to practical to test with. So I
built various gcc versions from source to investigate this:

- 10.2.0 (I did not actually build this one, it's the one from my
distro)
- 11.1.0
- 11 from today's git
- master from today's git

With gcc 10.2.0, as seen before, I don't get a DWARF 5 .debug_line
section.

With all three others, I get the same thing (modulo dir[2] which
specific to the compiler version) that looks good:

include_directories[ 0] = "/home/simark/build/binutils-gdb/gdb"
include_directories[ 1] = "/usr/include"
include_directories[ 2] = "/opt/gcc/git/lib/gcc/x86_64-pc-linux-gnu/12.0.0/include"
include_directories[ 3] = "/usr/include/bits"
include_directories[ 4] = "/usr/include/sys"
include_directories[ 5] = "/usr/include/gnu"
file_names[ 0]:
name: "test.c"
dir_index: 0
file_names[ 1]:
name: "test.c"
dir_index: 0
file_names[ 2]:
name: "stdc-predef.h"
dir_index: 1
file_names[ 3]:
name: "stdint.h"
dir_index: 2
file_names[ 4]:
name: "stdint.h"
dir_index: 1

I tested again using the gcc 11.1.0 from Ubuntu, that gave me a wrong
dir[0] before. I replicated the same directory structure
(/home/simark/build/binutils-gdb/gdb/...) in my Ubuntu container, and
things look good actually:

include_directories[ 0] = "/home/simark/build/binutils-gdb/gdb"
include_directories[ 1] = "/usr/include"
include_directories[ 2] = "/usr/lib/gcc/x86_64-linux-gnu/11/include"
include_directories[ 3] = "/usr/include/x86_64-linux-gnu/bits"
include_directories[ 4] = "/usr/include/x86_64-linux-gnu/sys"
include_directories[ 5] = "/usr/include/x86_64-linux-gnu/gnu"
file_names[ 0]:
name: "test.c"
dir_index: 0
file_names[ 1]:
name: "test.c"
dir_index: 0
file_names[ 2]:
name: "stdc-predef.h"
dir_index: 1

So I tried compiling a file in the root directory (/) on my
(non-container) host, and I did see the weird output:

include_directories[ 0] = "/usr/include"
include_directories[ 1] = "/usr/include"
include_directories[ 2] = "/usr/include/bits"
include_directories[ 3] = "/usr/include/sys"
include_directories[ 4] = "/usr/include/gnu"
include_directories[ 5] = "/opt/gcc/11.1.0/lib/gcc/x86_64-pc-linux-gnu/11.1.0/include"
include_directories[ 6] = "/usr/include/bits/types"
file_names[ 0]:
name: "test.c"
dir_index: 0
file_names[ 1]:
name: "test.c"
dir_index: 0
file_names[ 2]:
name: "stdc-predef.h"
dir_index: 1

So that looks like a gcc bug that only happens when the compilation
directory is the root. I'll go see if there's a gcc bug for this
already and file one if there isn't.

But other than that little corner case, the gcc 11+ -gdwarf-5 output
looks good.

I did a quick test loading the binary made using gcc master in GDB, and
I wasn't able to print the macro - both without and with your patch. I
didn't investigate further, I have to go now.

Simon