From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH 05/11] [gdb/macros] Work around a gcc PR fixed in gcc 9
Date: Tue, 21 May 2024 17:44:09 +0200 [thread overview]
Message-ID: <20240521154415.9543-5-tdevries@suse.de> (raw)
In-Reply-To: <20240521154415.9543-1-tdevries@suse.de>
When running test-case gdb.base/fission-macro-i.exp with gcc 8, we run into:
...
(gdb) set complaints 0^M
Offset from DW_FORM_GNU_str_index or DW_FORM_strx pointing outside of \
.debug_str.dwo section in CU at offset 0x0 \
[in module fission-macro-i-v5-b32-s0]^M
(gdb) FAIL: gdb.base/fission-macro-i.exp: dwarf_version=5: dwarf_bits=32: \
strict_dwarf=0: set complaints 0
...
We're using dwarf5, so the .debug_str_offsets section is supposed to have a
header, but there's none:
...
.section .debug_str_offsets.dwo,"e",@progbits
.long 0 # indexed string 0x0: GNU C17 8.2.1 20180831 ...
.long 0x87 # indexed string 0x1: FIRST 1
.long 0x8f # indexed string 0x2: /home/vries/gdb
.long 0x9f # indexed string 0x3: main
.long 0xa4 # indexed string 0x4: fission-macro-i.i
.long 0xe1 # indexed string 0x5: SECOND 2
...
In other words, we have a v4-style .debug_str_offsets section.
Workaround this by detecting that it's not a valid v5 header by comparing the
initial length to the the section size, and handling it as a v4 section.
IWBN to enable this workaround only for gcc version < 9, but unfortunately the
workaround is required to correctly read the producer string, so that's not
possible.
Tested on x86_64-linux.
Tested test-case (and gdb.base/fission-macro.exp) using a current gcc trunk
build and gcc 7-14.
---
gdb/dwarf2/read.c | 77 +++++++++++++++-------
gdb/testsuite/gdb.base/fission-macro-i.exp | 2 -
2 files changed, 53 insertions(+), 26 deletions(-)
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 3c2698d6832..abe128f35df 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -17514,32 +17514,47 @@ read_dwo_str_index (const struct die_reader_specs *reader, ULONGEST str_index)
const gdb_byte *p = reader->dwo_file->sections.str_offsets.buffer;
/* Header: Initial length. */
- read_initial_length (abfd, p + bytes_read, &bytes_read);
+ LONGEST initial_length
+ = read_initial_length (abfd, p + bytes_read, &bytes_read);
- /* Determine offset_size based on the .debug_str_offsets header. */
- const bool dwarf5_is_dwarf64 = bytes_read != 4;
- offset_size = dwarf5_is_dwarf64 ? 8 : 4;
+ if (initial_length + bytes_read
+ == reader->dwo_file->sections.str_offsets.size)
+ {
+ /* Determine offset_size based on the .debug_str_offsets header. */
+ const bool dwarf5_is_dwarf64 = bytes_read != 4;
+ offset_size = dwarf5_is_dwarf64 ? 8 : 4;
- /* Header: Version. */
- unsigned version = read_2_bytes (abfd, p + bytes_read);
- bytes_read += 2;
+ /* Header: Version. */
+ unsigned version = read_2_bytes (abfd, p + bytes_read);
+ bytes_read += 2;
- if (version <= 4)
- {
- /* We'd like one warning here about ignoring the section, but
- because we parse the header more than once (see FIXME above)
- we'd have many warnings, so use a complaint instead, which at
- least has a limit. */
- complaint (_("Section .debug_str_offsets in %s has unsupported"
- " version %d, use empty string."),
- reader->dwo_file->dwo_name.c_str (), version);
- return "";
- }
+ if (version <= 4)
+ {
+ /* We'd like one warning here about ignoring the section, but
+ because we parse the header more than once (see FIXME above)
+ we'd have many warnings, so use a complaint instead, which at
+ least has a limit. */
+ complaint (_("Section .debug_str_offsets in %s has unsupported"
+ " version %d, use empty string."),
+ reader->dwo_file->dwo_name.c_str (), version);
+ return "";
+ }
- /* Header: Padding. */
- bytes_read += 2;
+ /* Header: Padding. */
+ bytes_read += 2;
- str_offsets_base = bytes_read;
+ str_offsets_base = bytes_read;
+ }
+ else
+ {
+ /* GCC 8 and earlier has a bug that for dwarf5 it produces a
+ pre-dwarf5 .debug_str_offsets section. We'd wish we could make
+ this work-around more precise by checking that producer is gcc and
+ gcc version <= 8, but that doesn't work if we need this workaround
+ to read the producer string. */
+ offset_size = 4;
+ str_offsets_base = 0;
+ }
}
else
{
@@ -21249,9 +21264,23 @@ dwarf_decode_macros (struct dwarf2_cu *cu, unsigned int offset,
{
bfd *abfd = str_offsets_section->get_bfd_owner ();
unsigned int bytes_read = 0;
- read_initial_length (abfd, str_offsets_section->buffer, &bytes_read, false);
- const bool is_dwarf64 = bytes_read != 4;
- str_offsets_base = is_dwarf64 ? 16 : 8;
+ LONGEST initial_length
+ = read_initial_length (abfd, str_offsets_section->buffer,
+ &bytes_read, false);
+ if ((bytes_read == 4 || bytes_read == 12)
+ && initial_length + bytes_read == str_offsets_section->size)
+ {
+ const bool is_dwarf64 = bytes_read != 4;
+ str_offsets_base = is_dwarf64 ? 16 : 8;
+ }
+ else
+ {
+ /* GCC 8 and earlier has a bug that for dwarf5 it produces a
+ pre-dwarf5 .debug_str_offsets section. We use the same test
+ as in read_dwo_str_index. */
+ str_offsets_base = 0;
+ offset_size = 4;
+ }
}
}
else
diff --git a/gdb/testsuite/gdb.base/fission-macro-i.exp b/gdb/testsuite/gdb.base/fission-macro-i.exp
index 3121e1d289b..ae211d0e09b 100644
--- a/gdb/testsuite/gdb.base/fission-macro-i.exp
+++ b/gdb/testsuite/gdb.base/fission-macro-i.exp
@@ -13,8 +13,6 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. */
-require {expr [gcc_major_version] >= 9}
-
# Use a .i file instead of a .c file, to make sure that we only generate one
# .debug_macros section, working around gcc PR debug/111409.
standard_testfile .i -2.i
--
2.35.3
next prev parent reply other threads:[~2024-05-21 15:43 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-21 15:44 [PATCH 01/11] [gdb/testsuite] Add gdb.base/fission-macro.exp Tom de Vries
2024-05-21 15:44 ` [PATCH 02/11] [gdb/macros] Handle 64-bit dwarf in gdb.base/fission-macro.exp Tom de Vries
2024-05-21 15:44 ` [PATCH 03/11] [gdb/testsuite] Add test-case gdb.base/fission-macro-i.exp Tom de Vries
2024-06-13 16:27 ` Tom de Vries
2024-05-21 15:44 ` [PATCH 04/11] [gdb/macros] Work around gcc PR debug/99319 Tom de Vries
2024-05-21 15:44 ` Tom de Vries [this message]
2024-05-21 15:44 ` [PATCH 06/11] [gdb/macros] Handle v4 dwarf in gdb.base/fission-macro.exp Tom de Vries
2024-05-21 15:44 ` [PATCH 07/11] [gdb/macros] Workaround gcc PR debug/115066 Tom de Vries
2024-05-21 15:44 ` [PATCH 08/11] [gdb/testsuite] Extend gdb.base/fission-macro.exp Tom de Vries
2024-05-21 15:44 ` [PATCH 09/11] [gdb/macros] Fix gdb.base/fission-macro.exp with clang Tom de Vries
2024-05-21 15:44 ` [PATCH 10/11] [gdb/testsuite] Use -g3 in gdb.base/lineinc.exp Tom de Vries
2024-05-21 15:44 ` [PATCH 11/11] [gdb/testsuite] Don't use readelf in gdb/contrib/cc-with-tweaks.sh Tom de Vries
2024-06-13 15:40 ` [PATCH 01/11] [gdb/testsuite] Add gdb.base/fission-macro.exp Tom de Vries
2024-06-17 8:16 ` Christophe Lyon
2024-06-17 8:23 ` Tom de Vries
2024-06-17 8:43 ` Christophe Lyon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240521154415.9543-5-tdevries@suse.de \
--to=tdevries@suse.de \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).