]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Add language to type unit in debug-names-tu.exp.tcl
authorTom Tromey <tom@tromey.com>
Sun, 19 Jan 2025 22:42:51 +0000 (15:42 -0700)
committerTom Tromey <tom@tromey.com>
Mon, 3 Mar 2025 21:16:44 +0000 (14:16 -0700)
I think debug-names-tu.exp.tcl only passes by accident -- the type
unit does not have a language, which gdb essentially requires.

This isn't noticeable right now because the type unit in question is
expanded in one phase and then the symbol found in another.  However,
I'm working on a series that would regress this.

This patch partially fixes the problem by correcting the test case,
adding the language to the TU.

Hoewver, it then goes a bit further and arranges for this information
not to be written to .debug_names.  Whether or not a type should be
considered "static" seems like something that is purely internal to
gdb, so this patch has the entry-creation function apply the
appropriate transform.

It also may make sense to change the "debug_names" proc in the test
suite to process attributes more like the ordinary "cu" proc does.

gdb/dwarf2/cooked-index.c
gdb/dwarf2/cooked-index.h
gdb/dwarf2/index-write.c
gdb/dwarf2/read.c
gdb/testsuite/gdb.dwarf2/debug-names-tu.exp.tcl
gdb/testsuite/lib/dwarf.exp

