aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2025-01-19 15:42:51 -0700
committerTom Tromey <tom@tromey.com>2025-03-03 14:16:44 -0700
commit268c8bda250f0b282d1fa9bdf7e5959cba018eeb (patch)
treeafd42ea3d853a2eca365eefa2237a0050fb652bf
parent50ca09324ae2132f9bb73324482e4c0f5eaeddd1 (diff)
downloadbinutils-268c8bda250f0b282d1fa9bdf7e5959cba018eeb.zip
binutils-268c8bda250f0b282d1fa9bdf7e5959cba018eeb.tar.gz
binutils-268c8bda250f0b282d1fa9bdf7e5959cba018eeb.tar.bz2
Add language to type unit in debug-names-tu.exp.tcl
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.
-rw-r--r--gdb/dwarf2/cooked-index.c29
-rw-r--r--gdb/dwarf2/cooked-index.h7
-rw-r--r--gdb/dwarf2/index-write.c3
-rw-r--r--gdb/dwarf2/read.c12
-rw-r--r--gdb/testsuite/gdb.dwarf2/debug-names-tu.exp.tcl5
-rw-r--r--gdb/testsuite/lib/dwarf.exp56
6 files changed, 67 insertions, 45 deletions
diff --git a/gdb/dwarf2/cooked-index.c b/gdb/dwarf2/cooked-index.c
index e609a2a..21d9dab 100644
--- a/gdb/dwarf2/cooked-index.c
+++ b/gdb/dwarf2/cooked-index.c
@@ -271,6 +271,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,
const char *name, cooked_index_entry_ref parent_entry,
diff --git a/gdb/dwarf2/cooked-index.h b/gdb/dwarf2/cooked-index.h
index a1d174e..b85c703 100644
--- a/gdb/dwarf2/cooked-index.h
+++ b/gdb/dwarf2/cooked-index.h
@@ -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
diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c
index 174eb22..1d0dacb 100644
--- a/gdb/dwarf2/index-write.c
+++ b/gdb/dwarf2/index-write.c
@@ -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);
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 29af3db..b239458 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -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
diff --git a/gdb/testsuite/gdb.dwarf2/debug-names-tu.exp.tcl b/gdb/testsuite/gdb.dwarf2/debug-names-tu.exp.tcl
index b7ed935..826e739 100644
--- a/gdb/testsuite/gdb.dwarf2/debug-names-tu.exp.tcl
+++ b/gdb/testsuite/gdb.dwarf2/debug-names-tu.exp.tcl
@@ -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}
}
}
diff --git a/gdb/testsuite/lib/dwarf.exp b/gdb/testsuite/lib/dwarf.exp
index bcf3d73..7dcf13f 100644
--- a/gdb/testsuite/lib/dwarf.exp
+++ b/gdb/testsuite/lib/dwarf.exp
@@ -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"