Skip to content

Commit

Permalink
[pdb] Parse and dump section map and section contribs
Browse files Browse the repository at this point in the history
Differential Revision: http://reviews.llvm.org/D20876
Reviewed By: rnk, ruiu

llvm-svn: 271488
  • Loading branch information
Zachary Turner committed Jun 2, 2016
1 parent 7cf29e3 commit 93839cb
Show file tree
Hide file tree
Showing 17 changed files with 1,196 additions and 322 deletions.
40 changes: 40 additions & 0 deletions llvm/include/llvm/DebugInfo/CodeView/EnumTables.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//===- EnumTables.h Enum to string conversion tables ------------*- 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_ENUMTABLES_H
#define LLVM_DEBUGINFO_CODEVIEW_ENUMTABLES_H

#include "llvm/ADT/ArrayRef.h"
#include "llvm/DebugInfo/CodeView/CodeView.h"
#include "llvm/Support/COFF.h"
#include "llvm/Support/ScopedPrinter.h"

#include <stdint.h>

namespace llvm {
namespace codeview {
ArrayRef<EnumEntry<SymbolKind>> getSymbolTypeNames();
ArrayRef<EnumEntry<uint16_t>> getRegisterNames();
ArrayRef<EnumEntry<uint8_t>> getProcSymFlagNames();
ArrayRef<EnumEntry<uint16_t>> getLocalFlagNames();
ArrayRef<EnumEntry<uint32_t>> getFrameCookieKindNames();
ArrayRef<EnumEntry<SourceLanguage>> getSourceLanguageNames();
ArrayRef<EnumEntry<uint32_t>> getCompileSym2FlagNames();
ArrayRef<EnumEntry<uint32_t>> getCompileSym3FlagNames();
ArrayRef<EnumEntry<unsigned>> getCPUTypeNames();
ArrayRef<EnumEntry<uint32_t>> getFrameProcSymFlagNames();
ArrayRef<EnumEntry<uint16_t>> getExportSymFlagNames();
ArrayRef<EnumEntry<uint8_t>> getThunkOrdinalNames();
ArrayRef<EnumEntry<uint16_t>> getTrampolineNames();
ArrayRef<EnumEntry<COFF::SectionCharacteristics>>
getImageSectionCharacteristicNames();
} // namespace codeview
} // namespace llvm

