diff options
| author | Frederic Riss <friss@apple.com> | 2018-05-11 18:21:11 +0000 |
|---|---|---|
| committer | Frederic Riss <friss@apple.com> | 2018-05-11 18:21:11 +0000 |
| commit | d10d3795f737ca8a0f602e8a442728d301e65378 (patch) | |
| tree | 48bfd332e4b87f99a6d443d656f3d16b4763bc1a /lldb/source/Plugins/Platform | |
| parent | 5fb6437012ce6020a86ff4dfdae56306fea8d80a (diff) | |
| download | bcm5719-llvm-d10d3795f737ca8a0f602e8a442728d301e65378.tar.gz bcm5719-llvm-d10d3795f737ca8a0f602e8a442728d301e65378.zip | |
Add a lock to PlatformPOSIX::DoLoadImage
Summary:
Multiple threads could be calling into DoLoadImage concurrently,
only one should be allowed to create the UtilityFunction.
Reviewers: jingham
Subscribers: emaste, lldb-commits
Differential Revision: https://reviews.llvm.org/D46733
llvm-svn: 332115
Diffstat (limited to 'lldb/source/Plugins/Platform')
| -rw-r--r-- | lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp | 30 | ||||
| -rw-r--r-- | lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.h | 8 |
2 files changed, 16 insertions, 22 deletions
diff --git a/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp b/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp index f7a82651022..9b2c86a5f68 100644 --- a/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp +++ b/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp @@ -929,10 +929,9 @@ Status PlatformPOSIX::EvaluateLibdlExpression( return Status(); } -UtilityFunction * -PlatformPOSIX::MakeLoadImageUtilityFunction(ExecutionContext &exe_ctx, - Status &error) -{ +std::unique_ptr<UtilityFunction> +PlatformPOSIX::MakeLoadImageUtilityFunction(ExecutionContext &exe_ctx, + Status &error) { // Remember to prepend this with the prefix from // GetLibdlFunctionDeclarations. The returned values are all in // __lldb_dlopen_result for consistency. The wrapper returns a void * but @@ -982,7 +981,6 @@ PlatformPOSIX::MakeLoadImageUtilityFunction(ExecutionContext &exe_ctx, Value value; ValueList arguments; FunctionCaller *do_dlopen_function = nullptr; - UtilityFunction *dlopen_utility_func = nullptr; // Fetch the clang types we will need: ClangASTContext *ast = process->GetTarget().GetScratchClangASTContext(); @@ -1015,9 +1013,7 @@ PlatformPOSIX::MakeLoadImageUtilityFunction(ExecutionContext &exe_ctx, } // We made a good utility function, so cache it in the process: - dlopen_utility_func = dlopen_utility_func_up.get(); - process->SetLoadImageUtilityFunction(std::move(dlopen_utility_func_up)); - return dlopen_utility_func; + return dlopen_utility_func_up; } uint32_t PlatformPOSIX::DoLoadImage(lldb_private::Process *process, @@ -1038,18 +1034,16 @@ uint32_t PlatformPOSIX::DoLoadImage(lldb_private::Process *process, thread_sp->CalculateExecutionContext(exe_ctx); Status utility_error; - - // The UtilityFunction is held in the Process. Platforms don't track the - // lifespan of the Targets that use them, we can't put this in the Platform. - UtilityFunction *dlopen_utility_func - = process->GetLoadImageUtilityFunction(this); + UtilityFunction *dlopen_utility_func; ValueList arguments; FunctionCaller *do_dlopen_function = nullptr; - - if (!dlopen_utility_func) { - // Make the UtilityFunction: - dlopen_utility_func = MakeLoadImageUtilityFunction(exe_ctx, error); - } + + // The UtilityFunction is held in the Process. Platforms don't track the + // lifespan of the Targets that use them, we can't put this in the Platform. + dlopen_utility_func = process->GetLoadImageUtilityFunction( + this, [&]() -> std::unique_ptr<UtilityFunction> { + return MakeLoadImageUtilityFunction(exe_ctx, error); + }); // If we couldn't make it, the error will be in error, so we can exit here. if (!dlopen_utility_func) return LLDB_INVALID_IMAGE_TOKEN; diff --git a/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.h b/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.h index 1235e21f30d..12d6c6209f0 100644 --- a/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.h +++ b/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.h @@ -199,10 +199,10 @@ protected: EvaluateLibdlExpression(lldb_private::Process *process, const char *expr_cstr, llvm::StringRef expr_prefix, lldb::ValueObjectSP &result_valobj_sp); - - lldb_private::UtilityFunction * - MakeLoadImageUtilityFunction(lldb_private::ExecutionContext &exe_ctx, - lldb_private::Status &error); + + std::unique_ptr<lldb_private::UtilityFunction> + MakeLoadImageUtilityFunction(lldb_private::ExecutionContext &exe_ctx, + lldb_private::Status &error); virtual llvm::StringRef GetLibdlFunctionDeclarations(lldb_private::Process *process); |

