Skip to content

Commit

Permalink
[lldb/Reproducers] Always record the current working directory
Browse files Browse the repository at this point in the history
Setting the current working directory in the VFS will fail if the given
path doesn't exist in the YAML mapping or on disk.
  • Loading branch information
JDevlieghere committed Jul 20, 2020
1 parent 3f16114 commit f8df2e1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lldb/include/lldb/Utility/Reproducer.h
Expand Up @@ -11,6 +11,7 @@

#include "lldb/Utility/FileSpec.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/FileCollector.h"
#include "llvm/Support/YAMLTraits.h"
Expand Down Expand Up @@ -149,6 +150,7 @@ class WorkingDirectoryProvider : public Provider<WorkingDirectoryProvider> {
}

void Update(llvm::StringRef path) { m_cwd = std::string(path); }
llvm::StringRef GetWorkingDirectory() { return m_cwd; }

struct Info {
static const char *name;
Expand Down
5 changes: 4 additions & 1 deletion lldb/source/API/SBReproducer.cpp
Expand Up @@ -234,7 +234,10 @@ const char *SBReproducer::GetPath() {

void SBReproducer::SetWorkingDirectory(const char *path) {
if (auto *g = lldb_private::repro::Reproducer::Instance().GetGenerator()) {
g->GetOrCreate<WorkingDirectoryProvider>().Update(path);
auto &wp = g->GetOrCreate<repro::WorkingDirectoryProvider>();
wp.Update(path);
auto &fp = g->GetOrCreate<repro::FileProvider>();
fp.RecordInterestingDirectory(wp.GetWorkingDirectory());
}
}

Expand Down
2 changes: 2 additions & 0 deletions lldb/source/Initialization/SystemInitializerCommon.cpp
Expand Up @@ -94,6 +94,8 @@ llvm::Error SystemInitializerCommon::Initialize() {
vp.SetVersion(lldb_private::GetVersion());
repro::FileProvider &fp = g->GetOrCreate<repro::FileProvider>();
FileSystem::Initialize(fp.GetFileCollector());
repro::WorkingDirectoryProvider &wp = g->GetOrCreate<repro::WorkingDirectoryProvider>();
fp.RecordInterestingDirectory(wp.GetWorkingDirectory());
} else {
FileSystem::Initialize();
}
Expand Down
10 changes: 10 additions & 0 deletions lldb/test/Shell/Reproducer/TestWorkingDir.test
Expand Up @@ -15,3 +15,13 @@

# RUN: cat %t.repro/cwd.txt | FileCheck %t.check
# RUN: %lldb --replay %t.repro | FileCheck %t.check

# Make sure the current working directory is recorded even when it's not
# referenced.

# RUN: rm -rf %t.repro
# RUN: mkdir -p %t/probably_unique
# RUN: cd %t/probably_unique
# RUN: %lldb -x -b -o 'reproducer generate' --capture --capture-path %t.repro
# RUN: cat %t.repro/cwd.txt | FileCheck %s
# CHECK: probably_unique

0 comments on commit f8df2e1

Please sign in to comment.