Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit c2427c2

Browse files
committed
Revert Changing CodeView debug info type record representation in assembly files to make it more human-readable & editable
This reverts r364982 (git commit 2082bf28ebea76cc187b508f801122866420d9ff) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@364987 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 3dc9416 commit c2427c2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+53
-674
lines changed

include/llvm/DebugInfo/CodeView/CVTypeVisitor.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
#include "llvm/DebugInfo/CodeView/CVRecord.h"
1313
#include "llvm/DebugInfo/CodeView/TypeRecord.h"
14-
#include "llvm/DebugInfo/CodeView/TypeVisitorCallbackPipeline.h"
1514
#include "llvm/Support/Error.h"
1615

1716
namespace llvm {
@@ -31,9 +30,6 @@ enum VisitorDataSource {
3130
Error visitTypeRecord(CVType &Record, TypeIndex Index,
3231
TypeVisitorCallbacks &Callbacks,
3332
VisitorDataSource Source = VDS_BytesPresent);
34-
Error visitTypeRecord(CVType &Record, TypeIndex Index,
35-
TypeVisitorCallbackPipeline &Callbacks,
36-
VisitorDataSource Source = VDS_BytesPresent);
3733
Error visitTypeRecord(CVType &Record, TypeVisitorCallbacks &Callbacks,
3834
VisitorDataSource Source = VDS_BytesPresent);
3935

include/llvm/DebugInfo/CodeView/CodeViewRecordIO.h

Lines changed: 7 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -24,64 +24,28 @@
2424
#include <type_traits>
2525

2626
namespace llvm {
27-
2827
namespace codeview {
2928

30-
class CodeViewRecordStreamer {
31-
public:
32-
virtual void EmitBytes(StringRef Data) = 0;
33-
virtual void EmitIntValue(uint64_t Value, unsigned Size) = 0;
34-
virtual void EmitBinaryData(StringRef Data) = 0;
35-
virtual ~CodeViewRecordStreamer() = default;
36-
};
37-
3829
class CodeViewRecordIO {
3930
uint32_t getCurrentOffset() const {
40-
if (isWriting())
41-
return Writer->getOffset();
42-
else if (isReading())
43-
return Reader->getOffset();
44-
else
45-
return 0;
31+
return (isWriting()) ? Writer->getOffset() : Reader->getOffset();
4632
}
4733

4834
public:
49-
// deserializes records to structures
5035
explicit CodeViewRecordIO(BinaryStreamReader &Reader) : Reader(&Reader) {}
51-
52-
// serializes records to buffer
5336
explicit CodeViewRecordIO(BinaryStreamWriter &Writer) : Writer(&Writer) {}
5437

55-
// writes records to assembly file using MC library interface
56-
explicit CodeViewRecordIO(CodeViewRecordStreamer &Streamer)
57-
: Streamer(&Streamer) {}
58-
5938
Error beginRecord(Optional<uint32_t> MaxLength);
6039
Error endRecord();
6140

6241
Error mapInteger(TypeIndex &TypeInd);
6342

64-
bool isStreaming() const {
65-
return (Streamer != nullptr) && (Reader == nullptr) && (Writer == nullptr);
66-
}
67-
bool isReading() const {
68-
return (Reader != nullptr) && (Streamer == nullptr) && (Writer == nullptr);
69-
}
70-
bool isWriting() const {
71-
return (Writer != nullptr) && (Streamer == nullptr) && (Reader == nullptr);
72-
}
43+
bool isReading() const { return Reader != nullptr; }
44+
bool isWriting() const { return !isReading(); }
7345

7446
uint32_t maxFieldLength() const;
7547

7648
template <typename T> Error mapObject(T &Value) {
77-
if (isStreaming()) {
78-
StringRef BytesSR =
79-
StringRef((reinterpret_cast<const char *>(&Value)), sizeof(Value));
80-
Streamer->EmitBytes(BytesSR);
81-
incrStreamedLen(sizeof(T));
82-
return Error::success();
83-
}
84-
8549
if (isWriting())
8650
return Writer->writeObject(Value);
8751

@@ -93,34 +57,25 @@ class CodeViewRecordIO {
9357
}
9458

9559
template <typename T> Error mapInteger(T &Value) {
96-
if (isStreaming()) {
97-
Streamer->EmitIntValue((int)Value, sizeof(T));
98-
incrStreamedLen(sizeof(T));
99-
return Error::success();
100-
}
101-
10260
if (isWriting())
10361
return Writer->writeInteger(Value);
10462

10563
return Reader->readInteger(Value);
10664
}
10765

10866
template <typename T> Error mapEnum(T &Value) {
109-
if (!isStreaming() && sizeof(Value) > maxFieldLength())
67+
if (sizeof(Value) > maxFieldLength())
11068
return make_error<CodeViewError>(cv_error_code::insufficient_buffer);
11169

11270
using U = typename std::underlying_type<T>::type;
11371
U X;
114-
115-
if (isWriting() || isStreaming())
72+
if (isWriting())
11673
X = static_cast<U>(Value);
11774

11875
if (auto EC = mapInteger(X))
11976
return EC;
120-
12177
if (isReading())
12278
Value = static_cast<T>(X);
123-
12479
return Error::success();
12580
}
12681

@@ -135,16 +90,7 @@ class CodeViewRecordIO {
13590
template <typename SizeType, typename T, typename ElementMapper>
13691
Error mapVectorN(T &Items, const ElementMapper &Mapper) {
13792
SizeType Size;
138-
if (isStreaming()) {
139-
Size = static_cast<SizeType>(Items.size());
140-
Streamer->EmitIntValue(Size, sizeof(Size));
141-
incrStreamedLen(sizeof(Size)); // add 1 for the delimiter
142-
143-
for (auto &X : Items) {
144-
if (auto EC = Mapper(*this, X))
145-
return EC;
146-
}
147-
} else if (isWriting()) {
93+
if (isWriting()) {
14894
Size = static_cast<SizeType>(Items.size());
14995
if (auto EC = Writer->writeInteger(Size))
15096
return EC;
@@ -169,7 +115,7 @@ class CodeViewRecordIO {
169115

170116
template <typename T, typename ElementMapper>
171117
Error mapVectorTail(T &Items, const ElementMapper &Mapper) {
172-
if (isStreaming() || isWriting()) {
118+
if (isWriting()) {
173119
for (auto &Item : Items) {
174120
if (auto EC = Mapper(*this, Item))
175121
return EC;
@@ -192,28 +138,10 @@ class CodeViewRecordIO {
192138
Error padToAlignment(uint32_t Align);
193139
Error skipPadding();
194140

195-
uint64_t getStreamedLen() {
196-
if (isStreaming())
197-
return StreamedLen;
198-
return 0;
199-
}
200-
201141
private:
202-
void emitEncodedSignedInteger(const int64_t &Value);
203-
void emitEncodedUnsignedInteger(const uint64_t &Value);
204142
Error writeEncodedSignedInteger(const int64_t &Value);
205143
Error writeEncodedUnsignedInteger(const uint64_t &Value);
206144

207-
void incrStreamedLen(const uint64_t &Len) {
208-
if (isStreaming())
209-
StreamedLen += Len;
210-
}
211-
212-
void resetStreamedLen() {
213-
if (isStreaming())
214-
StreamedLen = 4; // The record prefix is 4 bytes long
215-
}
216-
217145
struct RecordLimit {
218146
uint32_t BeginOffset;
219147
Optional<uint32_t> MaxLength;
@@ -234,8 +162,6 @@ class CodeViewRecordIO {
234162

235163
BinaryStreamReader *Reader = nullptr;
236164
BinaryStreamWriter *Writer = nullptr;
237-
CodeViewRecordStreamer *Streamer = nullptr;
238-
uint64_t StreamedLen = 0;
239165
};
240166

241167
} // end namespace codeview

include/llvm/DebugInfo/CodeView/TypeRecordMapping.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@ class TypeRecordMapping : public TypeVisitorCallbacks {
2323
public:
2424
explicit TypeRecordMapping(BinaryStreamReader &Reader) : IO(Reader) {}
2525
explicit TypeRecordMapping(BinaryStreamWriter &Writer) : IO(Writer) {}
26-
explicit TypeRecordMapping(CodeViewRecordStreamer &Streamer) : IO(Streamer) {}
2726

2827
using TypeVisitorCallbacks::visitTypeBegin;
2928
Error visitTypeBegin(CVType &Record) override;
30-
Error visitTypeBegin(CVType &Record, TypeIndex Index) override;
3129
Error visitTypeEnd(CVType &Record) override;
3230

3331
Error visitMemberBegin(CVMemberRecord &Record) override;

include/llvm/DebugInfo/CodeView/TypeVisitorCallbackPipeline.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,6 @@ class TypeVisitorCallbackPipeline : public TypeVisitorCallbacks {
8282
Pipeline.push_back(&Callbacks);
8383
}
8484

85-
void addCallbackToPipelineFront(TypeVisitorCallbacks &Callbacks) {
86-
auto CallBackItr = Pipeline.begin();
87-
Pipeline.insert(CallBackItr, &Callbacks);
88-
}
89-
9085
#define TYPE_RECORD(EnumName, EnumVal, Name) \
9186
Error visitKnownRecord(CVType &CVR, Name##Record &Record) override { \
9287
return visitKnownRecordImpl(CVR, Record); \

lib/CodeGen/AsmPrinter/CodeViewDebug.cpp

Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
#include "llvm/DebugInfo/CodeView/TypeIndex.h"
5252
#include "llvm/DebugInfo/CodeView/TypeRecord.h"
5353
#include "llvm/DebugInfo/CodeView/TypeTableCollection.h"
54-
#include "llvm/DebugInfo/CodeView/TypeVisitorCallbackPipeline.h"
5554
#include "llvm/IR/Constants.h"
5655
#include "llvm/IR/DataLayout.h"
5756
#include "llvm/IR/DebugInfoMetadata.h"
@@ -95,24 +94,6 @@
9594
using namespace llvm;
9695
using namespace llvm::codeview;
9796

98-
namespace {
99-
class CVMCAdapter : public CodeViewRecordStreamer {
100-
public:
101-
CVMCAdapter(MCStreamer &OS) : OS(&OS) {}
102-
103-
void EmitBytes(StringRef Data) { OS->EmitBytes(Data); }
104-
105-
void EmitIntValue(uint64_t Value, unsigned Size) {
106-
OS->EmitIntValue(Value, Size);
107-
}
108-
109-
void EmitBinaryData(StringRef Data) { OS->EmitBinaryData(Data); }
110-
111-
private:
112-
MCStreamer *OS = nullptr;
113-
};
114-
} // namespace
115-
11697
static CPUType mapArchToCVCPUType(Triple::ArchType Type) {
11798
switch (Type) {
11899
case Triple::ArchType::x86:
@@ -636,40 +617,26 @@ void CodeViewDebug::emitTypeInformation() {
636617
// This will fail if the record data is invalid.
637618
CVType Record = Table.getType(*B);
638619

639-
TypeVisitorCallbackPipeline Pipeline;
640-
CVMCAdapter CVMCOS(OS);
641-
TypeRecordMapping typeMapping(CVMCOS);
642-
SmallString<512> CommentBlock;
643-
raw_svector_ostream CommentOS(CommentBlock);
644-
645620
if (OS.isVerboseAsm()) {
646621
// Emit a block comment describing the type record for readability.
622+
SmallString<512> CommentBlock;
623+
raw_svector_ostream CommentOS(CommentBlock);
647624
ScopedPrinter SP(CommentOS);
648625
SP.setPrefix(CommentPrefix);
649626
TypeDumpVisitor TDV(Table, &SP, false);
650-
Pipeline.addCallbackToPipeline(TDV);
651-
}
652-
Pipeline.addCallbackToPipeline(typeMapping);
653-
654-
auto RecordLen = Record.length();
655-
auto RecordKind = Record.kind();
656-
OS.EmitIntValue(RecordLen - 2, 2);
657-
OS.EmitIntValue(RecordKind, sizeof(RecordKind));
658-
659-
Error E = codeview::visitTypeRecord(Record, *B, Pipeline);
660627

661-
if (E) {
662-
logAllUnhandledErrors(std::move(E), errs(), "error: ");
663-
llvm_unreachable("produced malformed type record");
664-
}
665-
666-
if (OS.isVerboseAsm()) {
628+
Error E = codeview::visitTypeRecord(Record, *B, TDV);
629+
if (E) {
630+
logAllUnhandledErrors(std::move(E), errs(), "error: ");
631+
llvm_unreachable("produced malformed type record");
632+
}
667633
// emitRawComment will insert its own tab and comment string before
668634
// the first line, so strip off our first one. It also prints its own
669635
// newline.
670636
OS.emitRawComment(
671637
CommentOS.str().drop_front(CommentPrefix.size() - 1).rtrim());
672638
}
639+
OS.EmitBinaryData(Record.str_data());
673640
B = Table.getNext(*B);
674641
}
675642
}

lib/DebugInfo/CodeView/CVTypeVisitor.cpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -209,14 +209,6 @@ struct VisitHelper {
209209
}
210210
}
211211

212-
VisitHelper(TypeVisitorCallbackPipeline &Callbacks, VisitorDataSource Source)
213-
: Visitor((Source == VDS_BytesPresent) ? Pipeline : Callbacks) {
214-
if (Source == VDS_BytesPresent) {
215-
Pipeline = Callbacks;
216-
Pipeline.addCallbackToPipelineFront(Deserializer);
217-
}
218-
}
219-
220212
TypeDeserializer Deserializer;
221213
TypeVisitorCallbackPipeline Pipeline;
222214
CVTypeVisitor Visitor;
@@ -230,13 +222,6 @@ Error llvm::codeview::visitTypeRecord(CVType &Record, TypeIndex Index,
230222
return V.Visitor.visitTypeRecord(Record, Index);
231223
}
232224

233-
Error llvm::codeview::visitTypeRecord(CVType &Record, TypeIndex Index,
234-
TypeVisitorCallbackPipeline &Callbacks,
235-
VisitorDataSource Source) {
236-
VisitHelper V(Callbacks, Source);
237-
return V.Visitor.visitTypeRecord(Record, Index);
238-
}
239-
240225
Error llvm::codeview::visitTypeRecord(CVType &Record,
241226
TypeVisitorCallbacks &Callbacks,
242227
VisitorDataSource Source) {

0 commit comments

Comments
 (0)