Skip to content

Commit

Permalink
[codeview] Move dumper into lib/DebugInfo/CodeView
Browse files Browse the repository at this point in the history
So that we can call it from llvm-pdbdump.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@268580 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
rnk committed May 5, 2016
1 parent 2b2a8f1 commit 1232987
Show file tree
Hide file tree
Showing 8 changed files with 949 additions and 813 deletions.
6 changes: 4 additions & 2 deletions include/llvm/DebugInfo/CodeView/CVTypeVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ class CVTypeVisitor {
// Field list records do not describe their own length, so we cannot
// continue parsing past an unknown member type.
visitUnknownMember(Leaf);
HadError = true;
return;
return parseError();
#define MEMBER_RECORD(ClassName, LeafEnum) \
case LeafEnum: { \
const ClassName *Rec; \
Expand All @@ -142,6 +141,9 @@ class CVTypeVisitor {
/// method is only called at most once per field list record.
void visitUnknownMember(TypeLeafKind Leaf) {}

/// Helper for returning from a void function when the stream is corrupted.
void parseError() { HadError = true; }

private:
/// Whether a type stream parsing error was encountered.
bool HadError = false;
Expand Down
65 changes: 65 additions & 0 deletions include/llvm/DebugInfo/CodeView/TypeDumper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//===-- TypeDumper.h - CodeView type info dumper ----------------*- 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_TYPEDUMPER_H
#define LLVM_DEBUGINFO_CODEVIEW_TYPEDUMPER_H

#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/DebugInfo/CodeView/TypeIndex.h"
#include "llvm/DebugInfo/CodeView/TypeRecord.h"

namespace llvm {
class ScopedPrinter;

namespace codeview {

/// Dumper for CodeView type streams found in COFF object files and PDB files.
class CVTypeDumper {
public:
CVTypeDumper(ScopedPrinter &W, bool PrintRecordBytes)
: W(W), PrintRecordBytes(PrintRecordBytes) {}

StringRef getTypeName(TypeIndex TI);
void printTypeIndex(StringRef FieldName, TypeIndex TI);

/// Dumps the type records in Data. Returns false if there was a type stream
/// parse error, and true otherwise.
bool dump(ArrayRef<uint8_t> Data);

/// Gets the type index for the next type record.
unsigned getNextTypeIndex() const {
return 0x1000 + CVUDTNames.size();
}

/// Records the name of a type, and reserves its type index.
void recordType(StringRef Name) { CVUDTNames.push_back(Name); }

/// Saves the name in a StringSet and creates a stable StringRef.
StringRef saveName(StringRef TypeName) {
return TypeNames.insert(TypeName).first->getKey();
}

private:
ScopedPrinter &W;

bool PrintRecordBytes = false;

/// All user defined type records in .debug$T live in here. Type indices
/// greater than 0x1000 are user defined. Subtract 0x1000 from the index to
/// index into this vector.
SmallVector<StringRef, 10> CVUDTNames;

StringSet<> TypeNames;
};

} // end namespace codeview
} // end namespace llvm

#endif // LLVM_DEBUGINFO_CODEVIEW_TYPEDUMPER_H
19 changes: 19 additions & 0 deletions include/llvm/DebugInfo/CodeView/TypeStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include <stdint.h>

namespace llvm {
class APSInt;

namespace codeview {

/// Consumes sizeof(T) bytes from the given byte sequence. Returns an error if
Expand All @@ -43,6 +45,23 @@ inline std::error_code consumeUInt32(StringRef &Data, uint32_t &Res) {
return std::error_code();
}

/// Decodes a numeric "leaf" value. These are integer literals encountered in
/// the type stream. If the value is positive and less than LF_NUMERIC (1 <<
/// 15), it is emitted directly in Data. Otherwise, it has a tag like LF_CHAR
/// that indicates the bitwidth and sign of the numeric data.
bool decodeNumericLeaf(ArrayRef<uint8_t> &Data, APSInt &Num);

inline bool decodeNumericLeaf(StringRef &Data, APSInt &Num) {
ArrayRef<uint8_t> Bytes(reinterpret_cast<const uint8_t *>(Data.data()),
Data.size());
bool Success = decodeNumericLeaf(Bytes, Num);
Data = StringRef(reinterpret_cast<const char *>(Bytes.data()), Bytes.size());
return Success;
}

/// Decode a numeric leaf value that is known to be a uint32_t.
bool decodeUIntLeaf(ArrayRef<uint8_t> &Data, uint64_t &Num);

// A const input iterator interface to the CodeView type stream.
class TypeIterator {
public:
Expand Down
2 changes: 2 additions & 0 deletions lib/DebugInfo/CodeView/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ add_llvm_library(LLVMDebugInfoCodeView
ListRecordBuilder.cpp
MemoryTypeTableBuilder.cpp
MethodListRecordBuilder.cpp
TypeDumper.cpp
TypeRecordBuilder.cpp
TypeTableBuilder.cpp
TypeStream.cpp

ADDITIONAL_HEADER_DIRS
${LLVM_MAIN_INCLUDE_DIR}/llvm/DebugInfo/CodeView
Expand Down
Loading

0 comments on commit 1232987

Please sign in to comment.