diff options
author | Tom de Vries <tdevries@suse.de> | 2023-10-16 16:32:28 +0200 |
---|---|---|
committer | Tom de Vries <tdevries@suse.de> | 2023-10-16 16:32:28 +0200 |
commit | 1d45d90934b10862c00a22bcf4075815a785001b (patch) | |
tree | 64ac6a72a23c6192d45cdac5d9c8621c2e4195c5 /gdb/dwarf2 | |
parent | 5d4a870e05ac45e3f5a301c672a4079995b5db7a (diff) | |
download | gdb-1d45d90934b10862c00a22bcf4075815a785001b.zip gdb-1d45d90934b10862c00a22bcf4075815a785001b.tar.gz gdb-1d45d90934b10862c00a22bcf4075815a785001b.tar.bz2 |
[gdb/symtab] Work around PR gas/29517
When using glibc debuginfo generated with gas 2.39, we run into PR gas/29517:
...
$ gdb -q -batch a.out -ex start -ex "p (char *)strstr (\"haha\", \"ah\")"
Temporary breakpoint 1 at 0x40051b: file hello.c, line 6.
Temporary breakpoint 1, main () at hello.c:6
6 printf ("hello\n");
Invalid cast.
...
while without glibc debuginfo installed we get the expected result:
...
$n = 0x7ffff7daa1b1 "aha"
...
and likewise with glibc debuginfo generated with gas 2.40.
The strstr ifunc resolves to __strstr_sse2_unaligned. The problem is that gas
generates dwarf that states that the return type is void:
...
<1><3e1e58>: Abbrev Number: 2 (DW_TAG_subprogram)
<3e1e59> DW_AT_name : __strstr_sse2_unaligned
<3e1e5d> DW_AT_external : 1
<3e1e5e> DW_AT_low_pc : 0xbbd2e
<3e1e66> DW_AT_high_pc : 0xbc1c3
...
while the return type should be a DW_TAG_unspecified_type, as is the case
with gas 2.40.
We can still use the workaround of casting to another function type for both
__strstr_sse2_unaligned:
...
(gdb) p ((char * (*) (const char *, const char *))__strstr_sse2_unaligned) \
("haha", "ah")
$n = 0x7ffff7daa211 "aha"
...
and strstr (which requires using *strstr to dereference the ifunc before we
cast):
...
gdb) p ((char * (*) (const char *, const char *))*strstr) ("haha", "ah")
$n = 0x7ffff7daa251 "aha"
...
but that's a bit cumbersome to use.
Work around this in the dwarf reader, such that we have instead:
...
(gdb) p (char *)strstr ("haha", "ah")
$n = 0x7ffff7daa1b1 "aha"
...
This also requires fixing producer_is_gcc to stop returning true for
producer "GNU AS 2.39.0".
Tested on x86_64-linux.
Approved-By: Andrew Burgess <aburgess@redhat.com>
PR symtab/30911
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30911
Diffstat (limited to 'gdb/dwarf2')
-rw-r--r-- | gdb/dwarf2/cu.c | 1 | ||||
-rw-r--r-- | gdb/dwarf2/cu.h | 1 | ||||
-rw-r--r-- | gdb/dwarf2/read.c | 23 |
3 files changed, 25 insertions, 0 deletions
diff --git a/gdb/dwarf2/cu.c b/gdb/dwarf2/cu.c index 89de40d..a908ec9 100644 --- a/gdb/dwarf2/cu.c +++ b/gdb/dwarf2/cu.c @@ -40,6 +40,7 @@ dwarf2_cu::dwarf2_cu (dwarf2_per_cu_data *per_cu, producer_is_icc_lt_14 (false), producer_is_codewarrior (false), producer_is_clang (false), + producer_is_gas_2_39 (false), processing_has_namespace_info (false), load_all_dies (false) { diff --git a/gdb/dwarf2/cu.h b/gdb/dwarf2/cu.h index 0c15d8b..6c61171 100644 --- a/gdb/dwarf2/cu.h +++ b/gdb/dwarf2/cu.h @@ -265,6 +265,7 @@ public: bool producer_is_icc_lt_14 : 1; bool producer_is_codewarrior : 1; bool producer_is_clang : 1; + bool producer_is_gas_2_39 : 1; /* When true, the file that we're processing is known to have debugging info for C++ namespaces. GCC 3.3.x did not produce diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index d4aec19..2eb34b2 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -11426,6 +11426,8 @@ check_producer (struct dwarf2_cu *cu) cu->producer_is_codewarrior = true; else if (producer_is_clang (cu->producer, &major, &minor)) cu->producer_is_clang = true; + else if (startswith (cu->producer, "GNU AS 2.39.0")) + cu->producer_is_gas_2_39 = true; else { /* For other non-GCC compilers, expect their behavior is DWARF version @@ -11461,6 +11463,15 @@ producer_is_codewarrior (struct dwarf2_cu *cu) return cu->producer_is_codewarrior; } +static bool +producer_is_gas_2_39 (struct dwarf2_cu *cu) +{ + if (!cu->checked_producer) + check_producer (cu); + + return cu->producer_is_gas_2_39; +} + /* Return the accessibility of DIE, as given by DW_AT_accessibility. If that attribute is not available, return the appropriate default. */ @@ -14635,6 +14646,18 @@ read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu) type = die_type (die, cu); + if (type->code () == TYPE_CODE_VOID + && !type->is_stub () + && die->child == nullptr + && producer_is_gas_2_39 (cu)) + { + /* Work around PR gas/29517, pretend we have an DW_TAG_unspecified_type + return type. */ + type = (type_allocator (cu->per_objfile->objfile, cu->lang ()) + .new_type (TYPE_CODE_VOID, 0, nullptr)); + type->set_is_stub (true); + } + /* The die_type call above may have already set the type for this DIE. */ ftype = get_die_type (die, cu); if (ftype) |