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

Raphael Isemann via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Mon May 24 06:45:21 PDT 2021


teemperor created this revision.
teemperor added a reviewer: LLDB.
teemperor added a project: LLDB.
Herald added a subscriber: JDevlieghere.
teemperor requested review of this revision.

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.


https://reviews.llvm.org/D103020

Files:
  lldb/source/Target/TargetList.cpp


Index: lldb/source/Target/TargetList.cpp
===================================================================
--- lldb/source/Target/TargetList.cpp
+++ lldb/source/Target/TargetList.cpp
@@ -48,6 +48,7 @@
                                 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 @@
                                 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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103020.347374.patch
Type: text/x-patch
Size: 1094 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20210524/1798d6e5/attachment.bin>


More information about the lldb-commits mailing list