[Lldb-commits] [lldb] r373102 - [Reproducer] Always use absolute paths for capture & replay.

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Fri Sep 27 10:30:40 PDT 2019


Author: jdevlieghere
Date: Fri Sep 27 10:30:40 2019
New Revision: 373102

URL: http://llvm.org/viewvc/llvm-project?rev=373102&view=rev
Log:
[Reproducer] Always use absolute paths for capture & replay.

The VFS requires files to be have absolute paths. The file collector
makes paths relative to the reproducer root. If the root is a relative
path, this would trigger an assert in the VFS. This patch ensures that
we always make the given path absolute.

Thank you Ted Woodward for pointing this out!

Added:
    lldb/trunk/lit/Reproducer/TestRelativePath.test
Modified:
    lldb/trunk/include/lldb/Utility/Reproducer.h
    lldb/trunk/source/Utility/Reproducer.cpp

Modified: lldb/trunk/include/lldb/Utility/Reproducer.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Utility/Reproducer.h?rev=373102&r1=373101&r2=373102&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Utility/Reproducer.h (original)
+++ lldb/trunk/include/lldb/Utility/Reproducer.h Fri Sep 27 10:30:40 2019
@@ -215,7 +215,7 @@ private:
 class Generator final {
 
 public:
-  Generator(const FileSpec &root);
+  Generator(FileSpec root);
   ~Generator();
 
   /// Method to indicate we want to keep the reproducer. If reproducer
@@ -272,7 +272,7 @@ private:
 
 class Loader final {
 public:
-  Loader(const FileSpec &root);
+  Loader(FileSpec root);
 
   template <typename T> FileSpec GetFile() {
     if (!HasFile(T::file))

Added: lldb/trunk/lit/Reproducer/TestRelativePath.test
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Reproducer/TestRelativePath.test?rev=373102&view=auto
==============================================================================
--- lldb/trunk/lit/Reproducer/TestRelativePath.test (added)
+++ lldb/trunk/lit/Reproducer/TestRelativePath.test Fri Sep 27 10:30:40 2019
@@ -0,0 +1,8 @@
+# This tests relative capture paths.
+
+# RUN: mkdir -p %t
+# RUN: cd %t
+# RUN: rm -rf ./foo
+# RUN: %clang %S/Inputs/simple.c -g -o %t/reproducer.out
+# RUN: %lldb -x -b -s %S/Inputs/FileCapture.in -o 'reproducer dump -p files' --capture --capture-path ./foo %t/reproducer.out
+# RUN: %lldb --replay ./foo

Modified: lldb/trunk/source/Utility/Reproducer.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/Reproducer.cpp?rev=373102&r1=373101&r2=373102&view=diff
==============================================================================
--- lldb/trunk/source/Utility/Reproducer.cpp (original)
+++ lldb/trunk/source/Utility/Reproducer.cpp Fri Sep 27 10:30:40 2019
@@ -136,7 +136,15 @@ FileSpec Reproducer::GetReproducerPath()
   return {};
 }
 
-Generator::Generator(const FileSpec &root) : m_root(root), m_done(false) {}
+static FileSpec MakeAbsolute(FileSpec file_spec) {
+  SmallString<128> path;
+  file_spec.GetPath(path, false);
+  llvm::sys::fs::make_absolute(path);
+  return FileSpec(path, file_spec.GetPathStyle());
+}
+
+Generator::Generator(FileSpec root)
+    : m_root(MakeAbsolute(std::move(root))), m_done(false) {}
 
 Generator::~Generator() {}
 
@@ -188,7 +196,8 @@ void Generator::AddProvidersToIndex() {
   yout << files;
 }
 
-Loader::Loader(const FileSpec &root) : m_root(root), m_loaded(false) {}
+Loader::Loader(FileSpec root)
+    : m_root(MakeAbsolute(std::move(root))), m_loaded(false) {}
 
 llvm::Error Loader::LoadIndex() {
   if (m_loaded)




More information about the lldb-commits mailing list