Skip to content

Commit 37e48e4

Browse files
authored
Fix crash due to un-checked error in LVReaderHandler::handleArchive method (#118951)
[llvm-debuginfo-analyzer] Fix crash due to un-checked error in LVReaderHandler::handleArchive method. - Added README describing how to generated the binary files used for the test. - A follow up patch to add extra ASSERT_NE Committed on behalf of @aurelien35
1 parent bdf7270 commit 37e48e4

File tree

4 files changed

+124
-0
lines changed

4 files changed

+124
-0
lines changed

llvm/lib/DebugInfo/LogicalView/LVReaderHandler.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ Error LVReaderHandler::handleArchive(LVReaders &Readers, StringRef Filename,
8888
Filename.str().c_str());
8989
}
9090

91+
if (Err)
92+
return createStringError(errorToErrorCode(std::move(Err)), "%s",
93+
Filename.str().c_str());
9194
return Error::success();
9295
}
9396

llvm/unittests/DebugInfo/LogicalView/CodeViewReaderTest.cpp

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ 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 =
36+
"test-codeview-msvc.lib(test-codeview-msvc.o)";
3437
const char *CodeViewPdbMsvc = "test-codeview-pdb-msvc.o";
3538

3639
// Helper function to get the first scope child from the given parent.
@@ -193,6 +196,72 @@ void checkElementPropertiesMsvcCodeview(LVReader *Reader) {
193196
EXPECT_EQ(Lines->size(), 0x0eu);
194197
}
195198

