From 7d8b016af12cf5d7964b0c9c23e5dc735ea68682 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Sun, 19 Oct 2025 13:06:40 -0600 Subject: [PATCH] Fix use of "main" in gdb_index with C++ In commit f283e80f (Fix use of "main" marker in gdb index), I changed the DWARF reader to understand that the C language's "main" might appear in the .gdb_index, and should not be ignored. This week I realized that this same problem can affect C++ as well. I'm not sure why I didn't consider this at the time. This patch fixes the bug. It's somewhat of a hack, I guess, but also at least understandable. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33441 --- gdb/dwarf2/cooked-index.c | 8 ++++++-- gdb/testsuite/gdb.base/fission-macro.exp | 23 ++++++++++++++--------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/gdb/dwarf2/cooked-index.c b/gdb/dwarf2/cooked-index.c index 111dadbdbc9..bf22bdd7ba2 100644 --- a/gdb/dwarf2/cooked-index.c +++ b/gdb/dwarf2/cooked-index.c @@ -191,8 +191,12 @@ cooked_index::get_main () const /* 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) + types, 'main' doesn't count. Similarly, C++ requires + canonicalization, but again "main" is an + exception. */ + if ((entry->lang != language_ada + && entry->lang != language_cplus) + || strcmp (entry->name, "main") == 0) { /* There won't be one better than this. */ return entry; diff --git a/gdb/testsuite/gdb.base/fission-macro.exp b/gdb/testsuite/gdb.base/fission-macro.exp index 0680da69e08..29ef692057b 100644 --- a/gdb/testsuite/gdb.base/fission-macro.exp +++ b/gdb/testsuite/gdb.base/fission-macro.exp @@ -18,11 +18,14 @@ require {expr {[gcc_major_version] >= 14}} standard_testfile .c -2.c -proc do_tests { dwarf_version dwarf_bits strict_dwarf } { +proc do_tests { lang dwarf_version dwarf_bits strict_dwarf } { set opts {} lappend opts debug lappend opts quiet lappend opts additional_flags=-gsplit-dwarf + if {$lang == "c++"} { + lappend opts "additional_flags=-x c++" + } lappend opts macros if { $dwarf_bits == 64 } { @@ -66,14 +69,16 @@ proc do_tests { dwarf_version dwarf_bits strict_dwarf } { gdb_test "info macro FOURTH" "#define FOURTH 4" } -foreach_with_prefix dwarf_version {4 5} { - if { $dwarf_version == 4 && [gcc_major_version] < 15 } { - # Gcc does not contain fix for PR debug/115066. - continue - } - foreach_with_prefix dwarf_bits {32 64} { - foreach_with_prefix strict_dwarf {0 1} { - do_tests $dwarf_version $dwarf_bits $strict_dwarf +foreach_with_prefix lang {c c++} { + foreach_with_prefix dwarf_version {4 5} { + if { $dwarf_version == 4 && [gcc_major_version] < 15 } { + # Gcc does not contain fix for PR debug/115066. + continue + } + foreach_with_prefix dwarf_bits {32 64} { + foreach_with_prefix strict_dwarf {0 1} { + do_tests $lang $dwarf_version $dwarf_bits $strict_dwarf + } } } } -- 2.47.3