mirror of
https://github.com/Gericom/teak-llvm.git
synced 2025-06-20 12:05:48 -04:00

VarStreamArray was built on the assumption that it is backed by a StreamRef, and offset 0 of that StreamRef is the first byte of the first record in the array. This is a logical and intuitive assumption, but unfortunately we have use cases where it doesn't hold. Specifically, a PDB module's symbol stream is prefixed by 4 bytes containing a magic value, and the first byte of record data in the array is actually at offset 4 of this byte sequence. Previously, we would just truncate the first 4 bytes and then construct the VarStreamArray with the resulting StreamRef, so that offset 0 of the underlying stream did correspond to the first byte of the first record, but this is problematic, because symbol records reference other symbol records by the absolute offset including that initial magic 4 bytes. So if another record wants to refer to the first record in the array, it would say "the record at offset 4". This led to extremely confusing hacks and semantics in loading code, and after spending 30 minutes trying to get some math right and failing, I decided to fix this in the underlying implementation of VarStreamArray. Now, we can say that a stream is skewed by a particular amount. This way, when we access a record by absolute offset, we can use the same values that the records themselves contain, instead of having to do fixups. Differential Revision: https://reviews.llvm.org/D55344 llvm-svn: 348499
84 lines
2.7 KiB
C++
84 lines
2.7 KiB
C++
//===- CVSymbolVisitor.cpp --------------------------------------*- C++ -*-===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "llvm/DebugInfo/CodeView/CVSymbolVisitor.h"
|
|
|
|
#include "llvm/DebugInfo/CodeView/CodeViewError.h"
|
|
#include "llvm/DebugInfo/CodeView/SymbolVisitorCallbacks.h"
|
|
|
|
using namespace llvm;
|
|
using namespace llvm::codeview;
|
|
|
|
CVSymbolVisitor::CVSymbolVisitor(SymbolVisitorCallbacks &Callbacks)
|
|
: Callbacks(Callbacks) {}
|
|
|
|
template <typename T>
|
|
static Error visitKnownRecord(CVSymbol &Record,
|
|
SymbolVisitorCallbacks &Callbacks) {
|
|
SymbolRecordKind RK = static_cast<SymbolRecordKind>(Record.Type);
|
|
T KnownRecord(RK);
|
|
if (auto EC = Callbacks.visitKnownRecord(Record, KnownRecord))
|
|
return EC;
|
|
return Error::success();
|
|
}
|
|
|
|
static Error finishVisitation(CVSymbol &Record,
|
|
SymbolVisitorCallbacks &Callbacks) {
|
|
switch (Record.Type) {
|
|
default:
|
|
if (auto EC = Callbacks.visitUnknownSymbol(Record))
|
|
return EC;
|
|
break;
|
|
#define SYMBOL_RECORD(EnumName, EnumVal, Name) \
|
|
case EnumName: { \
|
|
if (auto EC = visitKnownRecord<Name>(Record, Callbacks)) \
|
|
return EC; \
|
|
break; \
|
|
}
|
|
#define SYMBOL_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName) \
|
|
SYMBOL_RECORD(EnumVal, EnumVal, AliasName)
|
|
#include "llvm/DebugInfo/CodeView/CodeViewSymbols.def"
|
|
}
|
|
|
|
if (auto EC = Callbacks.visitSymbolEnd(Record))
|
|
return EC;
|
|
|
|
return Error::success();
|
|
}
|
|
|
|
Error CVSymbolVisitor::visitSymbolRecord(CVSymbol &Record) {
|
|
if (auto EC = Callbacks.visitSymbolBegin(Record))
|
|
return EC;
|
|
return finishVisitation(Record, Callbacks);
|
|
}
|
|
|
|
Error CVSymbolVisitor::visitSymbolRecord(CVSymbol &Record, uint32_t Offset) {
|
|
if (auto EC = Callbacks.visitSymbolBegin(Record, Offset))
|
|
return EC;
|
|
return finishVisitation(Record, Callbacks);
|
|
}
|
|
|
|
Error CVSymbolVisitor::visitSymbolStream(const CVSymbolArray &Symbols) {
|
|
for (auto I : Symbols) {
|
|
if (auto EC = visitSymbolRecord(I))
|
|
return EC;
|
|
}
|
|
return Error::success();
|
|
}
|
|
|
|
Error CVSymbolVisitor::visitSymbolStream(const CVSymbolArray &Symbols,
|
|
uint32_t InitialOffset) {
|
|
for (auto I : Symbols) {
|
|
if (auto EC = visitSymbolRecord(I, InitialOffset + Symbols.skew()))
|
|
return EC;
|
|
InitialOffset += I.length();
|
|
}
|
|
return Error::success();
|
|
}
|