From d3de3145006bb178b9114ba01cf1f97e27dfd537 Mon Sep 17 00:00:00 2001 From: Paul Robinson Date: Tue, 21 May 2019 11:59:03 +0000 Subject: [PATCH] [DebugInfo] Handle '# line "file"' correctly for asm source. This provides the correct file path for the original source, rather than the preprocessed source. Part of the fix for PR41839. Differential Revision: https://reviews.llvm.org/D62074 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@361248 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/MCParser/AsmParser.cpp | 15 ++++++++++++++- test/MC/ELF/debug-hash-file.s | 21 +++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 test/MC/ELF/debug-hash-file.s diff --git a/lib/MC/MCParser/AsmParser.cpp b/lib/MC/MCParser/AsmParser.cpp index 40e3306a57d..f0d78a43190 100644 --- a/lib/MC/MCParser/AsmParser.cpp +++ b/lib/MC/MCParser/AsmParser.cpp @@ -165,6 +165,9 @@ private: }; CppHashInfoTy CppHashInfo; + /// The filename from the first cpp hash file line comment, if any. + StringRef FirstCppHashFilename; + /// List of forward directional labels for diagnosis at the end. SmallVector, 4> DirLabels; @@ -849,6 +852,13 @@ bool AsmParser::enabledGenDwarfForAssembly() { // the assembler source was produced with debug info already) then emit one // describing the assembler source file itself. if (getContext().getGenDwarfFileNumber() == 0) { + // Use the first #line directive for this, if any. It's preprocessed, so + // there is no checksum, and of course no source directive. + if (!FirstCppHashFilename.empty()) + getContext().setMCLineTableRootFile(/*CUID=*/0, + getContext().getCompilationDir(), + FirstCppHashFilename, + /*Cksum=*/None, /*Source=*/None); const MCDwarfFile &RootFile = getContext().getMCDwarfLineTable(/*CUID=*/0).getRootFile(); getContext().setGenDwarfFileNumber(getStreamer().EmitDwarfFileDirective( @@ -2285,11 +2295,14 @@ bool AsmParser::parseCppHashLineFilenameComment(SMLoc L) { // Get rid of the enclosing quotes. Filename = Filename.substr(1, Filename.size() - 2); - // Save the SMLoc, Filename and LineNumber for later use by diagnostics. + // Save the SMLoc, Filename and LineNumber for later use by diagnostics + // and possibly DWARF file info. CppHashInfo.Loc = L; CppHashInfo.Filename = Filename; CppHashInfo.LineNumber = LineNumber; CppHashInfo.Buf = CurBuffer; + if (FirstCppHashFilename.empty()) + FirstCppHashFilename = Filename; return false; } diff --git a/test/MC/ELF/debug-hash-file.s b/test/MC/ELF/debug-hash-file.s new file mode 100644 index 00000000000..a72e5d6aa8d --- /dev/null +++ b/test/MC/ELF/debug-hash-file.s @@ -0,0 +1,21 @@ +// RUN: llvm-mc -triple x86_64-unknown-linux-gnu -filetype obj -g -dwarf-version 4 -o %t %s +// RUN: llvm-dwarfdump -debug-info -debug-line %t | FileCheck %s + +// CHECK: DW_TAG_compile_unit +// CHECK-NOT: DW_TAG_ +// CHECK: DW_AT_name ("/MyTest/Inputs{{(/|\\)+}}other.S") +// CHECK: DW_TAG_label +// CHECK-NOT: DW_TAG_ +// CHECK: DW_AT_decl_file ("/MyTest/Inputs{{(/|\\)+}}other.S") + +// CHECK: include_directories[ 1] = "/MyTest/Inputs" +// CHECK: file_names[ 1]: +// CHECK-NEXT: name: "other.S" +// CHECK-NEXT: dir_index: 1 + +# 1 "/MyTest/Inputs/other.S" + +foo: + nop + nop + nop -- 2.50.1