[llvm] r361245 - [DebugInfo] Handle -main-file-name correctly for asm source.
Paul Robinson via llvm-commits
llvm-commits at lists.llvm.org
Tue May 21 04:52:27 PDT 2019
Author: probinson
Date: Tue May 21 04:52:27 2019
New Revision: 361245
URL: http://llvm.org/viewvc/llvm-project?rev=361245&view=rev
Log:
[DebugInfo] Handle -main-file-name correctly for asm source.
This option provides only the base filename, not a full relative path.
Part of the fix for PR41839.
Differential Revision: https://reviews.llvm.org/D62071
Added:
llvm/trunk/test/MC/ELF/debug-main-file.s
Removed:
llvm/trunk/test/DebugInfo/X86/main-file-name.s
Modified:
llvm/trunk/lib/MC/MCContext.cpp
Modified: llvm/trunk/lib/MC/MCContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCContext.cpp?rev=361245&r1=361244&r2=361245&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCContext.cpp (original)
+++ llvm/trunk/lib/MC/MCContext.cpp Tue May 21 04:52:27 2019
@@ -582,10 +582,21 @@ void MCContext::setGenDwarfRootFile(Stri
}
// Canonicalize the root filename. It cannot be empty, and should not
// repeat the compilation dir.
- StringRef FileName =
- !getMainFileName().empty() ? StringRef(getMainFileName()) : InputFileName;
- if (FileName.empty() || FileName == "-")
- FileName = "<stdin>";
+ // The MCContext ctor initializes MainFileName to the name associated with
+ // the SrcMgr's main file ID, which might be the same as InputFileName (and
+ // possibly include directory components).
+ // Or, MainFileName might have been overridden by a -main-file-name option,
+ // which is supposed to be just a base filename with no directory component.
+ // So, if the InputFileName and MainFileName are not equal, assume
+ // MainFileName is a substitute basename and replace the last component.
+ SmallString<1024> FileNameBuf = InputFileName;
+ if (FileNameBuf.empty() || FileNameBuf == "-")
+ FileNameBuf = "<stdin>";
+ if (!getMainFileName().empty() && FileNameBuf != getMainFileName()) {
+ llvm::sys::path::remove_filename(FileNameBuf);
+ llvm::sys::path::append(FileNameBuf, getMainFileName());
+ }
+ StringRef FileName = FileNameBuf;
if (FileName.consume_front(getCompilationDir()))
if (llvm::sys::path::is_separator(FileName.front()))
FileName = FileName.drop_front();
Removed: llvm/trunk/test/DebugInfo/X86/main-file-name.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/main-file-name.s?rev=361244&view=auto
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/main-file-name.s (original)
+++ llvm/trunk/test/DebugInfo/X86/main-file-name.s (removed)
@@ -1,17 +0,0 @@
-// RUN: llvm-mc -triple x86_64-unknown-linux-gnu -filetype obj -main-file-name foo.S -g -o %t %s
-// RUN: llvm-dwarfdump -v -debug-info %t | FileCheck %s
-
-// CHECK: DW_TAG_compile_unit [1]
-// CHECK-NOT: DW_TAG_
-// CHECK: DW_AT_name [DW_FORM_string] ("foo.S")
-
-
-# 1 "foo.S"
-# 1 "<built-in>" 1
-# 1 "foo.S" 2
-
-foo:
- nop
- nop
- nop
-
Added: llvm/trunk/test/MC/ELF/debug-main-file.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/debug-main-file.s?rev=361245&view=auto
==============================================================================
--- llvm/trunk/test/MC/ELF/debug-main-file.s (added)
+++ llvm/trunk/test/MC/ELF/debug-main-file.s Tue May 21 04:52:27 2019
@@ -0,0 +1,41 @@
+// RUN: mkdir -p %t/Inputs
+// RUN: cp %s %t/base.s
+// RUN: cp %s %t/Inputs/subdir.s
+// RUN: cd %t
+
+// RUN: llvm-mc -triple=x86_64-linux-unknown -filetype=obj -dwarf-version=4 \
+// RUN: -g base.s -o %t1.o
+// RUN: llvm-dwarfdump -debug-info %t1.o | \
+// RUN: FileCheck %s --check-prefixes=CHECK,BASE
+// RUN: llvm-mc -triple=x86_64-linux-unknown -filetype=obj -dwarf-version=4 \
+// RUN: -g base.s -o %t2.o -main-file-name rename.s
+// RUN: llvm-dwarfdump -debug-info %t2.o | \
+// RUN: FileCheck %s --check-prefixes=CHECK,RENAME
+// RUN: llvm-mc -triple=x86_64-linux-unknown -filetype=obj -dwarf-version=4 \
+// RUN: -g Inputs\subdir.s -o %t3.o
+// RUN: llvm-dwarfdump -debug-info %t3.o | \
+// RUN: FileCheck %s --check-prefixes=CHECK,SUBDIR
+// RUN: llvm-mc -triple=x86_64-linux-unknown -filetype=obj -dwarf-version=4 \
+// RUN: -g Inputs\subdir.s -main-file-name sub-rename.s -o %t4.o
+// RUN: llvm-dwarfdump -debug-info %t4.o | \
+// RUN: FileCheck %s --check-prefixes=CHECK,SUB-RENAME
+
+// CHECK: DW_TAG_compile_unit
+// CHECK-NOT: DW_TAG
+// CHECK: DW_AT_name
+// BASE-SAME: ("base.s")
+// RENAME-SAME: ("rename.s")
+// SUBDIR-SAME: ("Inputs{{(/|\\)+}}subdir.s")
+// SUB-RENAME-SAME: ("Inputs{{(/|\\)+}}sub-rename.s")
+
+// CHECK: DW_TAG_label
+// CHECK-NOT: DW_TAG
+// CHECK: DW_AT_decl_file
+// BASE-SAME: ("{{.*(/|\\)}}base.s")
+// RENAME-SAME: ("{{.*(/|\\)}}rename.s")
+// SUBDIR-SAME: ("{{.*Inputs(/|\\)+}}subdir.s")
+// SUB-RENAME-SAME: ("{{.*Inputs(/|\\)+}}sub-rename.s")
+
+ .text
+start:
+ nop
More information about the llvm-commits
mailing list