Path: blob/main/contrib/llvm-project/llvm/lib/DebugInfo/PDB/Native/PublicsStream.cpp
35293 views
//===- PublicsStream.cpp - PDB Public Symbol Stream -----------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// The data structures defined in this file are based on the reference9// implementation which is available at10// https://github.com/Microsoft/microsoft-pdb/blob/master/PDB/dbi/gsi.h11//12// When you are reading the reference source code, you'd find the13// information below useful.14//15// - ppdb1->m_fMinimalDbgInfo seems to be always true.16// - SMALLBUCKETS macro is defined.17//18// The reference doesn't compile, so I learned just by reading code.19// It's not guaranteed to be correct.20//21//===----------------------------------------------------------------------===//2223#include "llvm/DebugInfo/PDB/Native/PublicsStream.h"24#include "llvm/DebugInfo/MSF/MappedBlockStream.h"25#include "llvm/DebugInfo/PDB/Native/RawError.h"26#include "llvm/DebugInfo/PDB/Native/RawTypes.h"27#include "llvm/Support/BinaryStreamReader.h"28#include "llvm/Support/Error.h"29#include <cstdint>3031using namespace llvm;32using namespace llvm::msf;33using namespace llvm::support;34using namespace llvm::pdb;3536PublicsStream::PublicsStream(std::unique_ptr<MappedBlockStream> Stream)37: Stream(std::move(Stream)) {}3839PublicsStream::~PublicsStream() = default;4041uint32_t PublicsStream::getSymHash() const { return Header->SymHash; }42uint16_t PublicsStream::getThunkTableSection() const {43return Header->ISectThunkTable;44}45uint32_t PublicsStream::getThunkTableOffset() const {46return Header->OffThunkTable;47}4849// Publics stream contains fixed-size headers and a serialized hash table.50// This implementation is not complete yet. It reads till the end of the51// stream so that we verify the stream is at least not corrupted. However,52// we skip over the hash table which we believe contains information about53// public symbols.54Error PublicsStream::reload() {55BinaryStreamReader Reader(*Stream);5657// Check stream size.58if (Reader.bytesRemaining() <59sizeof(PublicsStreamHeader) + sizeof(GSIHashHeader))60return make_error<RawError>(raw_error_code::corrupt_file,61"Publics Stream does not contain a header.");6263// Read PSGSIHDR struct.64if (Reader.readObject(Header))65return make_error<RawError>(raw_error_code::corrupt_file,66"Publics Stream does not contain a header.");6768// Read the hash table.69if (auto E = PublicsTable.read(Reader))70return E;7172// Something called "address map" follows.73uint32_t NumAddressMapEntries = Header->AddrMap / sizeof(uint32_t);74if (auto EC = Reader.readArray(AddressMap, NumAddressMapEntries))75return joinErrors(std::move(EC),76make_error<RawError>(raw_error_code::corrupt_file,77"Could not read an address map."));7879// Something called "thunk map" follows.80if (auto EC = Reader.readArray(ThunkMap, Header->NumThunks))81return joinErrors(std::move(EC),82make_error<RawError>(raw_error_code::corrupt_file,83"Could not read a thunk map."));8485// Something called "section map" follows.86if (Reader.bytesRemaining() > 0) {87if (auto EC = Reader.readArray(SectionOffsets, Header->NumSections))88return joinErrors(std::move(EC),89make_error<RawError>(raw_error_code::corrupt_file,90"Could not read a section map."));91}9293if (Reader.bytesRemaining() > 0)94return make_error<RawError>(raw_error_code::corrupt_file,95"Corrupted publics stream.");96return Error::success();97}9899100