2017-05-30 18:36:15 +02:00
|
|
|
//===- DebugInlineeLinesSubsection.cpp ------------------------*- C++-*-===//
|
2017-05-02 18:56:09 +02:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-05-30 18:36:15 +02:00
|
|
|
#include "llvm/DebugInfo/CodeView/DebugInlineeLinesSubsection.h"
|
2017-05-02 18:56:09 +02:00
|
|
|
|
|
|
|
#include "llvm/DebugInfo/CodeView/CodeViewError.h"
|
2017-05-30 18:36:15 +02:00
|
|
|
#include "llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h"
|
2017-05-30 19:13:33 +02:00
|
|
|
#include "llvm/DebugInfo/CodeView/DebugStringTableSubsection.h"
|
2017-05-30 18:36:15 +02:00
|
|
|
#include "llvm/DebugInfo/CodeView/DebugSubsectionRecord.h"
|
2017-05-02 18:56:09 +02:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace llvm::codeview;
|
|
|
|
|
2017-06-09 19:54:36 +02:00
|
|
|
Error VarStreamArrayExtractor<InlineeSourceLine>::
|
|
|
|
operator()(BinaryStreamRef Stream, uint32_t &Len, InlineeSourceLine &Item) {
|
2017-05-02 18:56:09 +02:00
|
|
|
BinaryStreamReader Reader(Stream);
|
|
|
|
|
|
|
|
if (auto EC = Reader.readObject(Item.Header))
|
|
|
|
return EC;
|
|
|
|
|
2017-05-03 07:34:00 +02:00
|
|
|
if (HasExtraFiles) {
|
2017-05-02 18:56:09 +02:00
|
|
|
uint32_t ExtraFileCount;
|
|
|
|
if (auto EC = Reader.readInteger(ExtraFileCount))
|
|
|
|
return EC;
|
|
|
|
if (auto EC = Reader.readArray(Item.ExtraFiles, ExtraFileCount))
|
|
|
|
return EC;
|
|
|
|
}
|
|
|
|
|
|
|
|
Len = Reader.getOffset();
|
|
|
|
return Error::success();
|
|
|
|
}
|
|
|
|
|
2017-05-30 18:36:15 +02:00
|
|
|
DebugInlineeLinesSubsectionRef::DebugInlineeLinesSubsectionRef()
|
|
|
|
: DebugSubsectionRef(DebugSubsectionKind::InlineeLines) {}
|
2017-05-02 18:56:09 +02:00
|
|
|
|
2017-05-30 18:36:15 +02:00
|
|
|
Error DebugInlineeLinesSubsectionRef::initialize(BinaryStreamReader Reader) {
|
2017-05-02 18:56:09 +02:00
|
|
|
if (auto EC = Reader.readEnum(Signature))
|
|
|
|
return EC;
|
|
|
|
|
2017-06-09 19:54:36 +02:00
|
|
|
Lines.getExtractor().HasExtraFiles = hasExtraFiles();
|
|
|
|
if (auto EC = Reader.readArray(Lines, Reader.bytesRemaining()))
|
2017-05-02 18:56:09 +02:00
|
|
|
return EC;
|
|
|
|
|
|
|
|
assert(Reader.bytesRemaining() == 0);
|
|
|
|
return Error::success();
|
|
|
|
}
|
|
|
|
|
2017-05-30 18:36:15 +02:00
|
|
|
bool DebugInlineeLinesSubsectionRef::hasExtraFiles() const {
|
2017-05-02 18:56:09 +02:00
|
|
|
return Signature == InlineeLinesSignature::ExtraFiles;
|
|
|
|
}
|
|
|
|
|
2017-05-30 18:36:15 +02:00
|
|
|
DebugInlineeLinesSubsection::DebugInlineeLinesSubsection(
|
|
|
|
DebugChecksumsSubsection &Checksums, bool HasExtraFiles)
|
|
|
|
: DebugSubsection(DebugSubsectionKind::InlineeLines), Checksums(Checksums),
|
|
|
|
HasExtraFiles(HasExtraFiles) {}
|
2017-05-02 18:56:09 +02:00
|
|
|
|
2017-05-30 19:13:33 +02:00
|
|
|
uint32_t DebugInlineeLinesSubsection::calculateSerializedSize() const {
|
2017-05-02 18:56:09 +02:00
|
|
|
// 4 bytes for the signature
|
|
|
|
uint32_t Size = sizeof(InlineeLinesSignature);
|
|
|
|
|
|
|
|
// one header for each entry.
|
|
|
|
Size += Entries.size() * sizeof(InlineeSourceLineHeader);
|
|
|
|
if (HasExtraFiles) {
|
|
|
|
// If extra files are enabled, one count for each entry.
|
|
|
|
Size += Entries.size() * sizeof(uint32_t);
|
|
|
|
|
|
|
|
// And one file id for each file.
|
|
|
|
Size += ExtraFileCount * sizeof(uint32_t);
|
|
|
|
}
|
|
|
|
assert(Size % 4 == 0);
|
|
|
|
return Size;
|
|
|
|
}
|
|
|
|
|
2017-05-30 19:13:33 +02:00
|
|
|
Error DebugInlineeLinesSubsection::commit(BinaryStreamWriter &Writer) const {
|
2017-05-02 18:56:09 +02:00
|
|
|
InlineeLinesSignature Sig = InlineeLinesSignature::Normal;
|
|
|
|
if (HasExtraFiles)
|
|
|
|
Sig = InlineeLinesSignature::ExtraFiles;
|
|
|
|
|
|
|
|
if (auto EC = Writer.writeEnum(Sig))
|
|
|
|
return EC;
|
|
|
|
|
|
|
|
for (const auto &E : Entries) {
|
|
|
|
if (auto EC = Writer.writeObject(E.Header))
|
|
|
|
return EC;
|
|
|
|
|
|
|
|
if (!HasExtraFiles)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (auto EC = Writer.writeInteger<uint32_t>(E.ExtraFiles.size()))
|
|
|
|
return EC;
|
|
|
|
if (auto EC = Writer.writeArray(makeArrayRef(E.ExtraFiles)))
|
|
|
|
return EC;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Error::success();
|
|
|
|
}
|
|
|
|
|
2017-05-30 18:36:15 +02:00
|
|
|
void DebugInlineeLinesSubsection::addExtraFile(StringRef FileName) {
|
2017-05-03 19:11:40 +02:00
|
|
|
uint32_t Offset = Checksums.mapChecksumOffset(FileName);
|
|
|
|
|
2017-05-02 18:56:09 +02:00
|
|
|
auto &Entry = Entries.back();
|
2017-05-03 19:11:40 +02:00
|
|
|
Entry.ExtraFiles.push_back(ulittle32_t(Offset));
|
2017-05-02 18:56:09 +02:00
|
|
|
++ExtraFileCount;
|
|
|
|
}
|
|
|
|
|
2017-05-30 18:36:15 +02:00
|
|
|
void DebugInlineeLinesSubsection::addInlineSite(TypeIndex FuncId,
|
|
|
|
StringRef FileName,
|
|
|
|
uint32_t SourceLine) {
|
2017-05-03 19:11:40 +02:00
|
|
|
uint32_t Offset = Checksums.mapChecksumOffset(FileName);
|
|
|
|
|
2017-05-02 18:56:09 +02:00
|
|
|
Entries.emplace_back();
|
|
|
|
auto &Entry = Entries.back();
|
2017-05-03 19:11:40 +02:00
|
|
|
Entry.Header.FileID = Offset;
|
2017-05-02 18:56:09 +02:00
|
|
|
Entry.Header.SourceLineNum = SourceLine;
|
|
|
|
Entry.Header.Inlinee = FuncId;
|
|
|
|
}
|