#endif // LLVM_DEBUGINFO_CODEVIEW_ENUMTABLES_H
8 changes: 8 additions & 0 deletions llvm/include/llvm/DebugInfo/CodeView/StreamReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ class StreamReader {
Error readStreamRef(StreamRef &Ref);
Error readStreamRef(StreamRef &Ref, uint32_t Length);

template <typename T> Error readEnum(T &Dest) {
typename std::underlying_type<T>::type N;
if (auto EC = readInteger(N))
return EC;
Dest = static_cast<T>(N);
return Error::success();
}

template <typename T> Error readObject(const T *&Dest) {
ArrayRef<uint8_t> Buffer;
if (auto EC = readBytes(Buffer, sizeof(T)))
Expand Down
14 changes: 13 additions & 1 deletion llvm/include/llvm/DebugInfo/PDB/Raw/DbiStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
#include "llvm/DebugInfo/PDB/Raw/ModInfo.h"
#include "llvm/DebugInfo/PDB/Raw/NameHashTable.h"
#include "llvm/DebugInfo/PDB/Raw/RawConstants.h"
#include "llvm/DebugInfo/PDB/Raw/RawTypes.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/Error.h"

namespace llvm {
namespace pdb {
class PDBFile;
class ISectionContribVisitor;

class DbiStream {
struct HeaderInfo;
Expand Down Expand Up @@ -50,11 +52,16 @@ class DbiStream {

PDB_Machine getMachineType() const;

uint32_t getDebugStreamIndex(DbgHeaderType Type) const;

ArrayRef<ModuleInfoEx> modules() const;

uint32_t getDebugStreamIndex(DbgHeaderType Type) const;
codeview::FixedStreamArray<SecMapEntry> getSectionMap() const;
void visitSectionContributions(ISectionContribVisitor &Visitor) const;

private:
Error initializeSectionContributionData();
Error initializeSectionMapData();
Error initializeFileInfo();

PDBFile &Pdb;
Expand All @@ -72,6 +79,11 @@ class DbiStream {

codeview::FixedStreamArray<support::ulittle16_t> DbgStreams;

PdbRaw_DbiSecContribVer SectionContribVersion;
codeview::FixedStreamArray<SectionContrib> SectionContribs;
codeview::FixedStreamArray<SectionContrib2> SectionContribs2;
codeview::FixedStreamArray<SecMapEntry> SectionMap;

const HeaderInfo *Header;
};
}
Expand Down
22 changes: 22 additions & 0 deletions llvm/include/llvm/DebugInfo/PDB/Raw/EnumTables.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===- EnumTables.h - Enum to string conversion tables ----------*- 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_PDB_RAW_ENUMTABLES_H
#define LLVM_DEBUGINFO_PDB_RAW_ENUMTABLES_H

#include "llvm/ADT/ArrayRef.h"
#include "llvm/Support/ScopedPrinter.h"

namespace llvm {
namespace pdb {
ArrayRef<EnumEntry<uint16_t>> getOMFSegMapDescFlagNames();
}
}

#endif // LLVM_DEBUGINFO_PDB_RAW_ENUMTABLES_H
28 changes: 28 additions & 0 deletions llvm/include/llvm/DebugInfo/PDB/Raw/ISectionContribVisitor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//===- ISectionContribVisitor.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_PDB_RAW_ISECTIONCONTRIBVISITOR_H
#define LLVM_DEBUGINFO_PDB_RAW_ISECTIONCONTRIBVISITOR_H

namespace llvm {
namespace pdb {
struct SectionContrib;
struct SectionContrib2;

class ISectionContribVisitor {
public:
virtual ~ISectionContribVisitor() {}

virtual void visit(const SectionContrib &C) = 0;
virtual void visit(const SectionContrib2 &C) = 0;
};
} // namespace pdb
} // namespace llvm

#endif // LLVM_DEBUGINFO_PDB_RAW_ISECTIONCONTRIBVISITOR_H
1 change: 1 addition & 0 deletions llvm/include/llvm/DebugInfo/PDB/Raw/PublicsStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "llvm/DebugInfo/PDB/PDBTypes.h"
#include "llvm/DebugInfo/PDB/Raw/MappedBlockStream.h"
#include "llvm/DebugInfo/PDB/Raw/RawConstants.h"
#include "llvm/DebugInfo/PDB/Raw/RawTypes.h"

#include "llvm/Support/Error.h"

Expand Down
28 changes: 15 additions & 13 deletions llvm/include/llvm/DebugInfo/PDB/Raw/RawConstants.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===- PDBRawConstants.h ----------------------------------------*- C++ -*-===//
//===- RawConstants.h -------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
Expand All @@ -10,7 +10,7 @@
#ifndef LLVM_DEBUGINFO_PDB_RAW_PDBRAWCONSTANTS_H
#define LLVM_DEBUGINFO_PDB_RAW_PDBRAWCONSTANTS_H

#include "llvm/Support/Endian.h"
#include "llvm/DebugInfo/CodeView/CodeView.h"

#include <cstdint>

Expand Down Expand Up @@ -46,6 +46,11 @@ enum PdbRaw_TpiVer : uint32_t {
PdbTpiV80 = 20040203,
};

enum PdbRaw_DbiSecContribVer : uint32_t {
DbiSecContribVer60 = 0xeffe0000 + 19970605,
DbiSecContribV2 = 0xeffe0000 + 20140516
};

enum SpecialStream : uint32_t {
// Stream 0 contains the copy of previous version of the MSF directory.
// We are not currently using it, but technically if we find the main
Expand Down Expand Up @@ -73,17 +78,14 @@ enum class DbgHeaderType : uint16_t {
Max
};

// This struct is defined as "SO" in langapi/include/pdb.h.
struct SectionOffset {
support::ulittle32_t Off;
support::ulittle16_t Isect;
char Padding[2];
};

// This is HRFile.
struct PSHashRecord {
support::ulittle32_t Off; // Offset in the symbol record stream
support::ulittle32_t CRef;
enum class OMFSegDescFlags : uint16_t {
Read = 1 << 0, // Segment is readable.
Write = 1 << 1, // Segment is writable.
Execute = 1 << 2, // Segment is executable.
AddressIs32Bit = 1 << 3, // Descriptor describes a 32-bit linear address.
IsSelector = 1 << 8, // Frame represents a selector.
IsAbsoluteAddress = 1 << 9, // Frame represents an absolute address.
IsGroup = 1 << 10 // If set, descriptor represents a group.
};

} // end namespace pdb
Expand Down
78 changes: 78 additions & 0 deletions llvm/include/llvm/DebugInfo/PDB/Raw/RawTypes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
//===- RawTypes.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_PDB_RAW_RAWTYPES_H
#define LLVM_DEBUGINFO_PDB_RAW_RAWTYPES_H

#include "llvm/Support/Endian.h"

namespace llvm {
namespace pdb {
// This struct is defined as "SO" in langapi/include/pdb.h.
struct SectionOffset {
support::ulittle32_t Off;
support::ulittle16_t Isect;
char Padding[2];
};

// This is HRFile.
struct PSHashRecord {
support::ulittle32_t Off; // Offset in the symbol record stream
support::ulittle32_t CRef;
};

// This struct is defined as `SC` in include/dbicommon.h
struct SectionContrib {
support::ulittle16_t ISect;
char Padding[2];
support::little32_t Off;
support::little32_t Size;
support::ulittle32_t Characteristics;
support::ulittle16_t Imod;
char Padding2[2];
support::ulittle32_t DataCrc;
support::ulittle32_t RelocCrc;
};

// This struct is defined as `SC2` in include/dbicommon.h
struct SectionContrib2 {
// To guarantee SectionContrib2 is standard layout, we cannot use inheritance.
SectionContrib Base;
support::ulittle32_t ISectCoff;
};

// This corresponds to the `OMFSegMap` structure.
struct SecMapHeader {
support::ulittle16_t SecCount; // Number of segment descriptors in table
support::ulittle16_t SecCountLog; // Number of logical segment descriptors
};

// This corresponds to the `OMFSegMapDesc` structure. The definition is not
// present in the reference implementation, but the layout is derived from
// code that accesses the fields.
struct SecMapEntry {
support::ulittle16_t Flags; // Descriptor flags. See OMFSegDescFlags
support::ulittle16_t Ovl; // Logical overlay number.
support::ulittle16_t Group; // Group index into descriptor array.
support::ulittle16_t Frame;
support::ulittle16_t SecName; // Byte index of the segment or group name
// in the sstSegName table, or 0xFFFF.
support::ulittle16_t ClassName; // Byte index of the class name in the
// sstSegName table, or 0xFFFF.
support::ulittle32_t Offset; // Byte offset of the logical segment
// within the specified physical segment.
// If group is set in flags, offset is the
// offset of the group.
support::ulittle32_t SecByteLength; // Byte count of the segment or group.
};

} // namespace pdb
} // namespace llvm

#endif
1 change: 1 addition & 0 deletions llvm/lib/DebugInfo/CodeView/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
add_llvm_library(LLVMDebugInfoCodeView
ByteStream.cpp
CodeViewError.cpp
EnumTables.cpp
FieldListRecordBuilder.cpp
Line.cpp
ListRecordBuilder.cpp
Expand Down

0 comments on commit 93839cb

Please sign in to comment.