-
Notifications
You must be signed in to change notification settings - Fork 13.9k
[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
base: main
Are you sure you want to change the base?
[llvm-debuginfo-analyzer] Incorrect directory path (.debug_line) #143849
Conversation
If any 'name' entry in the 'file_names' table from the .debug_line section contains directory information, the llvm-debuginfo-analyzer tool will display duplicated directory information when using the '--attribute=directories' option. .debug_line contents: Line table prologue: ... include_directories[ 0] = "path" file_names[ 0]: name: "path/test.cpp" dir_index: 0 ... the '--attribute=directories' will show: {Directory} 'path/path' <-- Duplicated 'path'
@llvm/pr-subscribers-debuginfo Author: Carlos Alberto Enciso (CarlosAlbertoEnciso) ChangesIf any 'name' entry in the 'file_names' table from the .debug_line .debug_line contents: the '--attribute=directories' will show: {Directory} 'path/path' <-- Duplicated 'path' Full diff: https://github.com/llvm/llvm-project/pull/143849.diff 2 Files Affected:
diff --git a/llvm/lib/DebugInfo/LogicalView/Readers/LVDWARFReader.cpp b/llvm/lib/DebugInfo/LogicalView/Readers/LVDWARFReader.cpp
index 7ff96ae90a7fd..f0b9da8c3fe80 100644
--- a/llvm/lib/DebugInfo/LogicalView/Readers/LVDWARFReader.cpp
+++ b/llvm/lib/DebugInfo/LogicalView/Readers/LVDWARFReader.cpp
@@ -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));
std::string String;
raw_string_ostream(String) << Directory << "/" << File;
- CompileUnit->addFilename(String);
+ CompileUnit->addFilename(transformPath(String));
}
// In DWARF5 the file indexes start at 0;
diff --git a/llvm/test/tools/llvm-debuginfo-analyzer/DWARF/dwarf-duplicated-directory-path.ll b/llvm/test/tools/llvm-debuginfo-analyzer/DWARF/dwarf-duplicated-directory-path.ll
new file mode 100644
index 0000000000000..87b383b16c721
--- /dev/null
+++ b/llvm/test/tools/llvm-debuginfo-analyzer/DWARF/dwarf-duplicated-directory-path.ll
@@ -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)
|
@llvm/pr-subscribers-llvm-binary-utilities Author: Carlos Alberto Enciso (CarlosAlbertoEnciso) ChangesIf any 'name' entry in the 'file_names' table from the .debug_line .debug_line contents: the '--attribute=directories' will show: {Directory} 'path/path' <-- Duplicated 'path' Full diff: https://github.com/llvm/llvm-project/pull/143849.diff 2 Files Affected:
diff --git a/llvm/lib/DebugInfo/LogicalView/Readers/LVDWARFReader.cpp b/llvm/lib/DebugInfo/LogicalView/Readers/LVDWARFReader.cpp
index 7ff96ae90a7fd..f0b9da8c3fe80 100644
--- a/llvm/lib/DebugInfo/LogicalView/Readers/LVDWARFReader.cpp
+++ b/llvm/lib/DebugInfo/LogicalView/Readers/LVDWARFReader.cpp
@@ -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));
std::string String;
raw_string_ostream(String) << Directory << "/" << File;
- CompileUnit->addFilename(String);
+ CompileUnit->addFilename(transformPath(String));
}
// In DWARF5 the file indexes start at 0;
diff --git a/llvm/test/tools/llvm-debuginfo-analyzer/DWARF/dwarf-duplicated-directory-path.ll b/llvm/test/tools/llvm-debuginfo-analyzer/DWARF/dwarf-duplicated-directory-path.ll
new file mode 100644
index 0000000000000..87b383b16c721
--- /dev/null
+++ b/llvm/test/tools/llvm-debuginfo-analyzer/DWARF/dwarf-duplicated-directory-path.ll
@@ -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)
|
This problem was discovered during the IR reader development (#135440), while comparing canonical views generated from IR and object files. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, @CarlosAlbertoEnciso! Looks clean; just one comment (see above).
// 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)); |
There was a problem hiding this comment.
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?
If any 'name' entry in the 'file_names' table from the .debug_line
section contains directory information, the llvm-debuginfo-analyzer
tool will display duplicated directory information when using the
'--attribute=directories' option.
.debug_line contents:
Line table prologue:
...
include_directories[ 0] = "path"
file_names[ 0]:
name: "path/test.cpp"
dir_index: 0
...
the '--attribute=directories' will show:
{Directory} 'path/path' <-- Duplicated 'path'