Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This patch adds the file provider which is responsible for capturing files used by LLDB. When capturing a reproducer, we use a file collector that is very similar to the one used in clang. For every file that we touch, we add an entry with a mapping from its virtual to its real path. When we decide to generate a reproducer we copy over the files and their permission into to reproducer folder. When replaying a reproducer, we load the VFS mapping and instantiate a RedirectingFileSystem. The latter will transparently use the files available in the reproducer. I've tested this on two macOS machines with an artificial example. Still, it is very likely that I missed some places where we (still) use native file system calls. I'm hoping to flesh those out while testing with more advanced examples. However, I will fix those things in separate patches. Differential revision: https://reviews.llvm.org/D54617 llvm-svn: 352538
- Loading branch information
1 parent
6159e86
commit 4657517
Showing
15 changed files
with
606 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
//===-- FileCollector.h -----------------------------------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLDB_UTILITY_FILE_COLLECTOR_H | ||
#define LLDB_UTILITY_FILE_COLLECTOR_H | ||
|
||
#include "lldb/Utility/FileSpec.h" | ||
|
||
#include "llvm/ADT/SmallVector.h" | ||
#include "llvm/ADT/StringMap.h" | ||
#include "llvm/ADT/StringSet.h" | ||
#include "llvm/ADT/Twine.h" | ||
#include "llvm/Support/VirtualFileSystem.h" | ||
|
||
#include <mutex> | ||
|
||
namespace lldb_private { | ||
|
||
/// Collects files into a directory and generates a mapping that can be used by | ||
/// the VFS. | ||
class FileCollector { | ||
public: | ||
FileCollector(const FileSpec &root); | ||
|
||
void AddFile(const llvm::Twine &file); | ||
void AddFile(const FileSpec &file) { return AddFile(file.GetPath()); } | ||
|
||
/// Write the yaml mapping (for the VFS) to the given file. | ||
std::error_code WriteMapping(const FileSpec &mapping_file); | ||
|
||
/// Copy the files into the root directory. | ||
/// | ||
/// When stop_on_error is true (the default) we abort as soon as one file | ||
/// cannot be copied. This is relatively common, for example when a file was | ||
/// removed after it was added to the mapping. | ||
std::error_code CopyFiles(bool stop_on_error = true); | ||
|
||
protected: | ||
void AddFileImpl(llvm::StringRef src_path); | ||
|
||
bool MarkAsSeen(llvm::StringRef path) { return m_seen.insert(path).second; } | ||
|
||
bool GetRealPath(llvm::StringRef src_path, | ||
llvm::SmallVectorImpl<char> &result); | ||
|
||
void AddFileToMapping(llvm::StringRef virtual_path, | ||
llvm::StringRef real_path) { | ||
m_vfs_writer.addFileMapping(virtual_path, real_path); | ||
} | ||
|
||
/// Synchronizes adding files. | ||
std::mutex m_mutex; | ||
|
||
/// The root directory where files are copied. | ||
FileSpec m_root; | ||
|
||
/// Tracks already seen files so they can be skipped. | ||
llvm::StringSet<> m_seen; | ||
|
||
/// The yaml mapping writer. | ||
llvm::vfs::YAMLVFSWriter m_vfs_writer; | ||
|
||
/// Caches real_path calls when resolving symlinks. | ||
llvm::StringMap<std::string> m_symlink_map; | ||
}; | ||
|
||
} // namespace lldb_private | ||
|
||
#endif // LLDB_UTILITY_FILE_COLLECTOR_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
run | ||
reproducer status | ||
reproducer generate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
reproducer status | ||
run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# REQUIRES: system-darwin | ||
|
||
# This tests the replaying of GDB remote packets. | ||
# | ||
# We issue the same commands and ensure the output is identical to the original | ||
# process. To ensure we're not actually running the original binary we check | ||
# that the string "testing" is not printed. | ||
|
||
# RUN: %clang %S/Inputs/simple.c -g -o %t.out | ||
# RUN: %lldb -x -b -s %S/Inputs/FileCapture.in --capture %t.repro -- %t.out | FileCheck %s --check-prefix CHECK --check-prefix CAPTURE | ||
# RUN: rm %t.out | ||
# RUN: %lldb -x -b -s %S/Inputs/FileReplay.in --replay %t.repro -- %t.out | FileCheck %s --check-prefix CHECK --check-prefix REPLAY | ||
|
||
# CAPTURE: testing | ||
# REPLAY-NOT: testing | ||
|
||
# CHECK: Process {{.*}} exited | ||
|
||
# CAPTURE: Reproducer is in capture mode. | ||
# CAPTURE: Reproducer written |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.