-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Fix crash due to un-checked error in LVReaderHandler::handleArchive method #118951
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
40c944b
f48fab6
4f2e094
c7cf1e1
8a5973f
336844c
3212dae
a64d550
d86c8dd
81ba620
7db47c2
ae340e3
f164a86
1944610
df64aff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,9 @@ namespace { | |
|
||
const char *CodeViewClang = "test-codeview-clang.o"; | ||
const char *CodeViewMsvc = "test-codeview-msvc.o"; | ||
const char *CodeViewMsvcLib = "test-codeview-msvc.lib"; | ||
const char *CodeViewMsvcLibContentName = | ||
"test-codeview-msvc.lib(test-codeview-msvc.o)"; | ||
const char *CodeViewPdbMsvc = "test-codeview-pdb-msvc.o"; | ||
|
||
// Helper function to get the first scope child from the given parent. | ||
|
@@ -193,6 +196,72 @@ void checkElementPropertiesMsvcCodeview(LVReader *Reader) { | |
EXPECT_EQ(Lines->size(), 0x0eu); | ||
} | ||
|
||
// Check the logical elements basic properties (MSVC library - Codeview). | ||
void checkElementPropertiesMsvcLibraryCodeview(LVReader *Reader) { | ||
LVScopeRoot *Root = Reader->getScopesRoot(); | ||
LVScopeCompileUnit *CompileUnit = | ||
static_cast<LVScopeCompileUnit *>(getFirstScopeChild(Root)); | ||
LVScopeFunction *Function = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same check here for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will add this check in a separated patch. |
||
static_cast<LVScopeFunction *>(getFirstScopeChild(CompileUnit)); | ||
|
||
EXPECT_EQ(Root->getFileFormatName(), "COFF-x86-64"); | ||
EXPECT_EQ(Root->getName(), CodeViewMsvcLibContentName); | ||
|
||
EXPECT_EQ(CompileUnit->getBaseAddress(), 0u); | ||
EXPECT_TRUE(CompileUnit->getProducer().starts_with("Microsoft")); | ||
EXPECT_EQ(CompileUnit->getName(), "test.cpp"); | ||
|
||
EXPECT_EQ(Function->lineCount(), 14u); | ||
EXPECT_EQ(Function->scopeCount(), 1u); | ||
EXPECT_EQ(Function->symbolCount(), 3u); | ||
EXPECT_EQ(Function->typeCount(), 0u); | ||
EXPECT_EQ(Function->rangeCount(), 1u); | ||
|
||
const LVLocations *Ranges = Function->getRanges(); | ||
ASSERT_NE(Ranges, nullptr); | ||
ASSERT_EQ(Ranges->size(), 1u); | ||
LVLocations::const_iterator IterLocation = Ranges->begin(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check the iterators for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will add this check in a separated patch. |
||
LVLocation *Location = (*IterLocation); | ||
EXPECT_STREQ(Location->getIntervalInfo().c_str(), | ||
"{Range} Lines 2:9 [0x0000000000:0x0000000031]"); | ||
|
||
LVRange RangeList; | ||
Function->getRanges(RangeList); | ||
|
||
const LVRangeEntries &RangeEntries = RangeList.getEntries(); | ||
ASSERT_EQ(RangeEntries.size(), 2u); | ||
LVRangeEntries::const_iterator IterRanges = RangeEntries.cbegin(); | ||
LVRangeEntry RangeEntry = *IterRanges; | ||
EXPECT_EQ(RangeEntry.lower(), 0u); | ||
EXPECT_EQ(RangeEntry.upper(), 0x31u); | ||
EXPECT_EQ(RangeEntry.scope()->getLineNumber(), 0u); | ||
EXPECT_EQ(RangeEntry.scope()->getName(), "foo"); | ||
EXPECT_EQ(RangeEntry.scope()->getOffset(), 0u); | ||
|
||
++IterRanges; | ||
RangeEntry = *IterRanges; | ||
EXPECT_EQ(RangeEntry.lower(), 0x1bu); | ||
EXPECT_EQ(RangeEntry.upper(), 0x28u); | ||
EXPECT_EQ(RangeEntry.scope()->getLineNumber(), 0u); | ||
EXPECT_EQ(RangeEntry.scope()->getName(), "foo::?"); | ||
EXPECT_EQ(RangeEntry.scope()->getOffset(), 0u); | ||
|
||
const LVPublicNames &PublicNames = CompileUnit->getPublicNames(); | ||
ASSERT_EQ(PublicNames.size(), 1u); | ||
LVPublicNames::const_iterator IterNames = PublicNames.cbegin(); | ||
LVScope *Foo = (*IterNames).first; | ||
EXPECT_EQ(Foo->getName(), "foo"); | ||
EXPECT_EQ(Foo->getLineNumber(), 0u); | ||
LVNameInfo NameInfo = (*IterNames).second; | ||
EXPECT_EQ(NameInfo.first, 0u); | ||
EXPECT_EQ(NameInfo.second, 0x31u); | ||
|
||
// Lines (debug and assembler) for 'foo'. | ||
const LVLines *Lines = Foo->getLines(); | ||
ASSERT_NE(Lines, nullptr); | ||
EXPECT_EQ(Lines->size(), 0x0eu); | ||
} | ||
|
||
// Check the logical elements basic properties (MSVC - PDB). | ||
void checkElementPropertiesMsvcCodeviewPdb(LVReader *Reader) { | ||
LVScopeRoot *Root = Reader->getScopesRoot(); | ||
|
@@ -370,6 +439,11 @@ void elementProperties(SmallString<128> &InputsDir) { | |
createReader(ReaderHandler, InputsDir, CodeViewMsvc); | ||
checkElementPropertiesMsvcCodeview(Reader.get()); | ||
} | ||
{ | ||
std::unique_ptr<LVReader> Reader = | ||
createReader(ReaderHandler, InputsDir, CodeViewMsvcLib); | ||
checkElementPropertiesMsvcLibraryCodeview(Reader.get()); | ||
} | ||
{ | ||
std::unique_ptr<LVReader> Reader = | ||
createReader(ReaderHandler, InputsDir, CodeViewPdbMsvc); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
LogicalView unit tests input files generation | ||
============================================= | ||
|
||
# Source file: test.cpp | ||
|
||
``` | ||
using INTPTR = const int *; | ||
int foo(INTPTR ParamPtr, unsigned ParamUnsigned, bool ParamBool) { | ||
if (ParamBool) { | ||
typedef int INTEGER; | ||
const INTEGER CONSTANT = 7; | ||
return CONSTANT; | ||
} | ||
return ParamUnsigned; | ||
} | ||
``` | ||
|
||
# Linux binary files: | ||
|
||
## test-dwarf-clang.o | ||
|
||
```clang -c -w -g -gdwarf-4 -O0 test.cpp -o test-dwarf-clang.o``` | ||
|
||
## test-dwarf-gcc.o | ||
|
||
```g++ -c -w -g -O0 test.cpp -o test-dwarf-gcc.o``` | ||
|
||
# Windows binary files: | ||
|
||
## test-codeview-clang.o | ||
|
||
```clang++.exe --target=x86_64-windows -c -w -g -gcodeview test.cpp -o test-codeview-clang.o``` | ||
|
||
## test-codeview-msvc.o | ||
|
||
```cl.exe /nologo /EHsc /Od /Z7 /Fotest-codeview-msvc.o /c test.cpp``` | ||
|
||
## test-codeview-pdb-msvc.o and test-codeview-pdb-msvc-.pdb | ||
|
||
```cl.exe /nologo /EHsc /Od /Zi /Fotest-codeview-pdb-msvc.o /Fdtest-codeview-pdb-msvc-.pdb /c test.cpp``` | ||
|
||
## test-codeview-msvc.lib | ||
|
||
This file is a static library embedding the **test-codeview-msvc.o** object file. | ||
It is generated by the "lib.exe" tool shipped with MSVC compiler. | ||
|
||
```lib.exe /OUT:test-codeview-msvc.lib test-codeview-msvc.o``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check that
Root
is non-nullASSERT_NE(Root, nullptr);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will add this check in a separated patch.