Go to the documentation of this file.
9 #ifndef LLDB_UTILITY_REPRODUCER_H
10 #define LLDB_UTILITY_REPRODUCER_H
13 #include "llvm/ADT/DenseMap.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/Support/Error.h"
16 #include "llvm/Support/VirtualFileSystem.h"
17 #include "llvm/Support/YAMLTraits.h"
59 virtual llvm::StringRef
GetName()
const = 0;
60 virtual llvm::StringRef
GetFile()
const = 0;
79 llvm::StringRef
GetName()
const override {
return ThisProviderT::Info::name; }
80 llvm::StringRef
GetFile()
const override {
return ThisProviderT::Info::file; }
112 std::unique_ptr<ProviderBase> provider = std::make_unique<T>(
m_root);
113 return static_cast<T *
>(
Register(std::move(provider)));
117 template <
typename T> T *
Get() {
121 return static_cast<T *
>(it->second.get());
126 auto *provider = Get<T>();
143 llvm::DenseMap<const void *, std::unique_ptr<ProviderBase>>
m_providers;
167 template <
typename T> llvm::Expected<std::string>
LoadBuffer() {
168 FileSpec file = GetFile<typename T::Info>();
169 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> buffer =
170 llvm::vfs::getRealFileSystem()->getBufferForFile(file.
GetPath());
172 return llvm::errorCodeToError(buffer.getError());
173 return (*buffer)->getBuffer().str();
181 bool HasFile(llvm::StringRef file);
194 llvm::Optional<FileSpec> root);
231 #endif // LLDB_UTILITY_REPRODUCER_H
FileSpec m_root
Every provider knows where to dump its potential files.
void Discard()
Method to indicate we do not want to keep the reproducer.
T * Get()
Get an existing provider.
std::vector< std::string > m_files
static llvm::Optional< Reproducer > & InstanceImpl()
llvm::Optional< Generator > m_generator
llvm::DenseMap< const void *, std::unique_ptr< ProviderBase > > m_providers
Map of provider IDs to provider instances.
Loader(FileSpec root, bool passive=false)
virtual llvm::StringRef GetName() const =0
void SetAutoGenerate(bool b)
Enable or disable auto generate.
bool m_done
Flag to ensure that we never call both keep and discard.
virtual llvm::StringRef GetFile() const =0
void AddProvidersToIndex()
Builds and index with provider info.
static const void * ClassID()
T & GetOrCreate()
Get a provider if it exists, otherwise create it.
llvm::Optional< Loader > m_loader
bool m_auto_generate
Flag to auto generate a reproducer when it would otherwise be discarded.
llvm::Expected< std::string > LoadBuffer()
FileSpec GetReproducerPath() const
virtual void Discard()
The Discard method is called when it is decided that we do not need to keep any information and will ...
FileSpec m_root
The reproducer root directory.
std::mutex m_providers_mutex
FileSpec CopyByAppendingPathComponent(llvm::StringRef component) const
virtual void Keep()
The Keep method is called when it is decided that we need to keep the data in order to provide a repr...
ProviderBase(const FileSpec &root)
llvm::Error SetCapture(llvm::Optional< FileSpec > root)
const FileSpec & GetRoot() const
static bool Initialized()
virtual const void * DynamicClassID() const =0
static const void * ClassID()
Generator * GetGenerator()
bool IsAutoGenerate() const
Return whether auto generate is enabled.
bool HasFile(llvm::StringRef file)
llvm::StringRef GetFile() const override
T * Create()
Create and register a new provider.
void Keep()
Method to indicate we want to keep the reproducer.
A class that represents a running process on the host machine.
The provider defines an interface for generating files needed for reproducing.
The reproducer enables clients to obtain access to the Generator and Loader.
const FileSpec & GetRoot() const
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
const FileSpec & GetRoot() const
static Reproducer & Instance()
The generator is responsible for the logic needed to generate a reproducer.
virtual ~ProviderBase()=default
ProviderBase * Register(std::unique_ptr< ProviderBase > provider)
llvm::StringRef GetName() const override
const void * DynamicClassID() const override