[PATCH] D107875: [DWARF] Add findAttribute to DWARFAbbreviationDeclaration

Alexander Yermolovich via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 11 09:21:34 PDT 2021


ayermolo updated this revision to Diff 365772.
ayermolo added a comment.

clang-format


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D107875/new/

https://reviews.llvm.org/D107875

Files:
  llvm/include/llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h
  llvm/lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp


Index: llvm/lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp
===================================================================
--- llvm/lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp
+++ llvm/lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp
@@ -60,13 +60,15 @@
 
   // Read all of the abbreviation attributes and forms.
   while (true) {
+    uint32_t AOff = *OffsetPtr;
     auto A = static_cast<Attribute>(Data.getULEB128(OffsetPtr));
+    uint32_t FOff = *OffsetPtr;
     auto F = static_cast<Form>(Data.getULEB128(OffsetPtr));
     if (A && F) {
       bool IsImplicitConst = (F == DW_FORM_implicit_const);
       if (IsImplicitConst) {
         int64_t V = Data.getSLEB128(OffsetPtr);
-        AttributeSpecs.push_back(AttributeSpec(A, F, V));
+        AttributeSpecs.push_back(AttributeSpec(A, F, V, AOff, FOff));
         continue;
       }
       Optional<uint8_t> ByteSize;
@@ -108,7 +110,7 @@
         break;
       }
       // Record this attribute and its fixed size if it has one.
-      AttributeSpecs.push_back(AttributeSpec(A, F, ByteSize));
+      AttributeSpecs.push_back(AttributeSpec(A, F, ByteSize, AOff, FOff));
     } else if (A == 0 && F == 0) {
       // We successfully reached the end of this abbreviation declaration
       // since both attribute and form are zero.
@@ -138,6 +140,15 @@
   OS << '\n';
 }
 
+const DWARFAbbreviationDeclaration::AttributeSpec *
+DWARFAbbreviationDeclaration::findAttribute(dwarf::Attribute Attr) const {
+  for (uint32_t I = 0, E = AttributeSpecs.size(); I != E; ++I) {
+    if (AttributeSpecs[I].Attr == Attr)
+      return &AttributeSpecs[I];
+  }
+  return nullptr;
+}
+
 Optional<uint32_t>
 DWARFAbbreviationDeclaration::findAttributeIndex(dwarf::Attribute Attr) const {
   for (uint32_t i = 0, e = AttributeSpecs.size(); i != e; ++i) {
Index: llvm/include/llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h
===================================================================
--- llvm/include/llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h
+++ llvm/include/llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h
@@ -27,12 +27,15 @@
 class DWARFAbbreviationDeclaration {
 public:
   struct AttributeSpec {
-    AttributeSpec(dwarf::Attribute A, dwarf::Form F, int64_t Value)
-        : Attr(A), Form(F), Value(Value) {
+    AttributeSpec(dwarf::Attribute A, dwarf::Form F, int64_t Value,
+                  uint32_t AttrOffset = -1U, uint32_t FormOffset = -1U)
+        : Attr(A), Form(F), AttrOffset(AttrOffset), FormOffset(FormOffset),
+          Value(Value) {
       assert(isImplicitConst());
     }
-    AttributeSpec(dwarf::Attribute A, dwarf::Form F, Optional<uint8_t> ByteSize)
-        : Attr(A), Form(F) {
+    AttributeSpec(dwarf::Attribute A, dwarf::Form F, Optional<uint8_t> ByteSize,
+                  uint32_t AttrOffset = -1U, uint32_t FormOffset = -1U)
+        : Attr(A), Form(F), AttrOffset(AttrOffset), FormOffset(FormOffset) {
       assert(!isImplicitConst());
       this->ByteSize.HasByteSize = ByteSize.hasValue();
       if (this->ByteSize.HasByteSize)
@@ -41,6 +44,8 @@
 
     dwarf::Attribute Attr;
     dwarf::Form Form;
+    uint32_t AttrOffset;
+    uint32_t FormOffset;
 
   private:
     /// The following field is used for ByteSize for non-implicit_const
@@ -121,6 +126,8 @@
     return AttributeSpecs[idx].getImplicitConstValue();
   }
 
+  const AttributeSpec *findAttribute(dwarf::Attribute Attr) const;
+
   /// Get the index of the specified attribute.
   ///
   /// Searches the this abbreviation declaration for the index of the specified


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107875.365772.patch
Type: text/x-patch
Size: 3565 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210811/5639f084/attachment.bin>


More information about the llvm-commits mailing list