Skip to content

Commit

Permalink
Patch LLVM to make the AssemblyWriter emit debug-info comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
maleadt committed Jun 13, 2017
1 parent 493311b commit 1314758
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
5 changes: 5 additions & 0 deletions deps/llvm.mk
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,11 @@ $(eval $(call LLVM_PATCH,llvm-D33179))
$(eval $(call LLVM_PATCH,llvm-PR29010-i386-xmm)) # Remove for 4.0
endif # LLVM_VER

# patch the AsmWriter to print debug info comments
ifeq ($(LLVM_VER_SHORT),3.9)
$(eval $(call LLVM_PATCH,llvm-3.9-asmwriter-di))
endif

ifeq ($(LLVM_VER),3.7.1)
ifeq ($(BUILD_LLDB),1)
$(eval $(call LLVM_PATCH,lldb-3.7.1))
Expand Down
43 changes: 43 additions & 0 deletions deps/patches/llvm-3.9-asmwriter-di.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
diff --git a/lib/IR/AsmWriter.cpp b/lib/IR/AsmWriter.cpp
index 9b2399d..e7bb1ad 100644
--- a/lib/IR/AsmWriter.cpp
+++ b/lib/IR/AsmWriter.cpp
@@ -2115,6 +2115,8 @@ private:
// printGCRelocateComment - print comment after call to the gc.relocate
// intrinsic indicating base and derived pointer names.
void printGCRelocateComment(const GCRelocateInst &Relocate);
+
+ DILocation *InstrLoc = nullptr;
};
} // namespace

@@ -2710,6 +2712,7 @@ void AssemblyWriter::printFunction(const Function *F) {

Out << " {";
// Output all of the function's basic blocks.
+ InstrLoc = nullptr;
for (const BasicBlock &BB : *F)
printBasicBlock(&BB);

@@ -2792,6 +2795,21 @@ void AssemblyWriter::printBasicBlock(const BasicBlock *BB) {

/// printInstructionLine - Print an instruction and a newline character.
void AssemblyWriter::printInstructionLine(const Instruction &I) {
+ DILocation *NewInstrLoc = I.getDebugLoc();
+ if (NewInstrLoc != nullptr && NewInstrLoc != InstrLoc) {
+ bool NewFile = false;
+ if (!NewInstrLoc->getFilename().empty() &&
+ (InstrLoc == nullptr || NewInstrLoc->getFilename() != InstrLoc->getFilename())) {
+ Out << "; Filename: " << NewInstrLoc->getFilename() << '\n';
+ NewFile = true;
+ }
+
+ if (NewInstrLoc->getLine() != UINT_MAX &&
+ (NewFile || NewInstrLoc->getLine() != InstrLoc->getLine()))
+ Out << "; Source line: " << NewInstrLoc->getLine() << '\n';
+ }
+ InstrLoc = NewInstrLoc;
+
printInstruction(I);
Out << '\n';
}

0 comments on commit 1314758

Please sign in to comment.