public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH] [gdb/symtab] Fix gdb-index writing for .debug_types
Date: Thu,  7 Sep 2023 16:42:33 +0200	[thread overview]
Message-ID: <20230907144233.14505-2-tdevries@suse.de> (raw)
In-Reply-To: <20230907144233.14505-1-tdevries@suse.de>

With test-case gdb.ada/same_enum.exp and target board dwarf4-gdb-index we run
into:
...
(gdb) print red^M
No definition of "red" in current context.^M
(gdb) FAIL: gdb.ada/same_enum.exp: print red
...

[ This is a regression since commit 844a72efbce ("Simplify gdb_index writing"),
so this is broken in gdb 12 and 13. ]

The easiest way to see what's going wrong is with readelf.  We have in section
.gdb_index:
...
[7194] pck__red:
        2 [static, variable]
        3 [static, variable]
...
which points to the CUs 2 and 3 in the CU list (shown using "2" and "3"), but
should be pointing to the TUs 2 and 3 in the TU list (shown using "T2" and
"T3").

Fix this by removing the counter / types_counter distinction in
write_gdbindex, such that we get the expected:
...
[7194] pck__red:
        T2 [static, variable]
        T3 [static, variable]
...

[ While reading write_gdbindex I noticed a few oddities related to dwz
handling, I've filed PR30829 about this. ]

Tested on x86_64-linux.

PR symtab/30827
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30827
---
 gdb/dwarf2/index-write.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c
index e178bb067a9..11f254e263a 100644
--- a/gdb/dwarf2/index-write.c
+++ b/gdb/dwarf2/index-write.c
@@ -1201,18 +1201,14 @@ write_gdbindex (dwarf2_per_bfd *per_bfd, cooked_index *table,
   data_buf types_cu_list;
 
   /* The CU list is already sorted, so we don't need to do additional
-     work here.  Also, the debug_types entries do not appear in
-     all_units, but only in their own hash table.  */
+     work here.  */
 
   int counter = 0;
-  int types_counter = 0;
   for (int i = 0; i < per_bfd->all_units.size (); ++i)
     {
       dwarf2_per_cu_data *per_cu = per_bfd->all_units[i].get ();
 
-      int &this_counter = per_cu->is_debug_types ? types_counter : counter;
-
-      const auto insertpair = cu_index_htab.emplace (per_cu, this_counter);
+      const auto insertpair = cu_index_htab.emplace (per_cu, counter);
       gdb_assert (insertpair.second);
 
       /* The all_units list contains CUs read from the objfile as well as
@@ -1234,7 +1230,7 @@ write_gdbindex (dwarf2_per_bfd *per_bfd, cooked_index *table,
       else
 	cu_list.append_uint (8, BFD_ENDIAN_LITTLE, per_cu->length ());
 
-      ++this_counter;
+      ++counter;
     }
 
   write_cooked_index (table, cu_index_htab, &symtab);
-- 
2.35.3


  reply	other threads:[~2023-09-07 14:42 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-07 14:42 [PATCH] [gdb/ada] Extend type equivalence test in ada_resolve_enum Tom de Vries
2023-09-07 14:42 ` Tom de Vries [this message]
2023-09-07 18:42   ` [PATCH] [gdb/symtab] Fix gdb-index writing for .debug_types Tom Tromey
2023-09-07 18:36 ` [PATCH] [gdb/ada] Extend type equivalence test in ada_resolve_enum Tom Tromey

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=20230907144233.14505-2-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).