[llvm] r191035 - Unshift the GDB index/GNU pubnames constants modified in r191025
David Blaikie
dblaikie at gmail.com
Thu Sep 19 13:40:26 PDT 2013
Author: dblaikie
Date: Thu Sep 19 15:40:26 2013
New Revision: 191035
URL: http://llvm.org/viewvc/llvm-project?rev=191035&view=rev
Log:
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.
Modified:
llvm/trunk/include/llvm/Support/Dwarf.h
llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
llvm/trunk/lib/Support/Dwarf.cpp
Modified: llvm/trunk/include/llvm/Support/Dwarf.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Dwarf.h?rev=191035&r1=191034&r2=191035&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/Dwarf.h (original)
+++ llvm/trunk/include/llvm/Support/Dwarf.h Thu Sep 19 15:40:26 2013
@@ -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,
+enum GDBIndexEntryKind {
+ GIEK_NONE,
+ GIEK_TYPE,
+ GIEK_VARIABLE,
+ GIEK_FUNCTION,
+ GIEK_OTHER,
+ GIEK_UNUSED5,
+ GIEK_UNUSED6,
+ GIEK_UNUSED7,
+};
- // 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 GDBIndexEntryLinkage {
+ GIEL_EXTERNAL,
+ GIEL_STATIC
};
-/// GDBIndexTypeString - Return the string for the specified index type.
-const char *GDBIndexTypeString(unsigned Kind);
+/// 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<GDBIndexEntryKind>((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
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=191035&r1=191034&r2=191035&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Thu Sep 19 15:40:26 2013
@@ -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(Compile
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
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
if (GnuStyle) {
Asm->OutStreamer.AddComment("Index value");
- Asm->EmitInt8(computeIndexValue(TheCU, Entity));
+ Asm->EmitInt8(computeIndexValue(TheCU, Entity).toBits());
}
if (Asm->isVerbose())
Modified: llvm/trunk/lib/Support/Dwarf.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Dwarf.cpp?rev=191035&r1=191034&r2=191035&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Dwarf.cpp (original)
+++ llvm/trunk/lib/Support/Dwarf.cpp Thu Sep 19 15:40:26 2013
@@ -739,26 +739,3 @@ const char *llvm::dwarf::AtomTypeString(
}
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;
-}
More information about the llvm-commits
mailing list