Skip to content

[lldb][NFCI] Unify DW_TAG -> string conversions #90657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 32 additions & 30 deletions lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,9 +452,9 @@ TypeSP DWARFASTParserClang::ParseTypeFromDWARF(const SymbolContext &sc,
log,
"DWARFASTParserClang::ParseTypeFromDWARF "
"(die = {0:x16}, decl_ctx = {1:p} (die "
"{2:x16})) {3} name = '{4}')",
"{2:x16})) {3} ({4}) name = '{5}')",
die.GetOffset(), static_cast<void *>(context), context_die.GetOffset(),
die.GetTagAsCString(), die.GetName());
DW_TAG_value_to_name(die.Tag()), die.Tag(), die.GetName());
}

Type *type_ptr = dwarf->GetDIEToType().lookup(die.GetDIE());
Expand Down Expand Up @@ -765,9 +765,10 @@ DWARFASTParserClang::ParseTypeModifier(const SymbolContext &sc,
if (log)
dwarf->GetObjectFile()->GetModule()->LogMessage(
log,
"SymbolFileDWARF::ParseType (die = {0:x16}) {1} '{2}' "
"SymbolFileDWARF::ParseType (die = {0:x16}) {1} ({2}) '{3}' "
"is Objective-C 'id' built-in type.",
die.GetOffset(), die.GetTagAsCString(), die.GetName());
die.GetOffset(), DW_TAG_value_to_name(die.Tag()), die.Tag(),
die.GetName());
clang_type = m_ast.GetBasicType(eBasicTypeObjCID);
encoding_data_type = Type::eEncodingIsUID;
attrs.type.Clear();
Expand All @@ -776,9 +777,10 @@ DWARFASTParserClang::ParseTypeModifier(const SymbolContext &sc,
if (log)
dwarf->GetObjectFile()->GetModule()->LogMessage(
log,
"SymbolFileDWARF::ParseType (die = {0:x16}) {1} '{2}' "
"SymbolFileDWARF::ParseType (die = {0:x16}) {1} ({2}) '{3}' "
"is Objective-C 'Class' built-in type.",
die.GetOffset(), die.GetTagAsCString(), die.GetName());
die.GetOffset(), DW_TAG_value_to_name(die.Tag()), die.Tag(),
die.GetName());
clang_type = m_ast.GetBasicType(eBasicTypeObjCClass);
encoding_data_type = Type::eEncodingIsUID;
attrs.type.Clear();
Expand All @@ -787,9 +789,10 @@ DWARFASTParserClang::ParseTypeModifier(const SymbolContext &sc,
if (log)
dwarf->GetObjectFile()->GetModule()->LogMessage(
log,
"SymbolFileDWARF::ParseType (die = {0:x16}) {1} '{2}' "
"SymbolFileDWARF::ParseType (die = {0:x16}) {1} ({2}) '{3}' "
"is Objective-C 'selector' built-in type.",
die.GetOffset(), die.GetTagAsCString(), die.GetName());
die.GetOffset(), DW_TAG_value_to_name(die.Tag()), die.Tag(),
die.GetName());
clang_type = m_ast.GetBasicType(eBasicTypeObjCSel);
encoding_data_type = Type::eEncodingIsUID;
attrs.type.Clear();
Expand All @@ -808,10 +811,10 @@ DWARFASTParserClang::ParseTypeModifier(const SymbolContext &sc,
if (log)
dwarf->GetObjectFile()->GetModule()->LogMessage(
log,
"SymbolFileDWARF::ParseType (die = {0:x16}) {1} "
"'{2}' is 'objc_object*', which we overrode to "
"'id'.",
die.GetOffset(), die.GetTagAsCString(), die.GetName());
"SymbolFileDWARF::ParseType (die = {0:x16}) {1} ({2}) '{3}' "
"is 'objc_object*', which we overrode to 'id'.",
die.GetOffset(), DW_TAG_value_to_name(die.Tag()), die.Tag(),
die.GetName());
clang_type = m_ast.GetBasicType(eBasicTypeObjCID);
encoding_data_type = Type::eEncodingIsUID;
attrs.type.Clear();
Expand Down Expand Up @@ -870,10 +873,10 @@ TypeSP DWARFASTParserClang::ParseEnum(const SymbolContext &sc,
if (log) {
dwarf->GetObjectFile()->GetModule()->LogMessage(
log,
"SymbolFileDWARF({0:p}) - {1:x16}}: {2} type \"{3}\" is a "
"forward declaration, complete type is {4:x8}",
"SymbolFileDWARF({0:p}) - {1:x16}}: {2} ({3}) type \"{4}\" is a "
"forward declaration, complete type is {5:x8}",
static_cast<void *>(this), die.GetOffset(),
DW_TAG_value_to_name(tag), attrs.name.GetCString(),
DW_TAG_value_to_name(tag), tag, attrs.name.GetCString(),
type_sp->GetID());
}

Expand Down Expand Up @@ -1734,11 +1737,10 @@ DWARFASTParserClang::ParseStructureLikeDIE(const SymbolContext &sc,
if (log) {
dwarf->GetObjectFile()->GetModule()->LogMessage(
log,
"SymbolFileDWARF({0:p}) - {1:x16}: {2} type "
"\"{3}\" is an "
"incomplete objc type, complete type is {4:x8}",
"SymbolFileDWARF({0:p}) - {1:x16}: {2} ({3}) type \"{4}\" is an "
"incomplete objc type, complete type is {5:x8}",
static_cast<void *>(this), die.GetOffset(),
DW_TAG_value_to_name(tag), attrs.name.GetCString(),
DW_TAG_value_to_name(tag), tag, attrs.name.GetCString(),
type_sp->GetID());
}

Expand All @@ -1760,10 +1762,10 @@ DWARFASTParserClang::ParseStructureLikeDIE(const SymbolContext &sc,
if (log) {
dwarf->GetObjectFile()->GetModule()->LogMessage(
log,
"SymbolFileDWARF({0:p}) - {1:x16}: {2} type \"{3}\" is a "
"SymbolFileDWARF({0:p}) - {1:x16}: {2} ({3}) type \"{4}\" is a "
"forward declaration, trying to find complete type",
static_cast<void *>(this), die.GetOffset(), DW_TAG_value_to_name(tag),
attrs.name.GetCString());
tag, attrs.name.GetCString());
}

// See if the type comes from a Clang module and if so, track down
Expand All @@ -1789,10 +1791,10 @@ DWARFASTParserClang::ParseStructureLikeDIE(const SymbolContext &sc,
if (log) {
dwarf->GetObjectFile()->GetModule()->LogMessage(
log,
"SymbolFileDWARF({0:p}) - {1:x16}: {2} type \"{3}\" is a "
"forward declaration, complete type is {4:x8}",
"SymbolFileDWARF({0:p}) - {1:x16}: {2} ({3}) type \"{4}\" is a "
"forward declaration, complete type is {5:x8}",
static_cast<void *>(this), die.GetOffset(),
DW_TAG_value_to_name(tag), attrs.name.GetCString(),
DW_TAG_value_to_name(tag), tag, attrs.name.GetCString(),
type_sp->GetID());
}

Expand Down Expand Up @@ -1836,10 +1838,10 @@ DWARFASTParserClang::ParseStructureLikeDIE(const SymbolContext &sc,
if (log) {
dwarf->GetObjectFile()->GetModule()->LogMessage(
log,
"SymbolFileDWARF({0:p}) - {1:x16}: {2} type \"{3}\" "
"SymbolFileDWARF({0:p}) - {1:x16}: {2} ({3}) type \"{4}\" "
"clang::ClassTemplateDecl failed to return a decl.",
static_cast<void *>(this), die.GetOffset(),
DW_TAG_value_to_name(tag), attrs.name.GetCString());
DW_TAG_value_to_name(tag), tag, attrs.name.GetCString());
}
return TypeSP();
}
Expand Down Expand Up @@ -3018,11 +3020,11 @@ void DWARFASTParserClang::ParseSingleMember(
this_field_info.bit_offset)))) {
ObjectFile *objfile = die.GetDWARF()->GetObjectFile();
objfile->GetModule()->ReportWarning(
"{0:x16}: {1} bitfield named \"{2}\" has invalid "
"bit offset ({3:x8}) member will be ignored. Please file a bug "
"{0:x16}: {1} ({2}) bitfield named \"{3}\" has invalid "
"bit offset ({4:x8}) member will be ignored. Please file a bug "
"against the "
"compiler and include the preprocessed output for {4}\n",
die.GetID(), DW_TAG_value_to_name(tag), attrs.name,
"compiler and include the preprocessed output for {5}\n",
die.GetID(), DW_TAG_value_to_name(tag), tag, attrs.name,
this_field_info.bit_offset, GetUnitName(parent_die).c_str());
return;
}
Expand Down
4 changes: 0 additions & 4 deletions lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ dw_tag_t DWARFBaseDIE::Tag() const {
return llvm::dwarf::DW_TAG_null;
}

