From: Tom de Vries <tdevries@suse.de>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH] [debug] Fix dwarf v4 .debug_macro.dwo
Date: Tue, 14 May 2024 13:35:30 +0200 [thread overview]
Message-ID: <20240514113530.19808-1-tdevries@suse.de> (raw)
Consider a hello world, compiled with -gsplit-dwarf and dwarf version 4, and -g3:
...
$ gcc -gdwarf-4 -gsplit-dwarf /data/vries/hello.c -g3 -save-temps -dA
...
In section .debug_macro.dwo, we have:
...
.Ldebug_macro0:
.value 0x4 # DWARF macro version number
.byte 0x2 # Flags: 32-bit, lineptr present
.long .Lskeleton_debug_line0
.byte 0x3 # Start new file
.uleb128 0 # Included from line number 0
.uleb128 0x1 # file /data/vries/hello.c
.byte 0x5 # Define macro strp
.uleb128 0 # At line number 0
.uleb128 0x1d0 # The macro: "__STDC__ 1"
...
Given that we use a DW_MACRO_define_strp, we'd expect 0x1d0 to be an
offset into a .debug_str.dwo section.
But in fact, 0x1d0 is an index into the string offset table in
.debug_str_offsets.dwo:
...
.long 0x34f0 # indexed string 0x1d0: __STDC__ 1
...
Add asserts that catch this inconsistency, and fix this by using
DW_MACRO_define_strx instead.
Tested on x86_64.
PR debug/115066
---
gcc/dwarf2out.cc | 20 ++++++++++++++------
gcc/testsuite/gcc.dg/pr115066.c | 8 ++++++++
2 files changed, 22 insertions(+), 6 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/pr115066.c
diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc
index eedb13bb069..70b7f5f42cd 100644
--- a/gcc/dwarf2out.cc
+++ b/gcc/dwarf2out.cc
@@ -29045,7 +29045,7 @@ output_macinfo_op (macinfo_entry *ref)
&& !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
&& (debug_str_section->common.flags & SECTION_MERGE) != 0)
{
- if (dwarf_split_debug_info && dwarf_version >= 5)
+ if (dwarf_split_debug_info)
ref->code = ref->code == DW_MACINFO_define
? DW_MACRO_define_strx : DW_MACRO_undef_strx;
else
@@ -29097,12 +29097,20 @@ output_macinfo_op (macinfo_entry *ref)
HOST_WIDE_INT_PRINT_UNSIGNED,
ref->lineno);
if (node->form == DW_FORM_strp)
- dw2_asm_output_offset (dwarf_offset_size, node->label,
- debug_str_section, "The macro: \"%s\"",
- ref->info);
+ {
+ gcc_assert (ref->code == DW_MACRO_define_strp
+ || ref->code == DW_MACRO_undef_strp);
+ dw2_asm_output_offset (dwarf_offset_size, node->label,
+ debug_str_section, "The macro: \"%s\"",
+ ref->info);
+ }
else
- dw2_asm_output_data_uleb128 (node->index, "The macro: \"%s\"",
- ref->info);
+ {
+ gcc_assert (ref->code == DW_MACRO_define_strx
+ || ref->code == DW_MACRO_undef_strx);
+ dw2_asm_output_data_uleb128 (node->index, "The macro: \"%s\"",
+ ref->info);
+ }
break;
case DW_MACRO_import:
dw2_asm_output_data (1, ref->code, "Import");
diff --git a/gcc/testsuite/gcc.dg/pr115066.c b/gcc/testsuite/gcc.dg/pr115066.c
new file mode 100644
index 00000000000..645757df209
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr115066.c
@@ -0,0 +1,8 @@
+/* { dg-do compile } */
+/* { dg-skip-if "split DWARF unsupported" { hppa*-*-hpux* powerpc*-ibm-aix* *-*-darwin* } } */
+/* { dg-options "-gsplit-dwarf -g3 -dA -gdwarf-4" } */
+/* { dg-final { scan-assembler-times {\.section\t"?\.debug_macro} 1 } } */
+/* { dg-final { scan-assembler-not {\.byte\t0x5\t# Define macro strp} } } */
+/* { dg-final { scan-assembler {\.byte\t0xb\t# Define macro strx} } } */
+
+#define foo 1
base-commit: 2d0eeb529d400e61197a09c56011be976dd81ef0
--
2.35.3
next reply other threads:[~2024-05-14 11:34 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-14 11:35 Tom de Vries [this message]
2024-05-14 11:39 ` Jakub Jelinek
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=20240514113530.19808-1-tdevries@suse.de \
--to=tdevries@suse.de \
--cc=gcc-patches@gcc.gnu.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).