Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit b5c7e2f

Browse files
author
Aleksandr Urakov
committed
[PDB] Extend IPDBSession's interface to retrieve frame data
Summary: This patch just extends the `IPDBSession` interface to allow retrieving of frame data through it, and adds an implementation over DIA. It is needed for an implementation (for now with DIA) of the conversion from FPO programs to DWARF expressions mentioned in D53086. Reviewers: zturner, asmith, rnk Reviewed By: asmith Subscribers: mgorny, aprantl, JDevlieghere, llvm-commits Differential Revision: https://reviews.llvm.org/D53324 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@344886 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent c2ec04c commit b5c7e2f

File tree

14 files changed

+247
-0
lines changed

14 files changed

+247
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//==- DIAEnumFrameData.h --------------------------------------- -*- C++ -*-==//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// This file is distributed under the University of Illinois Open Source
6+
// License. See LICENSE.TXT for details.
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#ifndef LLVM_DEBUGINFO_PDB_DIA_DIAENUMFRAMEDATA_H
11+
#define LLVM_DEBUGINFO_PDB_DIA_DIAENUMFRAMEDATA_H
12+
13+
#include "DIASupport.h"
14+
#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
15+
#include "llvm/DebugInfo/PDB/IPDBFrameData.h"
16+
17+
namespace llvm {
18+
namespace pdb {
19+
20+
class DIASession;
21+
22+
class DIAEnumFrameData : public IPDBEnumChildren<IPDBFrameData> {
23+
public:
24+
explicit DIAEnumFrameData(const DIASession &PDBSession,
25+
CComPtr<IDiaEnumFrameData> DiaEnumerator);
26+
27+
uint32_t getChildCount() const override;
28+
ChildTypePtr getChildAtIndex(uint32_t Index) const override;
29+
ChildTypePtr getNext() override;
30+
void reset() override;
31+
32+
private:
33+
const DIASession &Session;
34+
CComPtr<IDiaEnumFrameData> Enumerator;
35+
};
36+
37+
} // namespace pdb
38+
} // namespace llvm
39+
40+
#endif
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//===- DIAFrameData.h - DIA Impl. of IPDBFrameData ---------------- C++ -*-===//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// This file is distributed under the University of Illinois Open Source
6+
// License. See LICENSE.TXT for details.
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#ifndef LLVM_DEBUGINFO_PDB_DIA_DIAFRAMEDATA_H
11+
#define LLVM_DEBUGINFO_PDB_DIA_DIAFRAMEDATA_H
12+
13+
#include "DIASupport.h"
14+
#include "llvm/DebugInfo/PDB/IPDBFrameData.h"
15+
16+
namespace llvm {
17+
namespace pdb {
18+
19+
class DIASession;
20+
21+
class DIAFrameData : public IPDBFrameData {
22+
public:
23+
explicit DIAFrameData(const DIASession &PDBSession,
24+
CComPtr<IDiaFrameData> DiaFrameData);
25+
26+
uint32_t getAddressOffset() const override;
27+
uint32_t getAddressSection() const override;
28+
uint32_t getLengthBlock() const override;
29+
std::string getProgram() const override;
30+
uint32_t getRelativeVirtualAddress() const override;
31+
uint64_t getVirtualAddress() const override;
32+
33+
private:
34+
const DIASession &Session;
35+
CComPtr<IDiaFrameData> FrameData;
36+
};
37+
38+
} // namespace pdb
39+
} // namespace llvm
40+
41+
#endif

include/llvm/DebugInfo/PDB/DIA/DIASession.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class DIASession : public IPDBSession {
8585

8686
std::unique_ptr<IPDBEnumSectionContribs> getSectionContribs() const override;
8787

88+
std::unique_ptr<IPDBEnumFrameData> getFrameData() const override;
8889
private:
8990
CComPtr<IDiaSession> Session;
9091
};
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//===- IPDBFrameData.h - base interface for frame data ----------*- C++ -*-===//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// This file is distributed under the University of Illinois Open Source
6+
// License. See LICENSE.TXT for details.
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#ifndef LLVM_DEBUGINFO_PDB_IPDBFRAMEDATA_H
11+
#define LLVM_DEBUGINFO_PDB_IPDBFRAMEDATA_H
12+
13+
#include <cstdint>
14+
#include <string>
15+
16+
namespace llvm {
17+
namespace pdb {
18+
19+
/// IPDBFrameData defines an interface used to represent a frame data of some
20+
/// code block.
21+
class IPDBFrameData {
22+
public:
23+
virtual ~IPDBFrameData();
24+
25+
virtual uint32_t getAddressOffset() const = 0;
26+
virtual uint32_t getAddressSection() const = 0;
27+
virtual uint32_t getLengthBlock() const = 0;
28+
virtual std::string getProgram() const = 0;
29+
virtual uint32_t getRelativeVirtualAddress() const = 0;
30+
virtual uint64_t getVirtualAddress() const = 0;
31+
};
32+
33+
} // namespace pdb
34+
} // namespace llvm
35+
36+
#endif

