From: Keith Seitz Date: Tue, 21 Feb 2017 21:32:50 +0000 (-0800) Subject: Introduce dw2_linkage_name. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a156e8208c80665fe43e24c851258b12d3115e9b;p=thirdparty%2Fbinutils-gdb.git Introduce dw2_linkage_name. The DWARF reader is littered with the following idiom to read a linkage name from the debug info: mangled = dwarf2_string_attr (die, DW_AT_linkage_name, cu); if (mangled == NULL) mangled = dwarf2_string_attr (die, DW_AT_MIPS_linkage_name, cu); This patch introduces a new function to simplify this to: mangled = dw2_linkage_name (die, cu); gdb/ChangeLog --- diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index ae7d3f2474f..3edf6dbf77b 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -8497,6 +8497,22 @@ die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu) } } +/* Return the DIE's linkage name attribute, either DW_AT_linkage_name + or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not + defined for the given DIE. */ + +static const char * +dw2_linkage_name (struct die_info *die, struct dwarf2_cu *cu) +{ + const char *linkage_name; + + linkage_name = dwarf2_string_attr (die, DW_AT_linkage_name, cu); + if (linkage_name == NULL) + linkage_name = dwarf2_string_attr (die, DW_AT_MIPS_linkage_name, cu); + + return linkage_name; +} + /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero, compute the physname for the object, which include a method's: - formal parameters (C++), @@ -8536,11 +8552,8 @@ dwarf2_compute_name (const char *name, to be able to reference. Ideally, we want the user to be able to reference this entity using either natural or linkage name, but we haven't started looking at this enhancement yet. */ - const char *linkage_name; + const char *linkage_name = dw2_linkage_name (die, cu); - linkage_name = dwarf2_string_attr (die, DW_AT_linkage_name, cu); - if (linkage_name == NULL) - linkage_name = dwarf2_string_attr (die, DW_AT_MIPS_linkage_name, cu); if (linkage_name != NULL) return linkage_name; } @@ -8781,9 +8794,7 @@ dwarf2_physname (const char *name, struct die_info *die, struct dwarf2_cu *cu) back_to = make_cleanup (null_cleanup, NULL); - mangled = dwarf2_string_attr (die, DW_AT_linkage_name, cu); - if (mangled == NULL) - mangled = dwarf2_string_attr (die, DW_AT_MIPS_linkage_name, cu); + mangled = dw2_linkage_name (die, cu); /* rustc emits invalid values for DW_AT_linkage_name. Ignore these. See https://github.com/rust-lang/rust/issues/32925. */ @@ -11825,13 +11836,7 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu) const char *target_physname; /* Prefer the mangled name; otherwise compute the demangled one. */ - target_physname = dwarf2_string_attr (target_die, - DW_AT_linkage_name, - target_cu); - if (target_physname == NULL) - target_physname = dwarf2_string_attr (target_die, - DW_AT_MIPS_linkage_name, - target_cu); + target_physname = dw2_linkage_name (target_die, target_cu); if (target_physname == NULL) target_physname = dwarf2_physname (NULL, target_die, target_cu); if (target_physname == NULL) @@ -19690,12 +19695,8 @@ guess_full_die_structure_name (struct die_info *die, struct dwarf2_cu *cu) { if (child->tag == DW_TAG_subprogram) { - const char *linkage_name; + const char *linkage_name = dw2_linkage_name (child, cu); - linkage_name = dwarf2_string_attr (child, DW_AT_linkage_name, cu); - if (linkage_name == NULL) - linkage_name = dwarf2_string_attr (child, DW_AT_MIPS_linkage_name, - cu); if (linkage_name != NULL) { char *actual_name