Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Clang][DebugInfo] Use CGDebugInfo::createFile in CGDebugInfo::CreateCompileUnit (#83174) #83175

Closed
wants to merge 1 commit into from

Conversation

noxwell
Copy link

@noxwell noxwell commented Feb 27, 2024

Use CGDebugInfo::createFile wrapper that handles file remapping and corner cases instead of directly using DBuilder.createFile in CGDebugInfo::CreateCompileUnit.

Fixes #83174

Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:codegen debuginfo labels Feb 27, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Feb 27, 2024

@llvm/pr-subscribers-clang
@llvm/pr-subscribers-debuginfo

@llvm/pr-subscribers-clang-codegen

Author: Aleksei Vetrov (noxwell)

Changes

Use CGDebugInfo::createFile wrapper that handles file remapping and corner cases instead of directly using DBuilder.createFile in CGDebugInfo::CreateCompileUnit.

Fixes #83174


Full diff: https://github.com/llvm/llvm-project/pull/83175.diff

1 Files Affected:

  • (modified) clang/lib/CodeGen/CGDebugInfo.cpp (+2-3)
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index c2c01439f2dc99..2a24cc1a9dc020 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -628,9 +628,8 @@ void CGDebugInfo::CreateCompileUnit() {
   // file was specified with an absolute path.
   if (CSKind)
     CSInfo.emplace(*CSKind, Checksum);
-  llvm::DIFile *CUFile = DBuilder.createFile(
-      remapDIPath(MainFileName), remapDIPath(getCurrentDirname()), CSInfo,
-      getSource(SM, SM.getMainFileID()));
+  llvm::DIFile *CUFile = createFile(
+      MainFileName, CSInfo, getSource(SM, SM.getMainFileID()));
 
   StringRef Sysroot, SDK;
   if (CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::LLDB) {

Copy link

github-actions bot commented Feb 27, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Collaborator

@adrian-prantl adrian-prantl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test for this?

remapDIPath(MainFileName), remapDIPath(getCurrentDirname()), CSInfo,
getSource(SM, SM.getMainFileID()));
llvm::DIFile *CUFile =
createFile(MainFileName, CSInfo, getSource(SM, SM.getMainFileID()));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is MainFileName no longer being remapped here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CGDebugInfo::createFile takes care of remapping, see std::string RemappedFile = remapDIPath(FileName).

…CompileUnit

Use `CGDebugInfo::createFile` wrapper that handles file remapping and
corner cases instead of directly using `DBuilder.createFile` in
`CGDebugInfo::CreateCompileUnit`.

Add test to check corner case with remapping absolute path to relative.

Fixes llvm#83174
@noxwell
Copy link
Author

noxwell commented Feb 28, 2024

Can you add a test for this?

I added a test for remapping of absolute path. It passes with this PR and fails on trunk.

However, I found much bigger problem. This fix fails test debug-info-abspath.c, more specifically the last case, which checks that CU file has absolute path to source file as well as absolute path to current working directory. @adrian-prantl should now better, but I think it is done to satisfy DWARF standard:

A DW_AT_name attribute whose value is a null-terminated string containing the full or relative path name (relative to the value of the DW_AT_comp_dir attribute, see below) of the primary source file from which the compilation unit was derived.
A DW_AT_comp_dir attribute whose value is a null-terminated string containing the current working directory of the compilation command

It looks like there may be a problem in the standard: you can't have DW_TAG_compile_unit that references file by relative path, but not relative to DW_AT_comp_dir. What do you think?

// CHECK: = distinct !DICompileUnit({{.*}}file: ![[#CUFILE:]]
// CHECK: ![[#CUFILE]] = !DIFile(
// CHECK-NOT: directory: "./out"
// CHECK-SAME: filename: "./src{{[^"]+}}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you compare this to other tests with paths in them? In my memory you need to do some fancy regex for the / path separator work under Windows.

@noxwell
Copy link
Author

noxwell commented Mar 11, 2024

Closing this PR, because these changes are incompatible to DWARF standard, see 83175#issuecomment-1969473992

@noxwell noxwell closed this Mar 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:codegen clang Clang issues not falling into any other category debuginfo
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CGDebugInfo appends working directory to absolute path converted to relative with DebugPrefixMap
3 participants