include/llvm/DebugInfo/PDB/IPDBSession.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ class IPDBSession {
9191

9292
virtual std::unique_ptr<IPDBEnumSectionContribs>
9393
getSectionContribs() const = 0;
94+
95+
virtual std::unique_ptr<IPDBEnumFrameData>
96+
getFrameData() const = 0;
9497
};
9598
} // namespace pdb
9699
} // namespace llvm

include/llvm/DebugInfo/PDB/Native/NativeSession.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ class NativeSession : public IPDBSession {
9393

9494
std::unique_ptr<IPDBEnumSectionContribs> getSectionContribs() const override;
9595

96+
std::unique_ptr<IPDBEnumFrameData> getFrameData() const override;
97+
9698
PDBFile &getPDBFile() { return *Pdb; }
9799
const PDBFile &getPDBFile() const { return *Pdb; }
98100

include/llvm/DebugInfo/PDB/PDBTypes.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "llvm/DebugInfo/CodeView/CodeView.h"
1414
#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
15+
#include "llvm/DebugInfo/PDB/IPDBFrameData.h"
1516
#include "llvm/DebugInfo/PDB/Native/RawTypes.h"
1617
#include <cctype>
1718
#include <cstddef>
@@ -71,6 +72,7 @@ using IPDBEnumLineNumbers = IPDBEnumChildren<IPDBLineNumber>;
7172
using IPDBEnumTables = IPDBEnumChildren<IPDBTable>;
7273
using IPDBEnumInjectedSources = IPDBEnumChildren<IPDBInjectedSource>;
7374
using IPDBEnumSectionContribs = IPDBEnumChildren<IPDBSectionContrib>;
75+
using IPDBEnumFrameData = IPDBEnumChildren<IPDBFrameData>;
7476

7577
/// Specifies which PDB reader implementation is to be used. Only a value
7678
/// of PDB_ReaderType::DIA is currently supported, but Native is in the works.

lib/DebugInfo/PDB/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ if(LLVM_ENABLE_DIA_SDK)
1414
add_pdb_impl_folder(DIA
1515
DIA/DIADataStream.cpp
1616
DIA/DIAEnumDebugStreams.cpp
17+
DIA/DIAEnumFrameData.cpp
1718
DIA/DIAEnumInjectedSources.cpp
1819
DIA/DIAEnumLineNumbers.cpp
1920
DIA/DIAEnumSectionContribs.cpp
2021
DIA/DIAEnumSourceFiles.cpp
2122
DIA/DIAEnumSymbols.cpp
2223
DIA/DIAEnumTables.cpp
2324
DIA/DIAError.cpp
25+
DIA/DIAFrameData.cpp
2426
DIA/DIAInjectedSource.cpp
2527
DIA/DIALineNumber.cpp
2628
DIA/DIARawSymbol.cpp
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//==- DIAEnumFrameData.cpp ---------------------------------------*- C++ -*-==//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// This file is distributed under the University of Illinois Open Source
6+
// License. See LICENSE.TXT for details.
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#include "llvm/DebugInfo/PDB/DIA/DIAEnumFrameData.h"
11+
#include "llvm/DebugInfo/PDB/DIA/DIAFrameData.h"
12+
#include "llvm/DebugInfo/PDB/DIA/DIASession.h"
13+
14+
using namespace llvm::pdb;
15+
16+
DIAEnumFrameData::DIAEnumFrameData(const DIASession &PDBSession,
17+
CComPtr<IDiaEnumFrameData> DiaEnumerator)
18+
: Session(PDBSession), Enumerator(DiaEnumerator) {}
19+
20+
uint32_t DIAEnumFrameData::getChildCount() const {
21+
LONG Count = 0;
22+
return (S_OK == Enumerator->get_Count(&Count)) ? Count : 0;
23+
}
24+
25+
std::unique_ptr<IPDBFrameData>
26+
DIAEnumFrameData::getChildAtIndex(uint32_t Index) const {
27+
CComPtr<IDiaFrameData> Item;
28+
if (S_OK != Enumerator->Item(Index, &Item))
29+
return nullptr;
30+
31+
return std::unique_ptr<IPDBFrameData>(new DIAFrameData(Session, Item));
32+
}
33+
34+
std::unique_ptr<IPDBFrameData> DIAEnumFrameData::getNext() {
35+
CComPtr<IDiaFrameData> Item;
36+
ULONG NumFetched = 0;
37+
if (S_OK != Enumerator->Next(1, &Item, &NumFetched))
38+
return nullptr;
39+
40+
return std::unique_ptr<IPDBFrameData>(new DIAFrameData(Session, Item));
41+
}
42+
43+
void DIAEnumFrameData::reset() { Enumerator->Reset(); }
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//===- DIAFrameData.cpp - DIA impl. of IPDBFrameData -------------- C++ -*-===//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// This file is distributed under the University of Illinois Open Source
6+
// License. See LICENSE.TXT for details.
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#include "llvm/DebugInfo/PDB/DIA/DIAFrameData.h"
11+
#include "llvm/DebugInfo/PDB/DIA/DIASession.h"
12+
#include "llvm/DebugInfo/PDB/DIA/DIAUtils.h"
13+
14+
using namespace llvm::pdb;
15+
16+
DIAFrameData::DIAFrameData(const DIASession &PDBSession,
17+
CComPtr<IDiaFrameData> DiaFrameData)
18+
: Session(PDBSession), FrameData(DiaFrameData) {}
19+
20+
template <typename ArgType>
21+
ArgType
22+
PrivateGetDIAValue(IDiaFrameData *FrameData,
23+
HRESULT (__stdcall IDiaFrameData::*Method)(ArgType *)) {
24+
ArgType Value;
25+
if (S_OK == (FrameData->*Method)(&Value))
26+
return static_cast<ArgType>(Value);
27+
28+
return ArgType();
29+
}
30+
31+
uint32_t DIAFrameData::getAddressOffset() const {
32+
return PrivateGetDIAValue(FrameData, &IDiaFrameData::get_addressOffset);
33+
}
34+
35+
uint32_t DIAFrameData::getAddressSection() const {
36+
return PrivateGetDIAValue(FrameData, &IDiaFrameData::get_addressSection);
37+
}
38+
39+
uint32_t DIAFrameData::getLengthBlock() const {
40+
return PrivateGetDIAValue(FrameData, &IDiaFrameData::get_lengthBlock);
41+
}
42+
43+
std::string DIAFrameData::getProgram() const {
44+
return invokeBstrMethod(*FrameData, &IDiaFrameData::get_program);
45+
}
46+
47+
uint32_t DIAFrameData::getRelativeVirtualAddress() const {
48+
return PrivateGetDIAValue(FrameData,
49+
&IDiaFrameData::get_relativeVirtualAddress);
50+
}
51+
52+
uint64_t DIAFrameData::getVirtualAddress() const {
53+
return PrivateGetDIAValue(FrameData, &IDiaFrameData::get_virtualAddress);
54+
}

lib/DebugInfo/PDB/DIA/DIASession.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "llvm/DebugInfo/PDB/DIA/DIASession.h"
1010
#include "llvm/ADT/STLExtras.h"
1111
#include "llvm/DebugInfo/PDB/DIA/DIAEnumDebugStreams.h"
12+
#include "llvm/DebugInfo/PDB/DIA/DIAEnumFrameData.h"
1213
#include "llvm/DebugInfo/PDB/DIA/DIAEnumInjectedSources.h"
1314
#include "llvm/DebugInfo/PDB/DIA/DIAEnumLineNumbers.h"
1415
#include "llvm/DebugInfo/PDB/DIA/DIAEnumSectionContribs.h"
@@ -419,3 +420,13 @@ DIASession::getSectionContribs() const {
419420

420421
return llvm::make_unique<DIAEnumSectionContribs>(*this, Sections);
421422
}
423+
424+
std::unique_ptr<IPDBEnumFrameData>
425+
DIASession::getFrameData() const {
426+
CComPtr<IDiaEnumFrameData> FD =
427+
getTableEnumerator<IDiaEnumFrameData>(*Session);
428+
if (!FD)
429+
return nullptr;
430+
431+
return llvm::make_unique<DIAEnumFrameData>(*this, FD);
432+
}

lib/DebugInfo/PDB/Native/NativeSession.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,11 @@ NativeSession::getSectionContribs() const {
200200
return nullptr;
201201
}
202202

203+
std::unique_ptr<IPDBEnumFrameData>
204+
NativeSession::getFrameData() const {
205+
return nullptr;
206+
}
207+
203208
void NativeSession::initializeExeSymbol() {
204209
if (ExeSymbol == 0)
205210
ExeSymbol = Cache.createSymbol<NativeExeSymbol>();

lib/DebugInfo/PDB/PDBInterfaceAnchors.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
//===----------------------------------------------------------------------===//
1313

1414
#include "llvm/DebugInfo/PDB/IPDBDataStream.h"
15+
#include "llvm/DebugInfo/PDB/IPDBFrameData.h"
1516
#include "llvm/DebugInfo/PDB/IPDBInjectedSource.h"
1617
#include "llvm/DebugInfo/PDB/IPDBLineNumber.h"
1718
#include "llvm/DebugInfo/PDB/IPDBRawSymbol.h"
@@ -35,3 +36,5 @@ IPDBTable::~IPDBTable() = default;
3536
IPDBInjectedSource::~IPDBInjectedSource() = default;
3637

3738
IPDBSectionContrib::~IPDBSectionContrib() = default;
39+
40+
IPDBFrameData::~IPDBFrameData() = default;

unittests/DebugInfo/PDB/PDBApiTest.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ class MockSession : public IPDBSession {
159159
std::unique_ptr<IPDBEnumSectionContribs> getSectionContribs() const override {
160160
return nullptr;
161161
}
162+
163+
std::unique_ptr<IPDBEnumFrameData> getFrameData() const override {
164+
return nullptr;
165+
}
162166
};
163167

164168
class MockRawSymbol : public IPDBRawSymbol {

0 commit comments

Comments
 (0)