Skip to content

Commit 27ef81c

Browse files
committed
[Reproducer] Capture the debugger's working directory
This patch extends the reproducer to capture the debugger's current working directory. This information will be used later to set the current working directory of the VFS. llvm-svn: 375059
1 parent d3dd489 commit 27ef81c

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

lldb/include/lldb/Utility/Reproducer.h

+21
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,27 @@ class VersionProvider : public Provider<VersionProvider> {
132132
static char ID;
133133
};
134134

135+
/// Provider for the LLDB current working directroy.
136+
///
137+
/// When the reproducer is kept, it writes lldb's current working directory to
138+
/// a file named cwd.txt in the reproducer root.
139+
class WorkingDirectoryProvider : public Provider<WorkingDirectoryProvider> {
140+
public:
141+
WorkingDirectoryProvider(const FileSpec &directory) : Provider(directory) {
142+
llvm::SmallString<128> cwd;
143+
if (std::error_code EC = llvm::sys::fs::current_path(cwd))
144+
return;
145+
m_cwd = cwd.str();
146+
}
147+
struct Info {
148+
static const char *name;
149+
static const char *file;
150+
};
151+
void Keep() override;
152+
std::string m_cwd;
153+
static char ID;
154+
};
155+
135156
class DataRecorder {
136157
public:
137158
DataRecorder(const FileSpec &filename, std::error_code &ec)

lldb/source/Utility/Reproducer.cpp

+15-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ static FileSpec MakeAbsolute(FileSpec file_spec) {
144144
}
145145

146146
Generator::Generator(FileSpec root)
147-
: m_root(MakeAbsolute(std::move(root))), m_done(false) {}
147+
: m_root(MakeAbsolute(std::move(root))), m_done(false) {
148+
GetOrCreate<repro::WorkingDirectoryProvider>();
149+
}
148150

149151
Generator::~Generator() {}
150152

@@ -281,6 +283,15 @@ void VersionProvider::Keep() {
281283
os << m_version << "\n";
282284
}
283285

286+
void WorkingDirectoryProvider::Keep() {
287+
FileSpec file = GetRoot().CopyByAppendingPathComponent(Info::file);
288+
std::error_code ec;
289+
llvm::raw_fd_ostream os(file.GetPath(), ec, llvm::sys::fs::OF_Text);
290+
if (ec)
291+
return;
292+
os << m_cwd << "\n";
293+
}
294+
284295
llvm::raw_ostream *ProcessGDBRemoteProvider::GetHistoryStream() {
285296
FileSpec history_file = GetRoot().CopyByAppendingPathComponent(Info::file);
286297

@@ -330,6 +341,7 @@ char FileProvider::ID = 0;
330341
char ProcessGDBRemoteProvider::ID = 0;
331342
char ProviderBase::ID = 0;
332343
char VersionProvider::ID = 0;
344+
char WorkingDirectoryProvider::ID = 0;
333345
const char *CommandProvider::Info::file = "command-interpreter.yaml";
334346
const char *CommandProvider::Info::name = "command-interpreter";
335347
const char *FileProvider::Info::file = "files.yaml";
@@ -338,3 +350,5 @@ const char *ProcessGDBRemoteProvider::Info::file = "gdb-remote.yaml";
338350
const char *ProcessGDBRemoteProvider::Info::name = "gdb-remote";
339351
const char *VersionProvider::Info::file = "version.txt";
340352
const char *VersionProvider::Info::name = "version";
353+
const char *WorkingDirectoryProvider::Info::file = "cwd.txt";
354+
const char *WorkingDirectoryProvider::Info::name = "cwd";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# This tests relative capture paths.
2+
3+
# RUN: echo "CHECK: %t" > %t.check
4+
5+
# RUN: rm -rf %t.repro
6+
# RUN: mkdir -p %t.repro
7+
# RUN: mkdir -p %t
8+
# RUN: cd %t
9+
# RUN: %clang %S/Inputs/simple.c -g -o %t/reproducer.out
10+
# RUN: %lldb -x -b -s %S/Inputs/FileCapture.in --capture --capture-path %t.repro %t/reproducer.out
11+
# RUN: cat %t.repro/cwd.txt | FileCheck %t.check

0 commit comments

Comments
 (0)