Skip to content

Commit

Permalink
Correctly initialize the DW_AT_comp_dir attribute of Clang module ske…
Browse files Browse the repository at this point in the history
…leton CUs

Before this patch a Clang module skeleton CU would have a
DW_AT_comp_dir pointing to the directory of the module map file, and
this information was not used by anyone. Even worse, LLDB actually
resolves relative DWO paths by appending it to DW_AT_comp_dir. This
patch sets it to the same directory that is used as the main CU's
compilation directory, which would make the LLDB code work.

Differential Revision: https://reviews.llvm.org/D76377
  • Loading branch information
adrian-prantl committed Mar 20, 2020
1 parent 417d695 commit 079c6dd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
12 changes: 8 additions & 4 deletions clang/lib/CodeGen/CGDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2492,12 +2492,16 @@ llvm::DIModule *CGDebugInfo::getOrCreateModuleRef(ASTSourceDescriptor Mod,
? (uint64_t)Mod.getSignature()[1] << 32 | Mod.getSignature()[0]
: ~1ULL;
llvm::DIBuilder DIB(CGM.getModule());
SmallString<0> PCM;
if (!llvm::sys::path::is_absolute(PCM))
PCM = Mod.getPath();
llvm::sys::path::append(PCM, Mod.getASTFile());
StringRef CompDir = getCurrentDirname();
DIB.createCompileUnit(TheCU->getSourceLanguage(),
// TODO: Support "Source" from external AST providers?
DIB.createFile(Mod.getModuleName(), Mod.getPath()),
TheCU->getProducer(), true, StringRef(), 0,
Mod.getASTFile(), llvm::DICompileUnit::FullDebug,
Signature);
DIB.createFile(Mod.getModuleName(), CompDir),
TheCU->getProducer(), true, StringRef(), 0, PCM,
llvm::DICompileUnit::FullDebug, Signature);
DIB.finalize();
}

Expand Down
6 changes: 4 additions & 2 deletions clang/test/Modules/debug-info-moduleimport.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,7 @@
// RUN: -fmodule-format=obj -dwarf-ext-refs \
// RUN: %s -I %S/Inputs -isysroot /tmp/.. -I %t -emit-llvm -o - \
// RUN: | FileCheck %s --check-prefix=SKEL-CHECK
// SKEL-CHECK: distinct !DICompileUnit
// SKEL-CHECK: distinct !DICompileUnit{{.*}}dwoId
// SKEL-CHECK: distinct !DICompileUnit({{.*}}file: ![[CUFILE:[0-9]+]]
// SKEL-CHECK: ![[CUFILE]] = !DIFile({{.*}}directory: "[[COMP_DIR:.*]]"
// SKEL-CHECK: distinct !DICompileUnit({{.*}}file: ![[DWOFILE:[0-9]+]]{{.*}}dwoId
// SKEL-CHECK: ![[DWOFILE]] = !DIFile({{.*}}directory: "[[COMP_DIR]]"
8 changes: 4 additions & 4 deletions clang/test/PCH/debug-info-pch-path.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
// CHECK-REL-NODIR: ![[C]] = !DIFile({{.*}}directory: "[[DIR:.*]]"
// CHECK-REL-NODIR: !DICompileUnit(
// CHECK-REL-NODIR-SAME: file: ![[PCH:[0-9]+]]
// CHECK-REL-NODIR-SAME: splitDebugFilename: "prefix.pch"
// CHECK-REL-NODIR-SAME: splitDebugFilename: "{{.*}}PCH{{.*}}prefix.pch"
// CHECK-REL-NODIR: ![[PCH]] = !DIFile({{.*}}directory: "[[DIR]]

// ---------------------------------------------------------------------
Expand All @@ -47,8 +47,8 @@
// CHECK-REL: ![[C]] = !DIFile({{.*}}directory: "[[DIR:.*]]"
// CHECK-REL: !DICompileUnit(
// CHECK-REL-SAME: file: ![[PCH:[0-9]+]]
// CHECK-REL-SAME: splitDebugFilename: "prefix.pch"
// CHECK-REL: ![[PCH]] = !DIFile({{.*}}directory: "[[DIR]]{{.*}}pchdir"
// CHECK-REL-SAME: splitDebugFilename: "[[DIR]]{{.*}}pchdir{{.*}}prefix.pch"
// CHECK-REL: ![[PCH]] = !DIFile({{.*}}directory: "[[DIR]]"

// ---------------------------------------------------------------------
// Absolute PCH.
Expand All @@ -70,5 +70,5 @@
// CHECK-ABS: ![[C]] = !DIFile({{.*}}directory: "[[DIR:.*]]"
// CHECK-ABS: !DICompileUnit(
// CHECK-ABS-SAME: file: ![[PCH:[0-9]+]]
// CHECK-ABS-SAME: splitDebugFilename: "prefix.pch"
// CHECK-ABS-SAME: splitDebugFilename: "[[DIR]]{{.*}}prefix.pch"
// CHECK-ABS: ![[PCH]] = !DIFile({{.*}}directory: "[[DIR]]

0 comments on commit 079c6dd

Please sign in to comment.