From 9025f9559d778f425dbcc7f55917a6dccbb7d2f1 Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Wed, 21 Mar 2018 11:46:37 +0000 Subject: [dwarf] Unify unknown dwarf enum formatting code Summary: We have had at least three pieces of code (in DWARFAbbreviationDeclaration, DWARFAcceleratorTable and DWARFDie) that have hand-rolled support for dumping unknown dwarf enum values. While not terrible, they are a bit distracting and enable small differences to creep in (Unknown_ffff vs. Unknown_0xffff). I ended up needing to add a fourth place (DWARFVerifier), so it seems it would be a good time to centralize. This patch creates an alternative to the XXXString dumping functions in the BinaryFormat library, which formats an unknown value as DW_TYPE_unknown_1234, instead of just an empty string. It is based on the formatv function, as that allows us to avoid materializing the string for unknown values (and because this way I don't have to invent a name for the new functions :P). In this patch I add formatters for dwarf attributes, forms, tags, and index attributes as these are the ones in use currently, but adding other enums is straight-forward. Reviewers: dblaikie, JDevlieghere, aprantl Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D44570 llvm-svn: 328090 --- .../DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) (limited to 'llvm/lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp') diff --git a/llvm/lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp b/llvm/lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp index 688a85c9da3..adada672af0 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp @@ -16,6 +16,7 @@ #include "llvm/DebugInfo/DWARF/DWARFUnit.h" #include "llvm/Support/DataExtractor.h" #include "llvm/Support/Format.h" +#include "llvm/Support/FormatVariadic.h" #include "llvm/Support/raw_ostream.h" #include #include @@ -126,26 +127,11 @@ DWARFAbbreviationDeclaration::extract(DataExtractor Data, } void DWARFAbbreviationDeclaration::dump(raw_ostream &OS) const { - auto tagString = TagString(getTag()); OS << '[' << getCode() << "] "; - if (!tagString.empty()) - OS << tagString; - else - OS << format("DW_TAG_Unknown_%x", getTag()); + OS << formatv("{0}", getTag()); OS << "\tDW_CHILDREN_" << (hasChildren() ? "yes" : "no") << '\n'; for (const AttributeSpec &Spec : AttributeSpecs) { - OS << '\t'; - auto attrString = AttributeString(Spec.Attr); - if (!attrString.empty()) - OS << attrString; - else - OS << format("DW_AT_Unknown_%x", Spec.Attr); - OS << '\t'; - auto formString = FormEncodingString(Spec.Form); - if (!formString.empty()) - OS << formString; - else - OS << format("DW_FORM_Unknown_%x", Spec.Form); + OS << formatv("\t{0}\t{1}", Spec.Attr, Spec.Form); if (Spec.isImplicitConst()) OS << '\t' << Spec.getImplicitConstValue(); OS << '\n'; -- cgit v1.2.3