diff options
author | Jonas Devlieghere <jonas@devlieghere.com> | 2018-10-22 20:14:36 +0000 |
---|---|---|
committer | Jonas Devlieghere <jonas@devlieghere.com> | 2018-10-22 20:14:36 +0000 |
commit | 4f78c4f67b1e0901a97a828634b9cd3ddc70ca40 (patch) | |
tree | 47db7c33a5cd4cc8bb551691bbfee3b7b77caabe /lldb/source/Symbol/SymbolFile.cpp | |
parent | 7e4edbdd1b4d2fa97478fc16be2efff4de9afdf9 (diff) | |
download | bcm5719-llvm-4f78c4f67b1e0901a97a828634b9cd3ddc70ca40.tar.gz bcm5719-llvm-4f78c4f67b1e0901a97a828634b9cd3ddc70ca40.zip |
[SymbolFile] Add the module lock where necessary and assert that we own it.
As discussed with Greg at the dev meeting, we need to ensure we have the
module lock in the SymbolFile. Usually the symbol file is accessed
through the symbol vendor which ensures that the necessary locks are
taken. However, there are a few methods that are accessed by the
expression parser and were lacking the lock.
This patch adds the locking where necessary and everywhere else asserts
that we actually already own the lock.
Differential revision: https://reviews.llvm.org/D52543
llvm-svn: 344945
Diffstat (limited to 'lldb/source/Symbol/SymbolFile.cpp')
-rw-r--r-- | lldb/source/Symbol/SymbolFile.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lldb/source/Symbol/SymbolFile.cpp b/lldb/source/Symbol/SymbolFile.cpp index 6b4da9c5300..4bf7e5bacb9 100644 --- a/lldb/source/Symbol/SymbolFile.cpp +++ b/lldb/source/Symbol/SymbolFile.cpp @@ -19,12 +19,18 @@ #include "lldb/Utility/StreamString.h" #include "lldb/lldb-private.h" +#include <future> + using namespace lldb_private; void SymbolFile::PreloadSymbols() { // No-op for most implementations. } +std::recursive_mutex &SymbolFile::GetModuleMutex() const { + return GetObjectFile()->GetModule()->GetMutex(); +} + SymbolFile *SymbolFile::FindPlugin(ObjectFile *obj_file) { std::unique_ptr<SymbolFile> best_symfile_ap; if (obj_file != nullptr) { @@ -150,3 +156,17 @@ size_t SymbolFile::FindTypes(const std::vector<CompilerContext> &context, types.Clear(); return 0; } + +void SymbolFile::AssertModuleLock() { + // The code below is too expensive to leave enabled in release builds. It's + // enabled in debug builds or when the correct macro is set. +#if defined(LLDB_CONFIGURATION_DEBUG) + // We assert that we have to module lock by trying to acquire the lock from a + // different thread. Note that we must abort if the result is true to + // guarantee correctness. + assert(std::async(std::launch::async, + [this] { return this->GetModuleMutex().try_lock(); }) + .get() == false && + "Module is not locked"); +#endif +} |