Fix dumping codeview line tables when there are multiple debug sections

Codeview line tables for functions in different sections refer to a common
STRING_TABLE_SUBSECTION for filenames.
This happens when building with -Gy or with inline functions with MSVC.

Original patch by Jeff Muizelaar!



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@219125 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Timur Iskhodzhanov
2014-10-06 16:59:44 +00:00
parent 8ea5b7120f
commit 3e3908e2c7
3 changed files with 69 additions and 29 deletions

View File

@@ -82,6 +82,8 @@ private:
const llvm::object::COFFObjectFile *Obj;
RelocMapTy RelocMap;
StringRef CVFileIndexToStringOffsetTable;
StringRef CVStringTable;
};
} // namespace
@@ -440,8 +442,6 @@ void COFFDumper::printCodeViewLineTables(const SectionRef &Section) {
SmallVector<StringRef, 10> FunctionNames;
StringMap<StringRef> FunctionLineTables;
StringRef FileIndexToStringOffsetTable;
StringRef StringTable;
ListScope D(W, "CodeViewLineTables");
{
@@ -502,25 +502,25 @@ void COFFDumper::printCodeViewLineTables(const SectionRef &Section) {
break;
}
case COFF::DEBUG_STRING_TABLE_SUBSECTION:
if (PayloadSize == 0 || StringTable.data() != nullptr ||
if (PayloadSize == 0 || CVStringTable.data() != nullptr ||
Contents.back() != '\0') {
// Empty or duplicate or non-null-terminated subsection.
error(object_error::parse_failed);
return;
}
StringTable = Contents;
CVStringTable = Contents;
break;
case COFF::DEBUG_INDEX_SUBSECTION:
// Holds the translation table from file indices
// to offsets in the string table.
if (PayloadSize == 0 ||
FileIndexToStringOffsetTable.data() != nullptr) {
CVFileIndexToStringOffsetTable.data() != nullptr) {
// Empty or duplicate subsection.
error(object_error::parse_failed);
return;
}
FileIndexToStringOffsetTable = Contents;
CVFileIndexToStringOffsetTable = Contents;
break;
}
Offset += PayloadSize;
@@ -555,7 +555,7 @@ void COFFDumper::printCodeViewLineTables(const SectionRef &Section) {
uint32_t FilenameOffset;
{
DataExtractor SDE(FileIndexToStringOffsetTable, true, 4);
DataExtractor SDE(CVFileIndexToStringOffsetTable, true, 4);
uint32_t OffsetInSDE = OffsetInIndex;
if (!SDE.isValidOffset(OffsetInSDE)) {
error(object_error::parse_failed);
@@ -564,15 +564,15 @@ void COFFDumper::printCodeViewLineTables(const SectionRef &Section) {
FilenameOffset = SDE.getU32(&OffsetInSDE);
}
if (FilenameOffset == 0 || FilenameOffset + 1 >= StringTable.size() ||
StringTable.data()[FilenameOffset - 1] != '\0') {
if (FilenameOffset == 0 || FilenameOffset + 1 >= CVStringTable.size() ||
CVStringTable.data()[FilenameOffset - 1] != '\0') {
// Each string in an F3 subsection should be preceded by a null
// character.
error(object_error::parse_failed);
return;
}
StringRef Filename(StringTable.data() + FilenameOffset);
StringRef Filename(CVStringTable.data() + FilenameOffset);
ListScope S(W, "FilenameSegment");
W.printString("Filename", Filename);
for (unsigned J = 0; J != SegmentLength && DE.isValidOffset(Offset);