r348397 - Honor -fdebug-prefix-map when creating function names for the debug info.

Adrian Prantl via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 5 10:37:44 PST 2018


Author: adrian
Date: Wed Dec  5 10:37:44 2018
New Revision: 348397

URL: http://llvm.org/viewvc/llvm-project?rev=348397&view=rev
Log:
Honor -fdebug-prefix-map when creating function names for the debug info.

This adds a callback to PrintingPolicy to allow CGDebugInfo to remap
file paths according to -fdebug-prefix-map. Otherwise the debug info
(particularly function names for C++ lambdas) may contain paths that
should have been remapped in the debug info.

<rdar://problem/46128056>

Differential Revision: https://reviews.llvm.org/D55137

Added:
    cfe/trunk/test/CodeGenCXX/debug-prefix-map-lambda.cpp
Modified:
    cfe/trunk/include/clang/AST/PrettyPrinter.h
    cfe/trunk/lib/AST/TypePrinter.cpp
    cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
    cfe/trunk/lib/CodeGen/CGDebugInfo.h

Modified: cfe/trunk/include/clang/AST/PrettyPrinter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/PrettyPrinter.h?rev=348397&r1=348396&r2=348397&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/PrettyPrinter.h (original)
+++ cfe/trunk/include/clang/AST/PrettyPrinter.h Wed Dec  5 10:37:44 2018
@@ -50,7 +50,8 @@ struct PrintingPolicy {
         PolishForDeclaration(false), Half(LO.Half),
         MSWChar(LO.MicrosoftExt && !LO.WChar), IncludeNewlines(true),
         MSVCFormatting(false), ConstantsAsWritten(false),
-        SuppressImplicitBase(false), FullyQualifiedName(false) {}
+        SuppressImplicitBase(false), FullyQualifiedName(false),
+        RemapFilePaths(false) {}
 
   /// Adjust this printing policy for cases where it's known that we're
   /// printing C++ code (for instance, if AST dumping reaches a C++-only
@@ -223,6 +224,12 @@ struct PrintingPolicy {
   /// When true, print the fully qualified name of function declarations.
   /// This is the opposite of SuppressScope and thus overrules it.
   unsigned FullyQualifiedName : 1;
+
+  /// Whether to apply -fdebug-prefix-map to any file paths.
+  unsigned RemapFilePaths : 1;
+
+  /// When RemapFilePaths is true, this function performs the action.
+  std::function<std::string(StringRef)> remapPath;
 };
 
 } // end namespace clang

Modified: cfe/trunk/lib/AST/TypePrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TypePrinter.cpp?rev=348397&r1=348396&r2=348397&view=diff
==============================================================================
--- cfe/trunk/lib/AST/TypePrinter.cpp (original)
+++ cfe/trunk/lib/AST/TypePrinter.cpp Wed Dec  5 10:37:44 2018
@@ -1157,9 +1157,13 @@ void TypePrinter::printTag(TagDecl *D, r
       PresumedLoc PLoc = D->getASTContext().getSourceManager().getPresumedLoc(
           D->getLocation());
       if (PLoc.isValid()) {
-        OS << " at " << PLoc.getFilename()
-           << ':' << PLoc.getLine()
-           << ':' << PLoc.getColumn();
+        OS << " at ";
+        StringRef File = PLoc.getFilename();
+        if (Policy.RemapFilePaths)
+          OS << Policy.remapPath(File);
+        else
+          OS << File;
+        OS << ':' << PLoc.getLine() << ':' << PLoc.getColumn();
       }
     }
 

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=348397&r1=348396&r2=348397&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Wed Dec  5 10:37:44 2018
@@ -235,6 +235,9 @@ PrintingPolicy CGDebugInfo::getPrintingP
   if (CGM.getCodeGenOpts().EmitCodeView)
     PP.MSVCFormatting = true;
 
+  // Apply -fdebug-prefix-map.
+  PP.RemapFilePaths = true;
+  PP.remapPath = [this](StringRef Path) { return remapDIPath(Path); };
   return PP;
 }
 

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=348397&r1=348396&r2=348397&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.h (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.h Wed Dec  5 10:37:44 2018
@@ -341,6 +341,9 @@ public:
 
   void finalize();
 
+  /// Remap a given path with the current debug prefix map
+  std::string remapDIPath(StringRef) const;
+
   /// Register VLA size expression debug node with the qualified type.
   void registerVLASizeExpression(QualType Ty, llvm::Metadata *SizeExpr) {
     SizeExprCache[Ty] = SizeExpr;
@@ -528,9 +531,6 @@ private:
   /// Create new compile unit.
   void CreateCompileUnit();
 
-  /// Remap a given path with the current debug prefix map
-  std::string remapDIPath(StringRef) const;
-
   /// Compute the file checksum debug info for input file ID.
   Optional<llvm::DIFile::ChecksumKind>
   computeChecksum(FileID FID, SmallString<32> &Checksum) const;

Added: cfe/trunk/test/CodeGenCXX/debug-prefix-map-lambda.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-prefix-map-lambda.cpp?rev=348397&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/debug-prefix-map-lambda.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/debug-prefix-map-lambda.cpp Wed Dec  5 10:37:44 2018
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -debug-info-kind=limited -triple %itanium_abi_triple \
+// RUN:   -fdebug-prefix-map=%S=/SOURCE_ROOT %s -emit-llvm -o - | FileCheck %s
+
+template <typename T> void b(T) {}
+void c() {
+  // CHECK: !DISubprogram(name: "b<(lambda at
+  // CHECK-SAME:          /SOURCE_ROOT/debug-prefix-map-lambda.cpp
+  // CHECK-SAME:          [[@LINE+1]]:{{[0-9]+}})>"
+  b([]{});
+}




More information about the cfe-commits mailing list