Skip to content

Commit

Permalink
[llvm-pdbdump] Abstract some of the YAML/Raw printing code.
Browse files Browse the repository at this point in the history
There is a lot of duplicate code for printing line info between
YAML and the raw output printer.  This introduces a base class
that can be shared between the two, and makes some minor
cleanups in the process.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@301728 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
Zachary Turner committed Apr 29, 2017
1 parent e85d77f commit 40d2ca9
Show file tree
Hide file tree
Showing 22 changed files with 420 additions and 270 deletions.
3 changes: 2 additions & 1 deletion include/llvm/DebugInfo/CodeView/CodeView.h
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,8 @@ enum class TrampolineType : uint16_t { TrampIncremental, BranchIsland };
enum class FileChecksumKind : uint8_t { None, MD5, SHA1, SHA256 };

enum LineFlags : uint16_t {
HaveColumns = 1, // CV_LINES_HAVE_COLUMNS
LF_None = 0,
LF_HaveColumns = 1, // CV_LINES_HAVE_COLUMNS
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class ModuleDebugFileChecksumFragment final : public ModuleDebugFragment {
Iterator begin() const { return Checksums.begin(); }
Iterator end() const { return Checksums.end(); }

const FileChecksumArray &getArray() const { return Checksums; }

private:
FileChecksumArray Checksums;
};
Expand Down
33 changes: 21 additions & 12 deletions include/llvm/DebugInfo/CodeView/ModuleDebugFragmentVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,19 @@
#ifndef LLVM_DEBUGINFO_CODEVIEW_MODULEDEBUGFRAGMENTVISITOR_H
#define LLVM_DEBUGINFO_CODEVIEW_MODULEDEBUGFRAGMENTVISITOR_H

#include "llvm/ADT/ArrayRef.h"
#include "llvm/DebugInfo/CodeView/CodeView.h"
#include "llvm/DebugInfo/CodeView/CodeViewError.h"
#include "llvm/DebugInfo/CodeView/Line.h"
#include "llvm/DebugInfo/CodeView/ModuleDebugFileChecksumFragment.h"
#include "llvm/DebugInfo/CodeView/ModuleDebugFragmentRecord.h"
#include "llvm/DebugInfo/CodeView/ModuleDebugLineFragment.h"
#include "llvm/DebugInfo/CodeView/ModuleDebugUnknownFragment.h"
#include "llvm/Support/BinaryStreamArray.h"
#include "llvm/Support/BinaryStreamReader.h"
#include "llvm/Support/BinaryStreamRef.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/Error.h"
#include <cstdint>

namespace llvm {

namespace codeview {

class ModuleDebugFileChecksumFragment;
class ModuleDebugFragmentRecord;
class ModuleDebugInlineeLineFragment;
class ModuleDebugLineFragment;
class ModuleDebugUnknownFragment;

class ModuleDebugFragmentVisitor {
public:
virtual ~ModuleDebugFragmentVisitor() = default;
Expand All @@ -43,10 +37,25 @@ class ModuleDebugFragmentVisitor {
virtual Error visitFileChecksums(ModuleDebugFileChecksumFragment &Checksums) {
return Error::success();
}

virtual Error finished() { return Error::success(); }
};

Error visitModuleDebugFragment(const ModuleDebugFragmentRecord &R,
ModuleDebugFragmentVisitor &V);

template <typename T>
Error visitModuleDebugFragments(T &&FragmentRange,
ModuleDebugFragmentVisitor &V) {
for (const auto &L : FragmentRange) {
if (auto EC = visitModuleDebugFragment(L, V))
return EC;
}
if (auto EC = V.finished())
return EC;
return Error::success();
}

} // end namespace codeview

} // end namespace llvm
Expand Down
2 changes: 2 additions & 0 deletions include/llvm/DebugInfo/CodeView/ModuleDebugLineFragment.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ class ModuleDebugLineFragment final : public ModuleDebugFragment {

const LineFragmentHeader *header() const { return Header; }

bool hasColumnInfo() const;

private:
const LineFragmentHeader *Header = nullptr;
LineInfoArray LinesAndColumns;
Expand Down
2 changes: 1 addition & 1 deletion include/llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class DbiModuleDescriptor {
uint16_t getTypeServerIndex() const;
uint16_t getModuleStreamIndex() const;
uint32_t getSymbolDebugInfoByteSize() const;
uint32_t getLineInfoByteSize() const;
uint32_t getC11LineInfoByteSize() const;
uint32_t getC13LineInfoByteSize() const;
uint32_t getNumberOfFiles() const;
uint32_t getSourceFileNameIndex() const;
Expand Down
4 changes: 2 additions & 2 deletions include/llvm/DebugInfo/PDB/Native/RawTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ struct ModuleInfoHeader {
/// Size of local symbol debug info in above stream
support::ulittle32_t SymBytes;

/// Size of line number debug info in above stream
support::ulittle32_t LineBytes;
/// Size of C11 line number info in above stream
support::ulittle32_t C11Bytes;

/// Size of C13 line number info in above stream
support::ulittle32_t C13Bytes;
Expand Down
2 changes: 2 additions & 0 deletions lib/DebugInfo/CodeView/ModuleDebugFragmentVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
#include "llvm/DebugInfo/CodeView/ModuleDebugFragmentVisitor.h"

#include "llvm/DebugInfo/CodeView/ModuleDebugFileChecksumFragment.h"
#include "llvm/DebugInfo/CodeView/ModuleDebugFragmentRecord.h"
#include "llvm/DebugInfo/CodeView/ModuleDebugLineFragment.h"
#include "llvm/DebugInfo/CodeView/ModuleDebugUnknownFragment.h"
#include "llvm/Support/BinaryStreamReader.h"
#include "llvm/Support/BinaryStreamRef.h"

Expand Down
9 changes: 6 additions & 3 deletions lib/DebugInfo/CodeView/ModuleDebugLineFragment.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//===- ModuleDebugLineFragment.cpp --------------------------------*- C++
//-*-===//
//===- ModuleDebugLineFragment.cpp -------------------------------*- C++-*-===//
//
// The LLVM Compiler Infrastructure
//
Expand All @@ -24,7 +23,7 @@ Error LineColumnExtractor::extract(BinaryStreamRef Stream, uint32_t &Len,
BinaryStreamReader Reader(Stream);
if (auto EC = Reader.readObject(BlockHeader))
return EC;
bool HasColumn = Header->Flags & uint32_t(LineFlags::HaveColumns);
bool HasColumn = Header->Flags & uint16_t(LF_HaveColumns);
uint32_t LineInfoSize =
BlockHeader->NumLines *
(sizeof(LineNumberEntry) + (HasColumn ? sizeof(ColumnNumberEntry) : 0));
Expand Down Expand Up @@ -61,3 +60,7 @@ Error ModuleDebugLineFragment::initialize(BinaryStreamReader Reader) {

return Error::success();
}

bool ModuleDebugLineFragment::hasColumnInfo() const {
return Header->Flags & LF_HaveColumns;
}
4 changes: 2 additions & 2 deletions lib/DebugInfo/PDB/Native/DbiModuleDescriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ uint32_t DbiModuleDescriptor::getSymbolDebugInfoByteSize() const {
return Layout->SymBytes;
}

uint32_t DbiModuleDescriptor::getLineInfoByteSize() const {
return Layout->LineBytes;
uint32_t DbiModuleDescriptor::getC11LineInfoByteSize() const {
return Layout->C11Bytes;
}

uint32_t DbiModuleDescriptor::getC13LineInfoByteSize() const {
Expand Down
4 changes: 2 additions & 2 deletions lib/DebugInfo/PDB/Native/DbiModuleDescriptorBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ uint32_t DbiModuleDescriptorBuilder::calculateSerializedLength() const {
}

void DbiModuleDescriptorBuilder::finalize() {
Layout.C13Bytes = 0;
Layout.FileNameOffs = 0; // TODO: Fix this
Layout.Flags = 0; // TODO: Fix this
Layout.LineBytes = 0;
Layout.C11Bytes = 0;
Layout.C13Bytes = 0;
(void)Layout.Mod; // Set in constructor
(void)Layout.ModDiStream; // Set in finalizeMsfLayout
Layout.NumFiles = SourceFiles.size();
Expand Down
2 changes: 1 addition & 1 deletion lib/DebugInfo/PDB/Native/ModuleDebugStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Error ModuleDebugStream::reload() {
BinaryStreamReader Reader(*Stream);

uint32_t SymbolSize = Mod.getSymbolDebugInfoByteSize();
uint32_t C11Size = Mod.getLineInfoByteSize();
uint32_t C11Size = Mod.getC11LineInfoByteSize();
uint32_t C13Size = Mod.getC13LineInfoByteSize();

if (C11Size > 0 && C13Size > 0)
Expand Down
2 changes: 1 addition & 1 deletion lib/MC/MCCodeView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ void CodeViewContext::emitLineTableForFunction(MCObjectStreamer &OS,
bool HaveColumns = any_of(Locs, [](const MCCVLineEntry &LineEntry) {
return LineEntry.getColumn() != 0;
});
OS.EmitIntValue(HaveColumns ? int(LineFlags::HaveColumns) : 0, 2);
OS.EmitIntValue(HaveColumns ? int(LF_HaveColumns) : 0, 2);
OS.emitAbsoluteSymbolDiff(FuncEnd, FuncBegin, 4);

for (auto I = Locs.begin(), E = Locs.end(); I != E;) {
Expand Down
50 changes: 29 additions & 21 deletions test/DebugInfo/PDB/pdbdump-headers.test
Original file line number Diff line number Diff line change
Expand Up @@ -485,27 +485,6 @@
; EMPTY-NEXT: }
; EMPTY-NEXT: ]
; EMPTY-NEXT: LineInfo [
; EMPTY-NEXT: Lines {
; EMPTY-NEXT: FileName: d:\src\llvm\test\debuginfo\pdb\inputs\empty.cpp
; EMPTY-NEXT: Line {
; EMPTY-NEXT: Offset: 0
; EMPTY-NEXT: LineNumberStart: 5
; EMPTY-NEXT: EndDelta: 0
; EMPTY-NEXT: IsStatement: Yes
; EMPTY-NEXT: }
; EMPTY-NEXT: Line {
; EMPTY-NEXT: Offset: 3
; EMPTY-NEXT: LineNumberStart: 6
; EMPTY-NEXT: EndDelta: 0
; EMPTY-NEXT: IsStatement: Yes
; EMPTY-NEXT: }
; EMPTY-NEXT: Line {
; EMPTY-NEXT: Offset: 8
; EMPTY-NEXT: LineNumberStart: 7
; EMPTY-NEXT: EndDelta: 0
; EMPTY-NEXT: IsStatement: Yes
; EMPTY-NEXT: }
; EMPTY-NEXT: }
; EMPTY-NEXT: FileChecksums {
; EMPTY-NEXT: Checksum {
; EMPTY-NEXT: FileName: d:\src\llvm\test\debuginfo\pdb\inputs\empty.cpp
Expand All @@ -515,6 +494,35 @@
; EMPTY-NEXT: )
; EMPTY-NEXT: }
; EMPTY-NEXT: }
; EMPTY-NEXT: Lines {
; EMPTY-NEXT: LineFragment {
; EMPTY-NEXT: RelocSegment: 1
; EMPTY-NEXT: RelocOffset: 16
; EMPTY-NEXT: CodeSize: 10
; EMPTY-NEXT: HasColumns: 0
; EMPTY-NEXT: Lines {
; EMPTY-NEXT: FileName: d:\src\llvm\test\debuginfo\pdb\inputs\empty.cpp
; EMPTY-NEXT: Line {
; EMPTY-NEXT: Offset: 0
; EMPTY-NEXT: LineNumberStart: 5
; EMPTY-NEXT: EndDelta: 0
; EMPTY-NEXT: IsStatement: Yes
; EMPTY-NEXT: }
; EMPTY-NEXT: Line {
; EMPTY-NEXT: Offset: 3
; EMPTY-NEXT: LineNumberStart: 6
; EMPTY-NEXT: EndDelta: 0
; EMPTY-NEXT: IsStatement: Yes
; EMPTY-NEXT: }
; EMPTY-NEXT: Line {
; EMPTY-NEXT: Offset: 8
; EMPTY-NEXT: LineNumberStart: 7
; EMPTY-NEXT: EndDelta: 0
; EMPTY-NEXT: IsStatement: Yes
; EMPTY-NEXT: }
; EMPTY-NEXT: }
; EMPTY-NEXT: }
; EMPTY-NEXT: }
; EMPTY-NEXT: ]
; EMPTY-NEXT: }
; EMPTY-NEXT: {
Expand Down
116 changes: 58 additions & 58 deletions test/DebugInfo/PDB/pdbdump-yaml-lineinfo.test
Original file line number Diff line number Diff line change
@@ -1,59 +1,59 @@
; RUN: llvm-pdbdump pdb2yaml -dbi-module-lines %p/Inputs/empty.pdb \
; RUN: | FileCheck -check-prefix=YAML %s
YAML: ---
YAML: MSF:
YAML: SuperBlock:
YAML: BlockSize: 4096
YAML: FreeBlockMap: 2
YAML: NumBlocks: 25
YAML: NumDirectoryBytes: 136
YAML: Unknown1: 0
YAML: BlockMapAddr: 24
YAML: NumDirectoryBlocks: 1
YAML: DirectoryBlocks: [ 23 ]
YAML: NumStreams: 0
YAML: FileSize: 102400
YAML: DbiStream:
YAML: VerHeader: V70
YAML: Age: 1
YAML: BuildNumber: 35840
YAML: PdbDllVersion: 31101
YAML: PdbDllRbld: 0
YAML: Flags: 1
YAML: MachineType: x86
YAML: Modules:
YAML: - Module: 'd:\src\llvm\test\DebugInfo\PDB\Inputs\empty.obj'
YAML: ObjFile: 'd:\src\llvm\test\DebugInfo\PDB\Inputs\empty.obj'
YAML: SourceFiles:
YAML: - 'd:\src\llvm\test\debuginfo\pdb\inputs\empty.cpp'
YAML: LineInfo:
YAML: Lines:
YAML: CodeSize: 10
YAML: Flags: [ ]
YAML: RelocOffset: 16
YAML: RelocSegment: 1
YAML: LineInfo:
YAML: - FileName: 'd:\src\llvm\test\debuginfo\pdb\inputs\empty.cpp'
YAML: Lines:
YAML: - Offset: 0
YAML: LineStart: 5
YAML: IsStatement: true
YAML: EndDelta: 5
YAML: - Offset: 3
YAML: LineStart: 6
YAML: IsStatement: true
YAML: EndDelta: 6
YAML: - Offset: 8
YAML: LineStart: 7
YAML: IsStatement: true
YAML: EndDelta: 7
YAML: Columns:
YAML: Checksums:
YAML: - FileName: 'd:\src\llvm\test\debuginfo\pdb\inputs\empty.cpp'
YAML: Kind: MD5
YAML: Checksum: A0A5BD0D3ECD93FC29D19DE826FBF4BC
YAML: - Module: '* Linker *'
YAML: ObjFile: ''
; RUN: llvm-pdbdump pdb2yaml -dbi-module-lines %p/Inputs/empty.pdb \
; RUN: | FileCheck -check-prefix=YAML %s


YAML: ---
YAML: MSF:
YAML: SuperBlock:
YAML: BlockSize: 4096
YAML: FreeBlockMap: 2
YAML: NumBlocks: 25
YAML: NumDirectoryBytes: 136
YAML: Unknown1: 0
YAML: BlockMapAddr: 24
YAML: NumDirectoryBlocks: 1
YAML: DirectoryBlocks: [ 23 ]
YAML: NumStreams: 0
YAML: FileSize: 102400
YAML: DbiStream:
YAML: VerHeader: V70
YAML: Age: 1
YAML: BuildNumber: 35840
YAML: PdbDllVersion: 31101
YAML: PdbDllRbld: 0
YAML: Flags: 1
YAML: MachineType: x86
YAML: Modules:
YAML: - Module: 'd:\src\llvm\test\DebugInfo\PDB\Inputs\empty.obj'
YAML: ObjFile: 'd:\src\llvm\test\DebugInfo\PDB\Inputs\empty.obj'
YAML: SourceFiles:
YAML: - 'd:\src\llvm\test\debuginfo\pdb\inputs\empty.cpp'
YAML: LineInfo:
YAML: Checksums:
YAML: - FileName: 'd:\src\llvm\test\debuginfo\pdb\inputs\empty.cpp'
YAML: Kind: MD5
YAML: Checksum: A0A5BD0D3ECD93FC29D19DE826FBF4BC
YAML: Lines:
YAML: CodeSize: 10
YAML: Flags: [ ]
YAML: RelocOffset: 16
YAML: RelocSegment: 1
YAML: Blocks:
YAML: - FileName: 'd:\src\llvm\test\debuginfo\pdb\inputs\empty.cpp'
YAML: Lines:
YAML: - Offset: 0
YAML: LineStart: 5
YAML: IsStatement: true
YAML: EndDelta: 0
YAML: - Offset: 3
YAML: LineStart: 6
YAML: IsStatement: true
YAML: EndDelta: 0
YAML: - Offset: 8
YAML: LineStart: 7
YAML: IsStatement: true
YAML: EndDelta: 0
YAML: Columns:
YAML: - Module: '* Linker *'
YAML: ObjFile: ''
YAML: ...
Loading

0 comments on commit 40d2ca9

Please sign in to comment.