Skip to content

Commit 65fde25

Browse files
committed
[llvm-debuginfo-analyzer] Add support for DWARF DW_AT_byte_size
1 parent 8832a59 commit 65fde25

File tree

6 files changed

+29
-1
lines changed

6 files changed

+29
-1
lines changed

llvm/include/llvm/DebugInfo/LogicalView/Core/LVElement.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ class LVElement : public LVObject {
239239
virtual bool isBase() const { return false; }
240240
virtual bool isTemplateParam() const { return false; }
241241

242+
uint32_t getStorageSizeInBytes() const { return (getBitSize() + 7u) / 8u; }
242243
virtual uint32_t getBitSize() const { return 0; }
243244
virtual void setBitSize(uint32_t Size) {}
244245

llvm/include/llvm/DebugInfo/LogicalView/Core/LVScope.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ class LVScope : public LVElement {
9393
LVProperties<Property> Properties;
9494
static LVScopeDispatch Dispatch;
9595

96+
// Size in bits if this scope represents also a compound type.
97+
uint32_t BitSize = 0;
98+
9699
// Coverage factor in units (bytes).
97100
unsigned CoverageFactor = 0;
98101

@@ -269,6 +272,9 @@ class LVScope : public LVElement {
269272
bool removeElement(LVElement *Element) override;
270273
void updateLevel(LVScope *Parent, bool Moved) override;
271274

275+
uint32_t getBitSize() const override { return BitSize; }
276+
void setBitSize(uint32_t Size) override { BitSize = Size; }
277+
272278
void resolve() override;
273279
void resolveName() override;
274280
void resolveReferences() override;

llvm/include/llvm/DebugInfo/LogicalView/Core/LVType.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ class LVType : public LVElement {
5656
LVProperties<Property> Properties;
5757
static LVTypeDispatch Dispatch;
5858

59+
// Size in bits of a symbol of this type.
60+
uint32_t BitSize = 0;
61+
5962
// Find the current type in the given 'Targets'.
6063
LVType *findIn(const LVTypes *Targets) const;
6164

@@ -109,6 +112,10 @@ class LVType : public LVElement {
109112
virtual LVElement *getUnderlyingType() { return nullptr; }
110113
virtual void setUnderlyingType(LVElement *Element) {}
111114

115+
// Return the size in bits of an entity of this type.
116+
uint32_t getBitSize() const override { return BitSize; }
117+
void setBitSize(uint32_t Size) override { BitSize = Size; }
118+
112119
void resolveName() override;
113120
void resolveReferences() override;
114121

llvm/lib/DebugInfo/LogicalView/Core/LVType.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,10 @@ void LVType::print(raw_ostream &OS, bool Full) const {
292292
}
293293

294294
void LVType::printExtra(raw_ostream &OS, bool Full) const {
295-
OS << formattedKind(kind()) << " " << formattedName(getName()) << "\n";
295+
OS << formattedKind(kind()) << " " << formattedName(getName());
296+
if (uint32_t Size = getStorageSizeInBytes())
297+
OS << " [Size = " << Size << "]";
298+
OS << "\n";
296299
}
297300

298301
//===----------------------------------------------------------------------===//

llvm/lib/DebugInfo/LogicalView/Readers/LVDWARFReader.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,11 @@ void LVDWARFReader::processOneAttribute(const DWARFDie &Die,
307307
case dwarf::DW_AT_bit_size:
308308
CurrentElement->setBitSize(GetAsUnsignedConstant());
309309
break;
310+
case dwarf::DW_AT_byte_size:
311+
// Assume 8-bit bytes; this is consistent, e.g. with
312+
// lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp.
313+
CurrentElement->setBitSize(GetAsUnsignedConstant() * 8u);
314+
break;
310315
case dwarf::DW_AT_call_file:
311316
CurrentElement->setCallFilenameIndex(IncrementFileIndex
312317
? GetAsUnsignedConstant() + 1

llvm/unittests/DebugInfo/LogicalView/DWARFReaderTest.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,12 @@ void checkElementSelection(LVReader *Reader) {
155155
ASSERT_NE(Element, nullptr);
156156
EXPECT_NE(Element->getName().find("INTEGER"), StringRef::npos);
157157
EXPECT_EQ(Element->getIsType(), 1);
158+
// Underlying type is `int`
159+
const LVElement *UnderlyingType =
160+
static_cast<LVType *>(Element)->getUnderlyingType();
161+
EXPECT_EQ(UnderlyingType->getIsType(), 1);
162+
EXPECT_EQ(UnderlyingType->getBitSize(), 32u);
163+
EXPECT_EQ(UnderlyingType->getStorageSizeInBytes(), 4u);
158164

159165
Element = MapElements[0x000000000f]; // 'movl %edx, %eax'
160166
ASSERT_NE(Element, nullptr);

0 commit comments

Comments
 (0)