summaryrefslogtreecommitdiffstats
path: root/lldb/source
diff options
context:
space:
mode:
authorJonas Devlieghere <jonas@devlieghere.com>2019-01-18 01:04:59 +0000
committerJonas Devlieghere <jonas@devlieghere.com>2019-01-18 01:04:59 +0000
commite912cc512d61a7934f345b0952a2dbdf5e11e1e1 (patch)
tree1492c55ca4126fc31409a4bd86b2c1b1a0ba0672 /lldb/source
parent342a7ac8d6419aec9a79ea4ac3c93bbb6beeba26 (diff)
downloadbcm5719-llvm-e912cc512d61a7934f345b0952a2dbdf5e11e1e1.tar.gz
bcm5719-llvm-e912cc512d61a7934f345b0952a2dbdf5e11e1e1.zip
[Reproducers] Refactor reproducer info
In the original reproducer design, I expected providers to be more dynamic than they turned out. For example, we don't have any instances where one provider has multiple files. Additionally, I expected there to be less locality between capture and replay, with the provider being defined in one place and the replay code to live in another. Both contributed to the design of the provider info. This patch refactors the reproducer info to be something static. This means less magic strings and better type checking. The new design still allows for the capture and replay code to live in different places as long as they both have access to the new statically defined info class. I didn't completely get rid of the index, because it is useful for (1) sanity checking and (2) knowing what files are used by the reproducer. Differential revision: https://reviews.llvm.org/D56814 llvm-svn: 351501
Diffstat (limited to 'lldb/source')
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp27
-rw-r--r--lldb/source/Utility/Reproducer.cpp26
2 files changed, 26 insertions, 27 deletions
diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
index 797f63d537a..00bdd74eecb 100644
--- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -157,17 +157,24 @@ static const ProcessKDPPropertiesSP &GetGlobalPluginProperties() {
return g_settings_sp;
}
+struct ProcessGDBRemoteInfo {
+ static const char *name;
+ static const char *file;
+};
+
+const char *ProcessGDBRemoteInfo::name = "gdb-remote";
+const char *ProcessGDBRemoteInfo::file = "gdb-remote.yaml";
+
class ProcessGDBRemoteProvider
: public repro::Provider<ProcessGDBRemoteProvider> {
public:
+ typedef ProcessGDBRemoteInfo info;
+
ProcessGDBRemoteProvider(const FileSpec &directory) : Provider(directory) {
- m_info.name = "gdb-remote";
- m_info.files.push_back("gdb-remote.yaml");
}
raw_ostream *GetHistoryStream() {
- FileSpec history_file =
- GetRoot().CopyByAppendingPathComponent("gdb-remote.yaml");
+ FileSpec history_file = GetRoot().CopyByAppendingPathComponent(info::file);
std::error_code EC;
m_stream_up = llvm::make_unique<raw_fd_ostream>(history_file.GetPath(), EC,
@@ -3432,16 +3439,10 @@ Status ProcessGDBRemote::ConnectToReplayServer(repro::Loader *loader) {
if (!loader)
return Status("No loader provided.");
- auto provider_info = loader->GetProviderInfo("gdb-remote");
- if (!provider_info)
- return Status("No provider for gdb-remote.");
-
- if (provider_info->files.empty())
- return Status("Provider for gdb-remote contains no files.");
-
// Construct replay history path.
- FileSpec history_file = loader->GetRoot().CopyByAppendingPathComponent(
- provider_info->files.front());
+ FileSpec history_file = loader->GetFile<ProcessGDBRemoteInfo>();
+ if (!history_file)
+ return Status("No provider for gdb-remote.");
// Enable replay mode.
m_replay_mode = true;
diff --git a/lldb/source/Utility/Reproducer.cpp b/lldb/source/Utility/Reproducer.cpp
index 6e85ba41767..d012faf9d76 100644
--- a/lldb/source/Utility/Reproducer.cpp
+++ b/lldb/source/Utility/Reproducer.cpp
@@ -178,10 +178,13 @@ void Generator::AddProvidersToIndex() {
sys::fs::OpenFlags::F_None);
yaml::Output yout(*strm);
+ std::vector<std::string> files;
+ files.reserve(m_providers.size());
for (auto &provider : m_providers) {
- auto &provider_info = provider.second->GetInfo();
- yout << const_cast<ProviderInfo &>(provider_info);
+ files.emplace_back(provider.second->GetFile());
}
+
+ yout << files;
}
Loader::Loader(const FileSpec &root) : m_root(root), m_loaded(false) {}
@@ -196,29 +199,24 @@ llvm::Error Loader::LoadIndex() {
if (auto err = error_or_file.getError())
return make_error<StringError>("unable to load reproducer index", err);
- std::vector<ProviderInfo> provider_info;
yaml::Input yin((*error_or_file)->getBuffer());
- yin >> provider_info;
-
+ yin >> m_files;
if (auto err = yin.error())
return make_error<StringError>("unable to read reproducer index", err);
- for (auto &info : provider_info)
- m_provider_info[info.name] = info;
+ // Sort files to speed up search.
+ llvm::sort(m_files);
+ // Remember that we've loaded the index.
m_loaded = true;
return llvm::Error::success();
}
-llvm::Optional<ProviderInfo> Loader::GetProviderInfo(StringRef name) {
+bool Loader::HasFile(StringRef file) {
assert(m_loaded);
-
- auto it = m_provider_info.find(name);
- if (it == m_provider_info.end())
- return llvm::None;
-
- return it->second;
+ auto it = std::lower_bound(m_files.begin(), m_files.end(), file.str());
+ return (it != m_files.end()) && (*it == file);
}
void ProviderBase::anchor() {}
OpenPOWER on IntegriCloud