Files
archived-llvm/include/llvm/DebugInfo/CodeView/StringsAndChecksums.h
Zachary Turner 6ef51e8f14 [llvm-pdbutil] Support dumping CodeView from object files.
We have llvm-readobj for dumping CodeView from object files, and
llvm-pdbutil has always been more focused on PDB.  However,
llvm-pdbutil has a lot of useful options for summarizing debug
information in aggregate and presenting high level statistical
views.  Furthermore, it's arguably better as a testing tool since
we don't have to write tests to conform to a state-machine like
structure where you match multiple lines in succession, each
depending on a previous match.  llvm-pdbutil dumps much more
concisely, so it's possible to use single-line matches in many
cases where as with readobj tests you have to use multi-line
matches with an implicit state machine.

Because of this, I'm adding object file support to llvm-pdbutil.
In fact, this mirrors the cvdump tool from Microsoft, which also
supports both object files and pdb files.  In the future we could
perhaps rename this tool llvm-cvutil.

In the meantime, this allows us to deep dive into object files
the same way we already can with PDB files.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@312358 91177308-0d34-0410-b5e6-96231b3b80d8
2017-09-01 20:06:56 +00:00

108 lines
3.9 KiB
C++

//===- StringsAndChecksums.h ------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_CODEVIEW_STRINGSANDCHECKSUMS_H
#define LLVM_DEBUGINFO_CODEVIEW_STRINGSANDCHECKSUMS_H
#include "llvm/DebugInfo/CodeView/CodeView.h"
#include "llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h"
#include "llvm/DebugInfo/CodeView/DebugStringTableSubsection.h"
#include "llvm/DebugInfo/CodeView/DebugSubsectionRecord.h"
#include <memory>
namespace llvm {
namespace codeview {
class StringsAndChecksumsRef {
public:
// If no subsections are known about initially, we find as much as we can.
StringsAndChecksumsRef();
// If only a string table subsection is given, we find a checksums subsection.
explicit StringsAndChecksumsRef(const DebugStringTableSubsectionRef &Strings);
// If both subsections are given, we don't need to find anything.
StringsAndChecksumsRef(const DebugStringTableSubsectionRef &Strings,
const DebugChecksumsSubsectionRef &Checksums);
void setStrings(const DebugStringTableSubsectionRef &Strings);
void setChecksums(const DebugChecksumsSubsectionRef &CS);
void reset();
void resetStrings();
void resetChecksums();
template <typename T> void initialize(T &&FragmentRange) {
for (const DebugSubsectionRecord &R : FragmentRange) {
if (Strings && Checksums)
return;
if (R.kind() == DebugSubsectionKind::FileChecksums) {
initializeChecksums(R);
continue;
}
if (R.kind() == DebugSubsectionKind::StringTable && !Strings) {
// While in practice we should never encounter a string table even
// though the string table is already initialized, in theory it's
// possible. PDBs are supposed to have one global string table and
// then this subsection should not appear. Whereas object files are
// supposed to have this subsection appear exactly once. However,
// for testing purposes it's nice to be able to test this subsection
// independently of one format or the other, so for some tests we
// manually construct a PDB that contains this subsection in addition
// to a global string table.
initializeStrings(R);
continue;
}
}
}
const DebugStringTableSubsectionRef &strings() const { return *Strings; }
const DebugChecksumsSubsectionRef &checksums() const { return *Checksums; }
bool hasStrings() const { return Strings != nullptr; }
bool hasChecksums() const { return Checksums != nullptr; }
private:
void initializeStrings(const DebugSubsectionRecord &SR);
void initializeChecksums(const DebugSubsectionRecord &FCR);
std::shared_ptr<DebugStringTableSubsectionRef> OwnedStrings;
std::shared_ptr<DebugChecksumsSubsectionRef> OwnedChecksums;
const DebugStringTableSubsectionRef *Strings = nullptr;
const DebugChecksumsSubsectionRef *Checksums = nullptr;
};
class StringsAndChecksums {
public:
using StringsPtr = std::shared_ptr<DebugStringTableSubsection>;
using ChecksumsPtr = std::shared_ptr<DebugChecksumsSubsection>;
// If no subsections are known about initially, we find as much as we can.
StringsAndChecksums() = default;
void setStrings(const StringsPtr &SP) { Strings = SP; }
void setChecksums(const ChecksumsPtr &CP) { Checksums = CP; }
const StringsPtr &strings() const { return Strings; }
const ChecksumsPtr &checksums() const { return Checksums; }
bool hasStrings() const { return Strings != nullptr; }
bool hasChecksums() const { return Checksums != nullptr; }
private:
StringsPtr Strings;
ChecksumsPtr Checksums;
};
} // end namespace codeview
} // end namespace llvm
#endif // LLVM_DEBUGINFO_CODEVIEW_STRINGSANDCHECKSUMS_H