From: Tom Tromey Date: Mon, 22 Sep 2025 15:08:46 +0000 (-0600) Subject: Fix use of "main" marker in gdb index X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f283e80fed61096b39c17dc325ad13926aaafef0;p=thirdparty%2Fbinutils-gdb.git 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 --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 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;