[Lldb-commits] [lldb] ba51da8 - [lldb] Add missing mutex guards to TargetList::CreateTarget

Raphael Isemann via lldb-commits lldb-commits at lists.llvm.org
Mon May 24 10:50:21 PDT 2021


Author: Raphael Isemann
Date: 2021-05-24T19:49:57+02:00
New Revision: ba51da820e4dc73153009f8a621ef49711294ae1

URL: https://github.com/llvm/llvm-project/commit/ba51da820e4dc73153009f8a621ef49711294ae1
DIFF: https://github.com/llvm/llvm-project/commit/ba51da820e4dc73153009f8a621ef49711294ae1.diff

LOG: [lldb] Add missing mutex guards to TargetList::CreateTarget

TestMultipleTargets is randomly failing on the bots. The reason for that is that
the test is calling `SBDebugger::CreateTarget` from multiple threads.
`TargetList::CreateTarget` is curiously missing the guard that all of its other
member functions have, so all the threads in the test end up changing the
internal TargetList state at the same time and end up corrupting it.

Reviewed By: vsk, JDevlieghere

Differential Revision: https://reviews.llvm.org/D103020

Added: 
    

Modified: 
    lldb/source/Target/TargetList.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Target/TargetList.cpp b/lldb/source/Target/TargetList.cpp
index 1e5856dd0b221..595799cfc92aa 100644
--- a/lldb/source/Target/TargetList.cpp
+++ b/lldb/source/Target/TargetList.cpp
@@ -48,6 +48,7 @@ Status TargetList::CreateTarget(Debugger &debugger,
                                 LoadDependentFiles load_dependent_files,
                                 const OptionGroupPlatform *platform_options,
                                 TargetSP &target_sp) {
+  std::lock_guard<std::recursive_mutex> guard(m_target_list_mutex);
   auto result = TargetList::CreateTargetInternal(
       debugger, user_exe_path, triple_str, load_dependent_files,
       platform_options, target_sp);
@@ -62,6 +63,7 @@ Status TargetList::CreateTarget(Debugger &debugger,
                                 const ArchSpec &specified_arch,
                                 LoadDependentFiles load_dependent_files,
                                 PlatformSP &platform_sp, TargetSP &target_sp) {
+  std::lock_guard<std::recursive_mutex> guard(m_target_list_mutex);
   auto result = TargetList::CreateTargetInternal(
       debugger, user_exe_path, specified_arch, load_dependent_files,
       platform_sp, target_sp);


        


More information about the lldb-commits mailing list