]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Fix use of "main" in gdb_index with C++
authorTom Tromey <tom@tromey.com>
Sun, 19 Oct 2025 19:06:40 +0000 (13:06 -0600)
committerTom Tromey <tom@tromey.com>
Thu, 6 Nov 2025 23:39:47 +0000 (16:39 -0700)
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
gdb/testsuite/gdb.base/fission-macro.exp

index 111dadbdbc9dd1c4770a2d4b6c1b8a16c3d67852..bf22bdd7ba2a064c38439b153e394b070450dc4c 100644 (file)
@@ -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;
index 0680da69e089c02cb51c6dda300ad40180ea2363..29ef692057b195cb7bddce55cb13c9d7661347e3 100644 (file)
@@ -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
+           }
        }
     }
 }