Skip to content

[llvm-debuginfo-analyzer] Incorrect directory path (.debug_line) #143849

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions llvm/lib/DebugInfo/LogicalView/Readers/LVDWARFReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,14 +522,16 @@ void LVDWARFReader::createLineAndFileRecords(
for (const DWARFDebugLine::FileNameEntry &Entry :
Lines->Prologue.FileNames) {
std::string Directory;
if (Lines->getDirectoryForEntry(Entry, Directory))
Directory = transformPath(Directory);
Lines->getDirectoryForEntry(Entry, Directory);
if (Directory.empty())
Directory = std::string(CompileUnit->getCompilationDirectory());
std::string File = transformPath(dwarf::toStringRef(Entry.Name));
// Take just the filename component, as it may be contain the full
// path that would be added to the already existing path in Directory.
StringRef File =
llvm::sys::path::filename(dwarf::toStringRef(Entry.Name));
Comment on lines +528 to +531
Copy link
Contributor

Choose a reason for hiding this comment

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

Could it happen that the filename part of a !DIFile does not have the directory part as a prefix? E.g.

!1 = !DIFile(filename: "foo/test.cpp", directory: "bar")

Should this be interpreted as bar/foo/test.cpp instead?

std::string String;
raw_string_ostream(String) << Directory << "/" << File;
CompileUnit->addFilename(String);
CompileUnit->addFilename(transformPath(String));
}

// In DWARF5 the file indexes start at 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
; REQUIRES: x86-registered-target

; When the 'filename' field in DIFile entry contains the full pathname, such as:
;
; !1 = !DIFile(filename: "path/test.cpp", directory: "path")
;
; llvm-debuginfo-analyzer displays incorrect information for the directories
; extracted from the '.debug_line' section, when using '--attribute=directories'
;
; llvm-debuginfo-analyzer --attribute=directories --print=scopes test.o
;
; {CompileUnit} 'test.cpp'
; {Directory} 'path/path' <------- Duplicated 'path'

; The test case was produced by the following steps:
; // test.cpp
; void foo() {
; }

; 1) clang++ --target=x86_64-pc-linux-gnu -Xclang -disable-O0-optnone
; -Xclang -disable-llvm-passes -fno-discard-value-names
; -emit-llvm -S -g -O0 test.cpp -o test.ll
;
; 2) Manually adding directory information to the DIFile 'filename' field:
;
; !1 = !DIFile(filename: "test.cpp", directory: "path")
; -->
; !1 = !DIFile(filename: "path/test.cpp", directory: "path")

; RUN: llc --filetype=obj %p/dwarf-duplicated-directory-path.ll \
; RUN: -o %t.dwarf-duplicated-directory-path.o

; RUN: llvm-debuginfo-analyzer --attribute=directories,files \
; RUN: --print=scopes \
; RUN: %t.dwarf-duplicated-directory-path.o 2>&1 | \
; RUN: FileCheck --strict-whitespace -check-prefix=ONE %s

; ONE: Logical View:
; ONE-NEXT: {File} '{{.*}}dwarf-duplicated-directory-path.ll{{.*}}'
; ONE-EMPTY:
; ONE-NEXT: {CompileUnit} 'test.cpp'
; ONE-NEXT: {Directory} 'path'
; ONE-NEXT: {File} 'test.cpp'
; ONE-NEXT: 1 {Function} extern not_inlined 'foo' -> 'void'

source_filename = "test.cpp"
target triple = "x86_64-pc-linux-gnu"

define dso_local void @_Z3foov() !dbg !10 {
entry:
ret void, !dbg !13
}

!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!2, !3, !4}
!llvm.ident = !{!9}

!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
!1 = !DIFile(filename: "path/test.cpp", directory: "path")
!2 = !{i32 7, !"Dwarf Version", i32 5}
!3 = !{i32 2, !"Debug Info Version", i32 3}
!4 = !{i32 1, !"wchar_size", i32 4}
!9 = !{!"clang"}
!10 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 1, type: !11, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0)
!11 = !DISubroutineType(types: !12)
!12 = !{null}
!13 = !DILocation(line: 2, column: 1, scope: !10)
Loading