[Lldb-commits] [lldb] r353702 - Breakpad: auto-detect path style of file entries
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Mon Feb 11 06:11:00 PST 2019
Author: labath
Date: Mon Feb 11 06:11:00 2019
New Revision: 353702
URL: http://llvm.org/viewvc/llvm-project?rev=353702&view=rev
Log:
Breakpad: auto-detect path style of file entries
Summary:
This adds support for auto-detection of path style to SymbolFileBreakpad
(similar to how r351328 did the same for DWARF). We guess each file
entry separately, as we have no idea which file came from which compile
units (and different compile units can have different path styles). The
breakpad generates should have already converted the paths to absolute
ones, so this guess should be reasonable accurate, but as always with
these kinds of things, it is hard to give guarantees about anything.
In an attempt to bring some unity to the path guessing logic, I move the
guessing logic from inside SymbolFileDWARF into the FileSpec class and
have both symbol files use it to implent their desired behavior.
Reviewers: clayborg, lemo, JDevlieghere
Subscribers: aprantl, markmentovai, lldb-commits
Differential Revision: https://reviews.llvm.org/D57895
Added:
lldb/trunk/lit/SymbolFile/Breakpad/Inputs/line-table-mixed-path-styles.syms
lldb/trunk/lit/SymbolFile/Breakpad/line-table-mixed-path-styles.test
Modified:
lldb/trunk/include/lldb/Utility/FileSpec.h
lldb/trunk/lit/SymbolFile/Breakpad/line-table-discontinuous-file-ids.test
lldb/trunk/lit/SymbolFile/Breakpad/line-table-edgecases.test
lldb/trunk/lit/SymbolFile/Breakpad/line-table-missing-file.test
lldb/trunk/lit/SymbolFile/Breakpad/line-table.test
lldb/trunk/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp
lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
lldb/trunk/source/Utility/FileSpec.cpp
lldb/trunk/unittests/Utility/FileSpecTest.cpp
Modified: lldb/trunk/include/lldb/Utility/FileSpec.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Utility/FileSpec.h?rev=353702&r1=353701&r2=353702&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Utility/FileSpec.h (original)
+++ lldb/trunk/include/lldb/Utility/FileSpec.h Mon Feb 11 06:11:00 2019
@@ -242,6 +242,13 @@ public:
static bool Equal(const FileSpec &a, const FileSpec &b, bool full);
+ /// Attempt to guess path style for a given path string. It returns a style,
+ /// if it was able to make a reasonable guess, or None if it wasn't. The guess
+ /// will be correct if the input path was a valid absolute path on the system
+ /// which produced it. On other paths the result of this function is
+ /// unreliable (e.g. "c:\foo.txt" is a valid relative posix path).
+ static llvm::Optional<Style> GuessPathStyle(llvm::StringRef absolute_path);
+
//------------------------------------------------------------------
/// Case sensitivity of path.
///
Added: lldb/trunk/lit/SymbolFile/Breakpad/Inputs/line-table-mixed-path-styles.syms
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/SymbolFile/Breakpad/Inputs/line-table-mixed-path-styles.syms?rev=353702&view=auto
==============================================================================
--- lldb/trunk/lit/SymbolFile/Breakpad/Inputs/line-table-mixed-path-styles.syms (added)
+++ lldb/trunk/lit/SymbolFile/Breakpad/Inputs/line-table-mixed-path-styles.syms Mon Feb 11 06:11:00 2019
@@ -0,0 +1,7 @@
+MODULE Linux x86_64 761550E08086333960A9074A9CE2895C0 a.out
+INFO CODE_ID E05015768680393360A9074A9CE2895C
+FILE 0 /tmp/a.c
+FILE 1 c:\tmp\b.c
+FUNC b0 10 0 func
+b0 1 1 0
+b1 1 1 1
Modified: lldb/trunk/lit/SymbolFile/Breakpad/line-table-discontinuous-file-ids.test
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/SymbolFile/Breakpad/line-table-discontinuous-file-ids.test?rev=353702&r1=353701&r2=353702&view=diff
==============================================================================
--- lldb/trunk/lit/SymbolFile/Breakpad/line-table-discontinuous-file-ids.test (original)
+++ lldb/trunk/lit/SymbolFile/Breakpad/line-table-discontinuous-file-ids.test Mon Feb 11 06:11:00 2019
@@ -1,7 +1,5 @@
# Test that we handle files which has gaps in the FILE record IDs.
-# XFAIL: system-windows
-
# RUN: yaml2obj %S/Inputs/basic-elf.yaml > %T/line-table-discontinuous-file-ids.out
# RUN: %lldb %T/line-table-discontinuous-file-ids.out \
# RUN: -o "target symbols add -s line-table-discontinuous-file-ids.out %S/Inputs/line-table-discontinuous-file-ids.syms" \
Modified: lldb/trunk/lit/SymbolFile/Breakpad/line-table-edgecases.test
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/SymbolFile/Breakpad/line-table-edgecases.test?rev=353702&r1=353701&r2=353702&view=diff
==============================================================================
--- lldb/trunk/lit/SymbolFile/Breakpad/line-table-edgecases.test (original)
+++ lldb/trunk/lit/SymbolFile/Breakpad/line-table-edgecases.test Mon Feb 11 06:11:00 2019
@@ -2,8 +2,6 @@
# input contains a LINE record which does not belong to any function as well as
# a FUNC record without any LINE records.
-# XFAIL: system-windows
-
# RUN: yaml2obj %S/Inputs/basic-elf.yaml > %T/line-table-edgecases.out
# RUN: %lldb %T/line-table-edgecases.out \
# RUN: -o "target symbols add -s line-table-edgecases.out %S/Inputs/line-table-edgecases.syms" \
Modified: lldb/trunk/lit/SymbolFile/Breakpad/line-table-missing-file.test
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/SymbolFile/Breakpad/line-table-missing-file.test?rev=353702&r1=353701&r2=353702&view=diff
==============================================================================
--- lldb/trunk/lit/SymbolFile/Breakpad/line-table-missing-file.test (original)
+++ lldb/trunk/lit/SymbolFile/Breakpad/line-table-missing-file.test Mon Feb 11 06:11:00 2019
@@ -3,8 +3,6 @@
# Right now, "something reasonable" means creating a line entry with an empty
# file.
-# XFAIL: system-windows
-
# RUN: yaml2obj %S/Inputs/basic-elf.yaml > %T/line-table-missing-file.out
# RUN: %lldb %T/line-table-missing-file.out \
# RUN: -o "target symbols add -s line-table-missing-file.out %S/Inputs/line-table-missing-file.syms" \
Added: lldb/trunk/lit/SymbolFile/Breakpad/line-table-mixed-path-styles.test
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/SymbolFile/Breakpad/line-table-mixed-path-styles.test?rev=353702&view=auto
==============================================================================
--- lldb/trunk/lit/SymbolFile/Breakpad/line-table-mixed-path-styles.test (added)
+++ lldb/trunk/lit/SymbolFile/Breakpad/line-table-mixed-path-styles.test Mon Feb 11 06:11:00 2019
@@ -0,0 +1,11 @@
+# RUN: yaml2obj %S/Inputs/basic-elf.yaml > %T/line-table-mixed-path-styles.out
+# RUN: %lldb %T/line-table-mixed-path-styles.out \
+# RUN: -o "target symbols add -s line-table-mixed-path-styles.out %S/Inputs/line-table-mixed-path-styles.syms" \
+# RUN: -s %s -o exit | FileCheck %s
+
+image dump line-table a.c
+# CHECK-LABEL: Line table for /tmp/a.c
+# CHECK-NEXT: 0x00000000004000b0: /tmp/a.c:1
+# CHECK-NEXT: 0x00000000004000b1: c:\tmp\b.c:1
+# CHECK-NEXT: 0x00000000004000b2:
+# CHECK-EMPTY:
Modified: lldb/trunk/lit/SymbolFile/Breakpad/line-table.test
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/SymbolFile/Breakpad/line-table.test?rev=353702&r1=353701&r2=353702&view=diff
==============================================================================
--- lldb/trunk/lit/SymbolFile/Breakpad/line-table.test (original)
+++ lldb/trunk/lit/SymbolFile/Breakpad/line-table.test Mon Feb 11 06:11:00 2019
@@ -1,5 +1,3 @@
-# XFAIL: system-windows
-
# RUN: yaml2obj %S/Inputs/basic-elf.yaml > %T/line-table.out
# RUN: %lldb %T/line-table.out -o "target symbols add -s line-table.out %S/Inputs/line-table.syms" \
# RUN: -s %s -o exit | FileCheck %s
Modified: lldb/trunk/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp?rev=353702&r1=353701&r2=353702&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp Mon Feb 11 06:11:00 2019
@@ -398,7 +398,9 @@ void SymbolFileBreakpad::ParseFileRecord
if (record->Number >= m_files->size())
m_files->resize(record->Number + 1);
- (*m_files)[record->Number] = FileSpec(record->Name);
+ FileSpec::Style style = FileSpec::GuessPathStyle(record->Name)
+ .getValueOr(FileSpec::Style::native);
+ (*m_files)[record->Number] = FileSpec(record->Name, style);
}
}
Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp?rev=353702&r1=353701&r2=353702&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp Mon Feb 11 06:11:00 2019
@@ -820,22 +820,19 @@ void DWARFUnit::ComputeCompDirAndGuessPa
if (!die)
return;
- auto guess = [](llvm::StringRef str) {
- if (str.startswith("/"))
- return FileSpec::Style::posix;
- if (str.size() > 3 && llvm::isAlpha(str[0]) && str.substr(1, 2) == ":\\")
- return FileSpec::Style::windows;
- return FileSpec::Style::native;
- };
llvm::StringRef comp_dir = removeHostnameFromPathname(
die->GetAttributeValueAsString(m_dwarf, this, DW_AT_comp_dir, NULL));
if (!comp_dir.empty()) {
- m_comp_dir = resolveCompDir(FileSpec(comp_dir, guess(comp_dir)));
+ FileSpec::Style comp_dir_style =
+ FileSpec::GuessPathStyle(comp_dir).getValueOr(FileSpec::Style::native);
+ m_comp_dir = resolveCompDir(FileSpec(comp_dir, comp_dir_style));
} else {
// Try to detect the style based on the DW_AT_name attribute, but just store
// the detected style in the m_comp_dir field.
- m_comp_dir = FileSpec("", guess(die->GetAttributeValueAsString(
- m_dwarf, this, DW_AT_name, NULL)));
+ const char *name =
+ die->GetAttributeValueAsString(m_dwarf, this, DW_AT_name, NULL);
+ m_comp_dir = FileSpec(
+ "", FileSpec::GuessPathStyle(name).getValueOr(FileSpec::Style::native));
}
}
Modified: lldb/trunk/source/Utility/FileSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/FileSpec.cpp?rev=353702&r1=353701&r2=353702&view=diff
==============================================================================
--- lldb/trunk/source/Utility/FileSpec.cpp (original)
+++ lldb/trunk/source/Utility/FileSpec.cpp Mon Feb 11 06:11:00 2019
@@ -365,6 +365,17 @@ bool FileSpec::Equal(const FileSpec &a,
return a == b;
}
+llvm::Optional<FileSpec::Style> FileSpec::GuessPathStyle(llvm::StringRef absolute_path) {
+ if (absolute_path.startswith("/"))
+ return Style::posix;
+ if (absolute_path.startswith(R"(\\)"))
+ return Style::windows;
+ if (absolute_path.size() > 3 && llvm::isAlpha(absolute_path[0]) &&
+ absolute_path.substr(1, 2) == R"(:\)")
+ return Style::windows;
+ return llvm::None;
+}
+
//------------------------------------------------------------------
// Dump the object to the supplied stream. If the object contains a valid
// directory name, it will be displayed followed by a directory delimiter, and
Modified: lldb/trunk/unittests/Utility/FileSpecTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Utility/FileSpecTest.cpp?rev=353702&r1=353701&r2=353702&view=diff
==============================================================================
--- lldb/trunk/unittests/Utility/FileSpecTest.cpp (original)
+++ lldb/trunk/unittests/Utility/FileSpecTest.cpp Mon Feb 11 06:11:00 2019
@@ -189,6 +189,17 @@ TEST(FileSpecTest, EqualDotsPosixRoot) {
}
}
+TEST(FileSpecTest, GuessPathStyle) {
+ EXPECT_EQ(FileSpec::Style::posix, FileSpec::GuessPathStyle("/foo/bar.txt"));
+ EXPECT_EQ(FileSpec::Style::posix, FileSpec::GuessPathStyle("//net/bar.txt"));
+ EXPECT_EQ(FileSpec::Style::windows,
+ FileSpec::GuessPathStyle(R"(C:\foo.txt)"));
+ EXPECT_EQ(FileSpec::Style::windows,
+ FileSpec::GuessPathStyle(R"(\\net\foo.txt)"));
+ EXPECT_EQ(llvm::None, FileSpec::GuessPathStyle("foo.txt"));
+ EXPECT_EQ(llvm::None, FileSpec::GuessPathStyle("foo/bar.txt"));
+}
+
TEST(FileSpecTest, GetNormalizedPath) {
std::pair<const char *, const char *> posix_tests[] = {
{"/foo/.././bar", "/bar"},
More information about the lldb-commits
mailing list