index e609a2a9d4611dc9c1abddebbdd284e75c224b45..21d9dab5f41420f33d3966107e62e038789bb3b4 100644 (file)
@@ -270,6 +270,35 @@ cooked_index_entry::write_scope (struct obstack *storage,
 
 /* See cooked-index.h.  */
 
+cooked_index_entry *
+cooked_index_shard::create (sect_offset die_offset,
+                           enum dwarf_tag tag,
+                           cooked_index_flag flags,
+                           enum language lang,
+                           const char *name,
+                           cooked_index_entry_ref parent_entry,
+                           dwarf2_per_cu *per_cu)
+{
+  if (tag == DW_TAG_module || tag == DW_TAG_namespace)
+    flags &= ~IS_STATIC;
+  else if (lang == language_cplus
+          && (tag == DW_TAG_class_type
+              || tag == DW_TAG_interface_type
+              || tag == DW_TAG_structure_type
+              || tag == DW_TAG_union_type
+              || tag == DW_TAG_enumeration_type
+              || tag == DW_TAG_enumerator))
+    flags &= ~IS_STATIC;
+  else if (tag_is_type (tag))
+    flags |= IS_STATIC;
+
+  return new (&m_storage) cooked_index_entry (die_offset, tag, flags,
+                                             lang, name, parent_entry,
+                                             per_cu);
+}
+
+/* See cooked-index.h.  */
+
 cooked_index_entry *
 cooked_index_shard::add (sect_offset die_offset, enum dwarf_tag tag,
                         cooked_index_flag flags, enum language lang,
index a1d174e0e88c7bf3e15347333d8b28aa024ecc8e..b85c703dc25144c1f938feab2ff17b1d06d821e3 100644 (file)
@@ -333,12 +333,7 @@ private:
                              enum language lang,
                              const char *name,
                              cooked_index_entry_ref parent_entry,
-                             dwarf2_per_cu *per_cu)
-  {
-    return new (&m_storage) cooked_index_entry (die_offset, tag, flags,
-                                               lang, name, parent_entry,
-                                               per_cu);
-  }
+                             dwarf2_per_cu *per_cu);
 
   /* GNAT only emits mangled ("encoded") names in the DWARF, and does
      not emit the module structure.  However, we need this structure
index 174eb220df6836ae605adbe22b5e2b317b856b18..1d0dacb4b5220a88b19c770f8f8dd55ec152fe05 100644 (file)
@@ -754,7 +754,8 @@ public:
                m_abbrev_table.append_unsigned_leb128 (DW_FORM_ref_addr);
                m_abbrev_table.append_unsigned_leb128 (DW_IDX_GNU_language);
                m_abbrev_table.append_unsigned_leb128 (DW_FORM_udata);
-               if ((entry->flags & IS_STATIC) != 0)
+               if (!tag_is_type (entry->tag)
+                   && (entry->flags & IS_STATIC) != 0)
                  {
                    m_abbrev_table.append_unsigned_leb128 (DW_IDX_GNU_internal);
                    m_abbrev_table.append_unsigned_leb128 (DW_FORM_flag_present);
index 29af3dbf24ba4f2c3bb9ad9219833a1d68bd238e..b2394588cb8f552cb5b863c7456911c4f340c561 100644 (file)
@@ -15606,21 +15606,9 @@ cooked_indexer::scan_attributes (dwarf2_per_cu *scanning_per_cu,
            }
        }
 
-      if (abbrev->tag == DW_TAG_module || abbrev->tag == DW_TAG_namespace)
-       *flags &= ~IS_STATIC;
-
       if (abbrev->tag == DW_TAG_namespace && *name == nullptr)
        *name = "(anonymous namespace)";
 
-      if (m_language == language_cplus
-         && (abbrev->tag == DW_TAG_class_type
-             || abbrev->tag == DW_TAG_interface_type
-             || abbrev->tag == DW_TAG_structure_type
-             || abbrev->tag == DW_TAG_union_type
-             || abbrev->tag == DW_TAG_enumeration_type
-             || abbrev->tag == DW_TAG_enumerator))
-       *flags &= ~IS_STATIC;
-
       /* Keep in sync with new_symbol.  */
       if (abbrev->tag == DW_TAG_subprogram
          && (m_language == language_ada
index b7ed935de505f2e1cb544bd20bca084e07338251..826e7394da1cf5319babbbb8ccc3eb0e4166ef38 100644 (file)
@@ -46,7 +46,7 @@ Dwarf::assemble {
     }
 
     tu { label tu_label version $dwarf_version } 0x8ece66f4224fddb3 "" {
-       type_unit {} {
+       type_unit {{language @DW_LANG_C}} {
            declare_labels int_type
 
            structure_type {
@@ -70,7 +70,8 @@ Dwarf::assemble {
        cu cu_label
        tu tu_label
        name _start subprogram cu_label 0xEDDB6232
-       name struct_with_int_member structure_type tu_label 0x53A2AE86
+       name struct_with_int_member structure_type tu_label 0x53A2AE86 \
+           {DW_LANG_C}
     }
 }
 
index bcf3d73bff291b7792fac90c7681de814db007f3..7dcf13f2ce7bdbdd78c4972ac0e6c7a55958afdd 100644 (file)
@@ -3130,10 +3130,11 @@ namespace eval Dwarf {
        }
        variable _debug_names
        set _debug_names []
-       proc _debug_names_name { name tag cu hash } {
+       proc _debug_names_name { name tag cu hash {extra {}} } {
            variable _debug_names
            declare_labels entry_pool_offset
-           lappend _debug_names [list $name $tag $cu $hash $entry_pool_offset]
+           lappend _debug_names [list $name $tag $cu $hash $extra \
+                                     $entry_pool_offset]
        }
        with_override Dwarf::cu Dwarf::_debug_names_cu {
        with_override Dwarf::tu Dwarf::_debug_names_tu {
@@ -3196,14 +3197,13 @@ namespace eval Dwarf {
 
        # Hash Lookup Table - array of hashes.
        foreach idx $_debug_names {
-           set name [lindex $idx 0]
-           set hash [lindex $idx 3]
+           lassign $idx name tag cu hash extra label
            _op .4byte $hash "hash: $name"
        }
 
        # Name Table - array of string offsets.
        foreach idx $_debug_names {
-           set name [lindex $idx 0]
+           lassign $idx name tag cu hash extra label
 
            variable _strings
            if {![info exists _strings($name)]} {
@@ -3220,8 +3220,7 @@ namespace eval Dwarf {
        # Name Table - array of entry offsets.
        set base_label ""
        foreach idx $_debug_names {
-           set name [lindex $idx 0]
-           set label [lindex $idx 4]
+           lassign $idx name tag cu hash extra label
            if { [string equal $base_label ""]} {
                set base_label $label
            }
@@ -3234,31 +3233,42 @@ namespace eval Dwarf {
        set abbrev 1
        variable _constants
        foreach idx $_debug_names {
-           set name [lindex $idx 0]
-           set tag [lindex $idx 1]
-           set cu [lindex $idx 2]
+           lassign $idx name tag cu hash extra label
 
            if { [regexp "^CU-($decimal)$" $cu dummy cu_index] } {
-               set attr_name compile_unit
-               set attr_val 1
+               set attr_name DW_IDX_compile_unit
            } elseif { [regexp "^TU-($decimal)$" $cu dummy cu_index] } {
-               set attr_name type_unit
-               set attr_val 2
+               set attr_name DW_IDX_type_unit
            } else {
                set cu_index [lsearch -exact $_debug_names_cus $cu]
                if { $cu_index == -1 } {
-                   set attr_name type_unit
-                   set attr_val 2
+                   set attr_name DW_IDX_type_unit
                } else {
-                   set attr_name compile_unit
-                   set attr_val 1
+                   set attr_name DW_IDX_compile_unit
                }
            }
 
-           _op .byte $abbrev "abbrev $abbrev"
+           _op .uleb128 $abbrev "abbrev $abbrev"
            _op .uleb128 $_constants(DW_TAG_$tag) "DW_TAG_$tag"
-           _op .byte $attr_val  "DW_IDX_$attr_name (attribute)"
-           _op .byte 0x0f "DW_FORM_udata (form)"
+           _op .uleb128 $_constants($attr_name)  \
+               "$attr_name (attribute)"
+           _op .uleb128 0x0f "DW_FORM_udata (form)"
+           foreach word $extra {
+               if {$word == "static"} {
+                   _op .uleb128 $_constants(DW_IDX_GNU_internal) \
+                       "DW_IDX_GNU_internal"
+                   _op .uleb128 $_constants(DW_FORM_flag_present) \
+                       "DW_FORM_flag_present"
+               } elseif {[string match DW_LANG_* $word]} {
+                   _op .uleb128 $_constants(DW_IDX_GNU_language) \
+                       "DW_IDX_GNU_language"
+                   _op .uleb128 $_constants(DW_FORM_implicit_const) \
+                       "DW_FORM_flag_present"
+                   _op .sleb128 $_constants($word) $word
+               } else {
+                   error "unrecognized extra keyword $word"
+               }
+           }
            _op .byte 0  "abbrev terminator (attribute)"
            _op .byte 0  "abbrev terminator (form)"
            incr abbrev
@@ -3269,9 +3279,7 @@ namespace eval Dwarf {
        # Entry Pool
        set abbrev 1
        foreach idx $_debug_names {
-           set name [lindex $idx 0]
-           set cu [lindex $idx 2]
-           set label [lindex $idx 4]
+           lassign $idx name tag cu hash extra label
 
            if { [regexp "^CU-($decimal)$" $cu dummy cu_index] } {
                set comment "$name: CU index"