const char *DWARFBaseDIE::GetTagAsCString() const {
return DW_TAG_value_to_name(Tag());
}

const char *DWARFBaseDIE::GetAttributeValueAsString(const dw_attr_t attr,
const char *fail_value) const {
if (IsValid())
Expand Down
2 changes: 0 additions & 2 deletions lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ class DWARFBaseDIE {
// Accessing information about a DIE
dw_tag_t Tag() const;

const char *GetTagAsCString() const;

dw_offset_t GetOffset() const;

// Get the LLDB user ID for this DIE. This is often just the DIE offset,
Expand Down
16 changes: 5 additions & 11 deletions lldb/source/Plugins/SymbolFile/DWARF/DWARFDefines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,12 @@
namespace lldb_private::plugin {
namespace dwarf {

const char *DW_TAG_value_to_name(uint32_t val) {
static char invalid[100];

if (val == 0)
return "NULL";
llvm::StringRef DW_TAG_value_to_name(dw_tag_t tag) {
static constexpr llvm::StringLiteral s_unknown_tag_name("<unknown DW_TAG>");
if (llvm::StringRef tag_name = llvm::dwarf::TagString(tag); !tag_name.empty())
return tag_name;

llvm::StringRef llvmstr = llvm::dwarf::TagString(val);
if (llvmstr.empty()) {
snprintf(invalid, sizeof(invalid), "Unknown DW_TAG constant: 0x%x", val);
return invalid;
}
return llvmstr.data();
return s_unknown_tag_name;
}

const char *DW_AT_value_to_name(uint32_t val) {
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Plugins/SymbolFile/DWARF/DWARFDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace dwarf {

typedef uint32_t DRC_class; // Holds DRC_* class bitfields

const char *DW_TAG_value_to_name(uint32_t val);
llvm::StringRef DW_TAG_value_to_name(dw_tag_t tag);

const char *DW_AT_value_to_name(uint32_t val);

Expand Down
63 changes: 33 additions & 30 deletions lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1555,8 +1555,10 @@ Type *SymbolFileDWARF::ResolveTypeUID(const DWARFDIE &die,
Log *log = GetLog(DWARFLog::DebugInfo);
if (log)
GetObjectFile()->GetModule()->LogMessage(
log, "SymbolFileDWARF::ResolveTypeUID (die = {0:x16}) {1} '{2}'",
die.GetOffset(), die.GetTagAsCString(), die.GetName());
log,
"SymbolFileDWARF::ResolveTypeUID (die = {0:x16}) {1} ({2}) '{3}'",
die.GetOffset(), DW_TAG_value_to_name(die.Tag()), die.Tag(),
die.GetName());

// We might be coming in in the middle of a type tree (a class within a
// class, an enum within a class), so parse any needed parent DIEs before
Expand All @@ -1572,11 +1574,10 @@ Type *SymbolFileDWARF::ResolveTypeUID(const DWARFDIE &die,
if (log)
GetObjectFile()->GetModule()->LogMessage(
log,
"SymbolFileDWARF::ResolveTypeUID (die = {0:x16}) "
"{1} '{2}' "
"resolve parent forward type for {3:x16})",
die.GetOffset(), die.GetTagAsCString(), die.GetName(),
decl_ctx_die.GetOffset());
"SymbolFileDWARF::ResolveTypeUID (die = {0:x16}) {1} ({2}) "
"'{3}' resolve parent forward type for {4:x16})",
die.GetOffset(), DW_TAG_value_to_name(die.Tag()), die.Tag(),
die.GetName(), decl_ctx_die.GetOffset());
} break;

default:
Expand Down Expand Up @@ -1644,9 +1645,9 @@ bool SymbolFileDWARF::CompleteType(CompilerType &compiler_type) {
Log *log = GetLog(DWARFLog::DebugInfo | DWARFLog::TypeCompletion);
if (log)
GetObjectFile()->GetModule()->LogMessageVerboseBacktrace(
log, "{0:x8}: {1} '{2}' resolving forward declaration...",
dwarf_die.GetID(), dwarf_die.GetTagAsCString(),
type->GetName().AsCString());
log, "{0:x8}: {1} ({2}) '{3}' resolving forward declaration...",
dwarf_die.GetID(), DW_TAG_value_to_name(dwarf_die.Tag()),
dwarf_die.Tag(), type->GetName().AsCString());
assert(compiler_type);
if (DWARFASTParser *dwarf_ast = GetDWARFParser(*dwarf_die.GetCU()))
return dwarf_ast->CompleteTypeFromDWARF(dwarf_die, type, compiler_type);
Expand All @@ -1665,8 +1666,9 @@ Type *SymbolFileDWARF::ResolveType(const DWARFDIE &die,
return type;

GetObjectFile()->GetModule()->ReportError(
"Parsing a die that is being parsed die: {0:x16}: {1} {2}",
die.GetOffset(), die.GetTagAsCString(), die.GetName());
"Parsing a die that is being parsed die: {0:x16}: {1} ({2}) {3}",
die.GetOffset(), DW_TAG_value_to_name(die.Tag()), die.Tag(),
die.GetName());

} else
return type;
Expand Down Expand Up @@ -3134,9 +3136,9 @@ SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(const DWARFDIE &die) {
if (log) {
GetObjectFile()->GetModule()->LogMessage(
log,
"SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag={0}, "
"name='{1}')",
DW_TAG_value_to_name(tag), die.GetName());
"SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag={0} "
"({1}), name='{2}')",
DW_TAG_value_to_name(tag), tag, die.GetName());
}

// Get the type system that we are looking to find a type for. We will
Expand Down Expand Up @@ -3184,10 +3186,10 @@ SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(const DWARFDIE &die) {
GetObjectFile()->GetModule()->LogMessage(
log,
"SymbolFileDWARF::"
"FindDefinitionTypeForDWARFDeclContext(tag={0}, "
"name='{1}') ignoring die={2:x16} ({3})",
DW_TAG_value_to_name(tag), die.GetName(), type_die.GetOffset(),
type_die.GetName());
"FindDefinitionTypeForDWARFDeclContext(tag={0} ({1}), "
"name='{2}') ignoring die={3:x16} ({4})",
DW_TAG_value_to_name(tag), tag, die.GetName(),
type_die.GetOffset(), type_die.GetName());
}
return true;
}
Expand All @@ -3197,9 +3199,9 @@ SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(const DWARFDIE &die) {
GetObjectFile()->GetModule()->LogMessage(
log,
"SymbolFileDWARF::"
"FindDefinitionTypeForDWARFDeclContext(tag={0}, "
"name='{1}') trying die={2:x16} ({3})",
DW_TAG_value_to_name(tag), die.GetName(), type_die.GetOffset(),
"FindDefinitionTypeForDWARFDeclContext(tag={0} ({1}), name='{2}') "
"trying die={3:x16} ({4})",
DW_TAG_value_to_name(tag), tag, die.GetName(), type_die.GetOffset(),
type_dwarf_decl_ctx.GetQualifiedName());
}

Expand Down Expand Up @@ -3650,8 +3652,8 @@ VariableSP SymbolFileDWARF::ParseVariableDIE(const SymbolContext &sc,
StreamString strm;
location->DumpLocation(&strm, eDescriptionLevelFull, nullptr);
GetObjectFile()->GetModule()->ReportError(
"{0:x16}: {1} has an invalid location: {2}", die.GetOffset(),
die.GetTagAsCString(), strm.GetData());
"{0:x16}: {1} ({2}) has an invalid location: {3}", die.GetOffset(),
DW_TAG_value_to_name(die.Tag()), die.Tag(), strm.GetData());
}
if (location_DW_OP_addr != LLDB_INVALID_ADDRESS)
is_static_lifetime = true;
Expand Down Expand Up @@ -3839,19 +3841,20 @@ void SymbolFileDWARF::ParseAndAppendGlobalVariable(
variable_list_sp = sc.comp_unit->GetVariableList(false);
} else {
GetObjectFile()->GetModule()->ReportError(
"parent {0:x8} {1} with no valid compile unit in "
"symbol context for {2:x8} {3}.\n",
sc_parent_die.GetID(), sc_parent_die.GetTagAsCString(), die.GetID(),
die.GetTagAsCString());
"parent {0:x8} {1} ({2}) with no valid compile unit in "
"symbol context for {3:x8} {4} ({5}).\n",
sc_parent_die.GetID(), DW_TAG_value_to_name(sc_parent_die.Tag()),
sc_parent_die.Tag(), die.GetID(), DW_TAG_value_to_name(die.Tag()),
die.Tag());
return;
}
break;

default:
GetObjectFile()->GetModule()->ReportError(
"didn't find appropriate parent DIE for variable list for {0:x8} "
"{1}.\n",
die.GetID(), die.GetTagAsCString());
"{1} ({2}).\n",
die.GetID(), DW_TAG_value_to_name(die.Tag()), die.Tag());
return;
}

Expand Down