From: David Blaikie Date: Thu, 19 Sep 2013 20:40:26 +0000 (+0000) Subject: Unshift the GDB index/GNU pubnames constants modified in r191025 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=9599f51559c692bb20092da23e3a34b2cc841e03;p=oota-llvm.git Unshift the GDB index/GNU pubnames constants modified in r191025 Based on code review feedback from Eric Christopher, unshifting these constants as they can appear in the gdb_index itself, shifted a further 24 bits. This means that keeping them preshifted is a bit inflexible, so let's not do that. Given the motivation, wrap up some nicer enums, more type safety, and some utility functions. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@191035 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Support/Dwarf.h b/include/llvm/Support/Dwarf.h index f06c4801fd2..9f969728cfe 100644 --- a/include/llvm/Support/Dwarf.h +++ b/include/llvm/Support/Dwarf.h @@ -790,39 +790,50 @@ enum AcceleratorTable { const char *AtomTypeString(unsigned Atom); // Constants for the GNU pubnames/pubtypes extensions supporting gdb index. -enum GDBIndex { - // The gnu_pub* index value looks like: - // - // 0-3 reserved - // 4-6 symbol kind - // 7 0 == global, 1 == static - - // Attributes kinds for the index. - GDB_INDEX_SYMBOL_KIND_OFFSET = 4, - GDB_INDEX_SYMBOL_KIND_MASK = 7 << GDB_INDEX_SYMBOL_KIND_OFFSET, - - // Special value to indicate no attributes are present. - GDB_INDEX_SYMBOL_KIND_NONE = 0, - GDB_INDEX_SYMBOL_KIND_TYPE = 1 << GDB_INDEX_SYMBOL_KIND_OFFSET, - GDB_INDEX_SYMBOL_KIND_VARIABLE = 2 << GDB_INDEX_SYMBOL_KIND_OFFSET, - GDB_INDEX_SYMBOL_KIND_FUNCTION = 3 << GDB_INDEX_SYMBOL_KIND_OFFSET, - GDB_INDEX_SYMBOL_KIND_OTHER = 4 << GDB_INDEX_SYMBOL_KIND_OFFSET, - // 3 unused values. - GDB_INDEX_SYMBOL_KIND_UNUSED5 = 5 << GDB_INDEX_SYMBOL_KIND_OFFSET, - GDB_INDEX_SYMBOL_KIND_UNUSED6 = 6 << GDB_INDEX_SYMBOL_KIND_OFFSET, - GDB_INDEX_SYMBOL_KIND_UNUSED7 = 7 << GDB_INDEX_SYMBOL_KIND_OFFSET, - - // Index values are defined via the set of CUs that define the - // symbol. For the pubnames/pubtypes extensions we need the - // various shifts and masks. - GDB_INDEX_SYMBOL_STATIC_OFFSET = 7, - GDB_INDEX_SYMBOL_STATIC_MASK = 1 << GDB_INDEX_SYMBOL_STATIC_OFFSET, - GDB_INDEX_SYMBOL_STATIC = 1 << GDB_INDEX_SYMBOL_STATIC_OFFSET, - GDB_INDEX_SYMBOL_NON_STATIC = 0 +enum GDBIndexEntryKind { + GIEK_NONE, + GIEK_TYPE, + GIEK_VARIABLE, + GIEK_FUNCTION, + GIEK_OTHER, + GIEK_UNUSED5, + GIEK_UNUSED6, + GIEK_UNUSED7, }; -/// GDBIndexTypeString - Return the string for the specified index type. -const char *GDBIndexTypeString(unsigned Kind); +enum GDBIndexEntryLinkage { + GIEL_EXTERNAL, + GIEL_STATIC +}; + +/// The gnu_pub* kind looks like: +/// +/// 0-3 reserved +/// 4-6 symbol kind +/// 7 0 == global, 1 == static +/// +/// A gdb_index descriptor includes the above kind, shifted 24 bits up with the +/// offset of the cu within the debug_info section stored in those 24 bits. +struct PubIndexEntryDescriptor { + GDBIndexEntryKind Kind; + bool Static; + PubIndexEntryDescriptor(GDBIndexEntryKind Kind, bool Static) + : Kind(Kind), Static(Static) {} + /* implicit */ PubIndexEntryDescriptor(GDBIndexEntryKind Kind) + : Kind(Kind), Static(false) {} + explicit PubIndexEntryDescriptor(uint8_t Value) + : Kind(static_cast((Value & KIND_MASK) >> + KIND_OFFSET)), + Static(Value & STATIC_MASK) {} + uint8_t toBits() { + return Kind << KIND_OFFSET | Static << STATIC_OFFSET; + } +private: + const uint8_t KIND_OFFSET = 4; + const uint8_t KIND_MASK = 7 << KIND_OFFSET; + const uint8_t STATIC_OFFSET = 7; + const uint8_t STATIC_MASK = 1 << STATIC_OFFSET; +}; } // End of namespace dwarf diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index 22533f9aced..a814b72f288 100644 --- a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -2322,10 +2322,11 @@ void DwarfDebug::emitAccelTypes() { // reference in the pubname header doesn't change. /// computeIndexValue - Compute the gdb index value for the DIE and CU. -static uint8_t computeIndexValue(CompileUnit *CU, DIE *Die) { - uint8_t IsStatic = Die->findAttribute(dwarf::DW_AT_external) - ? dwarf::GDB_INDEX_SYMBOL_NON_STATIC - : dwarf::GDB_INDEX_SYMBOL_STATIC; +static dwarf::PubIndexEntryDescriptor computeIndexValue(CompileUnit *CU, + DIE *Die) { + dwarf::GDBIndexEntryLinkage IsStatic = + Die->findAttribute(dwarf::DW_AT_external) ? dwarf::GIEL_EXTERNAL + : dwarf::GIEL_STATIC; switch (Die->getTag()) { case dwarf::DW_TAG_class_type: @@ -2335,19 +2336,19 @@ static uint8_t computeIndexValue(CompileUnit *CU, DIE *Die) { case dwarf::DW_TAG_typedef: case dwarf::DW_TAG_base_type: case dwarf::DW_TAG_subrange_type: - return dwarf::GDB_INDEX_SYMBOL_KIND_TYPE | dwarf::GDB_INDEX_SYMBOL_STATIC; + return dwarf::PubIndexEntryDescriptor(dwarf::GIEK_TYPE, dwarf::GIEL_STATIC); case dwarf::DW_TAG_namespace: - return dwarf::GDB_INDEX_SYMBOL_KIND_TYPE; + return dwarf::GIEK_TYPE; case dwarf::DW_TAG_subprogram: - return dwarf::GDB_INDEX_SYMBOL_KIND_FUNCTION | IsStatic; + return dwarf::PubIndexEntryDescriptor(dwarf::GIEK_FUNCTION, IsStatic); case dwarf::DW_TAG_constant: case dwarf::DW_TAG_variable: - return dwarf::GDB_INDEX_SYMBOL_KIND_VARIABLE | IsStatic; + return dwarf::PubIndexEntryDescriptor(dwarf::GIEK_VARIABLE, IsStatic); case dwarf::DW_TAG_enumerator: - return dwarf::GDB_INDEX_SYMBOL_KIND_VARIABLE | - dwarf::GDB_INDEX_SYMBOL_STATIC; + return dwarf::PubIndexEntryDescriptor(dwarf::GIEK_VARIABLE, + dwarf::GIEL_STATIC); default: - return dwarf::GDB_INDEX_SYMBOL_KIND_NONE; + return dwarf::GIEK_NONE; } } @@ -2401,7 +2402,7 @@ void DwarfDebug::emitDebugPubNames(bool GnuStyle) { if (GnuStyle) { Asm->OutStreamer.AddComment("Index value"); - Asm->EmitInt8(computeIndexValue(TheCU, Entity)); + Asm->EmitInt8(computeIndexValue(TheCU, Entity).toBits()); } if (Asm->isVerbose()) @@ -2460,7 +2461,7 @@ void DwarfDebug::emitDebugPubTypes(bool GnuStyle) { if (GnuStyle) { Asm->OutStreamer.AddComment("Index value"); - Asm->EmitInt8(computeIndexValue(TheCU, Entity)); + Asm->EmitInt8(computeIndexValue(TheCU, Entity).toBits()); } if (Asm->isVerbose()) diff --git a/lib/Support/Dwarf.cpp b/lib/Support/Dwarf.cpp index 5c780ddc2b8..3bacdd35793 100644 --- a/lib/Support/Dwarf.cpp +++ b/lib/Support/Dwarf.cpp @@ -739,26 +739,3 @@ const char *llvm::dwarf::AtomTypeString(unsigned AT) { } return 0; } - -const char *llvm::dwarf::GDBIndexTypeString(unsigned Kind) { - switch (Kind) { - case GDB_INDEX_SYMBOL_KIND_NONE: - return "case GDB_INDEX_SYMBOL_KIND_NONE"; - case GDB_INDEX_SYMBOL_KIND_TYPE: - return "case GDB_INDEX_SYMBOL_KIND_TYPE"; - case GDB_INDEX_SYMBOL_KIND_VARIABLE: - return "case GDB_INDEX_SYMBOL_KIND_VARIABLE"; - case GDB_INDEX_SYMBOL_KIND_FUNCTION: - return "case GDB_INDEX_SYMBOL_KIND_FUNCTION"; - case GDB_INDEX_SYMBOL_KIND_OTHER: - return "case GDB_INDEX_SYMBOL_KIND_OTHER"; - // 3 unused bits. - case GDB_INDEX_SYMBOL_KIND_UNUSED5: - return "case GDB_INDEX_SYMBOL_KIND_UNUSED5"; - case GDB_INDEX_SYMBOL_KIND_UNUSED6: - return "case GDB_INDEX_SYMBOL_KIND_UNUSED6"; - case GDB_INDEX_SYMBOL_KIND_UNUSED7: - return "case GDB_INDEX_SYMBOL_KIND_UNUSED7"; - } - return 0; -}