[binutils-gdb] Fix use of "main" marker in gdb index
Tom Tromey
tromey@sourceware.org
Tue Oct 14 16:19:12 GMT 2025
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=f283e80fed61096b39c17dc325ad13926aaafef0
commit f283e80fed61096b39c17dc325ad13926aaafef0
Author: Tom Tromey <tom@tromey.com>
Date: Mon Sep 22 09:08:46 2025 -0600
Fix use of "main" marker in gdb index
Tom de Vries noticed that with .gdb_index, the "main" marker would
sometimes seemingly be ignored.
I tracked this down to an interaction between the rewritten reader and
the "main"-finding code in cooked_index. With the ordinary DWARF
scanner, a C "main" won't be marked as IS_MAIN; whereas with
.gdb_index this can happen. In this case, the code thinks that C
requires canonicalization (which is only true for types), and skips
using the symbol.
This patch fixes the problem and adds some comments explaining what is
going on.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33441
Diff:
---
gdb/dwarf2/cooked-index-shard.c | 3 ++-
gdb/dwarf2/cooked-index.c | 19 +++++--------------
2 files changed, 7 insertions(+), 15 deletions(-)
diff --git a/gdb/dwarf2/cooked-index-shard.c b/gdb/dwarf2/cooked-index-shard.c
index e440d85e1c9..58a02316e63 100644
--- a/gdb/dwarf2/cooked-index-shard.c
+++ b/gdb/dwarf2/cooked-index-shard.c
@@ -224,7 +224,8 @@ cooked_index_shard::finalize (const parent_map_map *parent_maps)
}
/* Note that this code must be kept in sync with
- language_requires_canonicalization. */
+ cooked_index::get_main -- if canonicalization is required
+ here, then a check might be required there. */
gdb_assert (entry->canonical == nullptr);
if ((entry->flags & IS_LINKAGE) != 0)
entry->canonical = entry->name;
diff --git a/gdb/dwarf2/cooked-index.c b/gdb/dwarf2/cooked-index.c
index 6209590febb..fbcfe8ff3b6 100644
--- a/gdb/dwarf2/cooked-index.c
+++ b/gdb/dwarf2/cooked-index.c
@@ -32,19 +32,6 @@
here, and then these are all waited for before exit proceeds. */
static gdb::unordered_set<cooked_index *> active_vectors;
-/* Return true if LANG requires canonicalization. This is used
- primarily to work around an issue computing the name of "main".
- This function must be kept in sync with
- cooked_index_shard::finalize. */
-
-static bool
-language_requires_canonicalization (enum language lang)
-{
- return (lang == language_ada
- || lang == language_c
- || lang == language_cplus);
-}
-
cooked_index::cooked_index (cooked_index_worker_up &&worker)
: m_state (std::move (worker))
{
@@ -201,7 +188,11 @@ cooked_index::get_main () const
{
if ((entry->flags & IS_MAIN) != 0)
{
- if (!language_requires_canonicalization (entry->lang))
+ /* This should be kept in sync with
+ cooked_index_shard::finalize. Note that there, C
+ requires canonicalization -- but that is only for
+ types, 'main' doesn't count. */
+ if (entry->lang != language_ada && entry->lang != language_cplus)
{
/* There won't be one better than this. */
return entry;
More information about the Gdb-cvs
mailing list