199+
// Check the logical elements basic properties (MSVC library - Codeview).
200+
void checkElementPropertiesMsvcLibraryCodeview(LVReader *Reader) {
201+
LVScopeRoot *Root = Reader->getScopesRoot();
202+
LVScopeCompileUnit *CompileUnit =
203+
static_cast<LVScopeCompileUnit *>(getFirstScopeChild(Root));
204+
LVScopeFunction *Function =
205+
static_cast<LVScopeFunction *>(getFirstScopeChild(CompileUnit));
206+
207+
EXPECT_EQ(Root->getFileFormatName(), "COFF-x86-64");
208+
EXPECT_EQ(Root->getName(), CodeViewMsvcLibContentName);
209+
210+
EXPECT_EQ(CompileUnit->getBaseAddress(), 0u);
211+
EXPECT_TRUE(CompileUnit->getProducer().starts_with("Microsoft"));
212+
EXPECT_EQ(CompileUnit->getName(), "test.cpp");
213+
214+
EXPECT_EQ(Function->lineCount(), 14u);
215+
EXPECT_EQ(Function->scopeCount(), 1u);
216+
EXPECT_EQ(Function->symbolCount(), 3u);
217+
EXPECT_EQ(Function->typeCount(), 0u);
218+
EXPECT_EQ(Function->rangeCount(), 1u);
219+
220+
const LVLocations *Ranges = Function->getRanges();
221+
ASSERT_NE(Ranges, nullptr);
222+
ASSERT_EQ(Ranges->size(), 1u);
223+
LVLocations::const_iterator IterLocation = Ranges->begin();
224+
LVLocation *Location = (*IterLocation);
225+
EXPECT_STREQ(Location->getIntervalInfo().c_str(),
226+
"{Range} Lines 2:9 [0x0000000000:0x0000000031]");
227+
228+
LVRange RangeList;
229+
Function->getRanges(RangeList);
230+
231+
const LVRangeEntries &RangeEntries = RangeList.getEntries();
232+
ASSERT_EQ(RangeEntries.size(), 2u);
233+
LVRangeEntries::const_iterator IterRanges = RangeEntries.cbegin();
234+
LVRangeEntry RangeEntry = *IterRanges;
235+
EXPECT_EQ(RangeEntry.lower(), 0u);
236+
EXPECT_EQ(RangeEntry.upper(), 0x31u);
237+
EXPECT_EQ(RangeEntry.scope()->getLineNumber(), 0u);
238+
EXPECT_EQ(RangeEntry.scope()->getName(), "foo");
239+
EXPECT_EQ(RangeEntry.scope()->getOffset(), 0u);
240+
241+
++IterRanges;
242+
RangeEntry = *IterRanges;
243+
EXPECT_EQ(RangeEntry.lower(), 0x1bu);
244+
EXPECT_EQ(RangeEntry.upper(), 0x28u);
245+
EXPECT_EQ(RangeEntry.scope()->getLineNumber(), 0u);
246+
EXPECT_EQ(RangeEntry.scope()->getName(), "foo::?");
247+
EXPECT_EQ(RangeEntry.scope()->getOffset(), 0u);
248+
249+
const LVPublicNames &PublicNames = CompileUnit->getPublicNames();
250+
ASSERT_EQ(PublicNames.size(), 1u);
251+
LVPublicNames::const_iterator IterNames = PublicNames.cbegin();
252+
LVScope *Foo = (*IterNames).first;
253+
EXPECT_EQ(Foo->getName(), "foo");
254+
EXPECT_EQ(Foo->getLineNumber(), 0u);
255+
LVNameInfo NameInfo = (*IterNames).second;
256+
EXPECT_EQ(NameInfo.first, 0u);
257+
EXPECT_EQ(NameInfo.second, 0x31u);
258+
259+
// Lines (debug and assembler) for 'foo'.
260+
const LVLines *Lines = Foo->getLines();
261+
ASSERT_NE(Lines, nullptr);
262+
EXPECT_EQ(Lines->size(), 0x0eu);
263+
}
264+
196265
// Check the logical elements basic properties (MSVC - PDB).
197266
void checkElementPropertiesMsvcCodeviewPdb(LVReader *Reader) {
198267
LVScopeRoot *Root = Reader->getScopesRoot();
@@ -370,6 +439,11 @@ void elementProperties(SmallString<128> &InputsDir) {
370439
createReader(ReaderHandler, InputsDir, CodeViewMsvc);
371440
checkElementPropertiesMsvcCodeview(Reader.get());
372441
}
442+
{
443+
std::unique_ptr<LVReader> Reader =
444+
createReader(ReaderHandler, InputsDir, CodeViewMsvcLib);
445+
checkElementPropertiesMsvcLibraryCodeview(Reader.get());
446+
}
373447
{
374448
std::unique_ptr<LVReader> Reader =
375449
createReader(ReaderHandler, InputsDir, CodeViewPdbMsvc);
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
LogicalView unit tests input files generation
2+
=============================================
3+
4+
# Source file: test.cpp
5+
6+
```
7+
using INTPTR = const int *;
8+
int foo(INTPTR ParamPtr, unsigned ParamUnsigned, bool ParamBool) {
9+
if (ParamBool) {
10+
typedef int INTEGER;
11+
const INTEGER CONSTANT = 7;
12+
return CONSTANT;
13+
}
14+
return ParamUnsigned;
15+
}
16+
```
17+
18+
# Linux binary files:
19+
20+
## test-dwarf-clang.o
21+
22+
```clang -c -w -g -gdwarf-4 -O0 test.cpp -o test-dwarf-clang.o```
23+
24+
## test-dwarf-gcc.o
25+
26+
```g++ -c -w -g -O0 test.cpp -o test-dwarf-gcc.o```
27+
28+
# Windows binary files:
29+
30+
## test-codeview-clang.o
31+
32+
```clang++.exe --target=x86_64-windows -c -w -g -gcodeview test.cpp -o test-codeview-clang.o```
33+
34+
## test-codeview-msvc.o
35+
36+
```cl.exe /nologo /EHsc /Od /Z7 /Fotest-codeview-msvc.o /c test.cpp```
37+
38+
## test-codeview-pdb-msvc.o and test-codeview-pdb-msvc-.pdb
39+
40+
```cl.exe /nologo /EHsc /Od /Zi /Fotest-codeview-pdb-msvc.o /Fdtest-codeview-pdb-msvc-.pdb /c test.cpp```
41+
42+
## test-codeview-msvc.lib
43+
44+
This file is a static library embedding the **test-codeview-msvc.o** object file.
45+
It is generated by the "lib.exe" tool shipped with MSVC compiler.
46+
47+
```lib.exe /OUT:test-codeview-msvc.lib test-codeview-msvc.o```
Binary file not shown.

0 commit comments

Comments
 (0)