Skip to content

Commit 4f2e094

Browse files
author
Your Name
committed
Add MSVC CodeView informations read from library test case
1 parent 3dbff90 commit 4f2e094

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

llvm/unittests/DebugInfo/LogicalView/CodeViewReaderTest.cpp

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ namespace {
3131

3232
const char *CodeViewClang = "test-codeview-clang.o";
3333
const char *CodeViewMsvc = "test-codeview-msvc.o";
34+
const char *CodeViewMsvcLib = "test-codeview-msvc.lib";
35+
const char *CodeViewMsvcLibContentName = "test-codeview-msvc.lib(test-codeview-msvc.o)";
3436
const char *CodeViewPdbMsvc = "test-codeview-pdb-msvc.o";
3537

3638
// Helper function to get the first scope child from the given parent.
@@ -193,6 +195,72 @@ void checkElementPropertiesMsvcCodeview(LVReader *Reader) {
193195
EXPECT_EQ(Lines->size(), 0x0eu);
194196
}
195197

198+
// Check the logical elements basic properties (MSVC library - Codeview).
199+
void checkElementPropertiesMsvcLibraryCodeview(LVReader *Reader) {
200+
LVScopeRoot *Root = Reader->getScopesRoot();
201+
LVScopeCompileUnit *CompileUnit =
202+
static_cast<LVScopeCompileUnit *>(getFirstScopeChild(Root));
203+
LVScopeFunction *Function =
204+
static_cast<LVScopeFunction *>(getFirstScopeChild(CompileUnit));
205+
206+
EXPECT_EQ(Root->getFileFormatName(), "COFF-x86-64");
207+
EXPECT_EQ(Root->getName(), CodeViewMsvcLibContentName);
208+
209+
EXPECT_EQ(CompileUnit->getBaseAddress(), 0u);
210+
EXPECT_TRUE(CompileUnit->getProducer().starts_with("Microsoft"));
211+
EXPECT_EQ(CompileUnit->getName(), "test.cpp");
212+
213+
EXPECT_EQ(Function->lineCount(), 14u);
214+
EXPECT_EQ(Function->scopeCount(), 1u);
215+
EXPECT_EQ(Function->symbolCount(), 3u);
216+
EXPECT_EQ(Function->typeCount(), 0u);
217+
EXPECT_EQ(Function->rangeCount(), 1u);
218+
219+
const LVLocations *Ranges = Function->getRanges();
220+
ASSERT_NE(Ranges, nullptr);
221+
ASSERT_EQ(Ranges->size(), 1u);
222+
LVLocations::const_iterator IterLocation = Ranges->begin();
223+
LVLocation *Location = (*IterLocation);
224+
EXPECT_STREQ(Location->getIntervalInfo().c_str(),
225+
"{Range} Lines 2:9 [0x0000000000:0x0000000031]");
226+
227+
LVRange RangeList;
228+
Function->getRanges(RangeList);
229+
230+
const LVRangeEntries &RangeEntries = RangeList.getEntries();
231+
ASSERT_EQ(RangeEntries.size(), 2u);
232+
LVRangeEntries::const_iterator IterRanges = RangeEntries.cbegin();
233+
LVRangeEntry RangeEntry = *IterRanges;
234+
EXPECT_EQ(RangeEntry.lower(), 0u);
235+
EXPECT_EQ(RangeEntry.upper(), 0x31u);
236+
EXPECT_EQ(RangeEntry.scope()->getLineNumber(), 0u);
237+
EXPECT_EQ(RangeEntry.scope()->getName(), "foo");
238+
EXPECT_EQ(RangeEntry.scope()->getOffset(), 0u);
239+
240+
++IterRanges;
241+
RangeEntry = *IterRanges;
242+
EXPECT_EQ(RangeEntry.lower(), 0x1bu);
243+
EXPECT_EQ(RangeEntry.upper(), 0x28u);
244+
EXPECT_EQ(RangeEntry.scope()->getLineNumber(), 0u);
245+
EXPECT_EQ(RangeEntry.scope()->getName(), "foo::?");
246+
EXPECT_EQ(RangeEntry.scope()->getOffset(), 0u);
247+
248+
const LVPublicNames &PublicNames = CompileUnit->getPublicNames();
249+
ASSERT_EQ(PublicNames.size(), 1u);
250+
LVPublicNames::const_iterator IterNames = PublicNames.cbegin();
251+
LVScope *Foo = (*IterNames).first;
252+
EXPECT_EQ(Foo->getName(), "foo");
253+
EXPECT_EQ(Foo->getLineNumber(), 0u);
254+
LVNameInfo NameInfo = (*IterNames).second;
255+
EXPECT_EQ(NameInfo.first, 0u);
256+
EXPECT_EQ(NameInfo.second, 0x31u);
257+
258+
// Lines (debug and assembler) for 'foo'.
259+
const LVLines *Lines = Foo->getLines();
260+
ASSERT_NE(Lines, nullptr);
261+
EXPECT_EQ(Lines->size(), 0x0eu);
262+
}
263+
196264
// Check the logical elements basic properties (MSVC - PDB).
197265
void checkElementPropertiesMsvcCodeviewPdb(LVReader *Reader) {
198266
LVScopeRoot *Root = Reader->getScopesRoot();
@@ -370,6 +438,11 @@ void elementProperties(SmallString<128> &InputsDir) {
370438
createReader(ReaderHandler, InputsDir, CodeViewMsvc);
371439
checkElementPropertiesMsvcCodeview(Reader.get());
372440
}
441+
{
442+
std::unique_ptr<LVReader> Reader =
443+
createReader(ReaderHandler, InputsDir, CodeViewMsvcLib);
444+
checkElementPropertiesMsvcLibraryCodeview(Reader.get());
445+
}
373446
{
374447
std::unique_ptr<LVReader> Reader =
375448
createReader(ReaderHandler, InputsDir, CodeViewPdbMsvc);
Binary file not shown.

0 commit comments

Comments
 (0)