Skip to content

Commit 8bda2cf

Browse files
committed
Move lock guard before AddTargetInternal instead of holding the mutex for the entire target creation and causing a deadlock with the module callback when running in parallel.
1 parent c4be17a commit 8bda2cf

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

lldb/source/Target/TargetList.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,16 @@ Status TargetList::CreateTarget(Debugger &debugger,
4848
LoadDependentFiles load_dependent_files,
4949
const OptionGroupPlatform *platform_options,
5050
TargetSP &target_sp) {
51-
std::lock_guard<std::recursive_mutex> guard(m_target_list_mutex);
51+
// Create Target Internal does not modify and state
52+
// directly and instead calls into methods which
53+
// they themselves are thread-safe. We do this so
54+
// the load module call back doesn't cause a re-entry
55+
// dead-lock when creating the target.
5256
auto result = TargetList::CreateTargetInternal(
5357
debugger, user_exe_path, triple_str, load_dependent_files,
5458
platform_options, target_sp);
5559

60+
std::lock_guard<std::recursive_mutex> guard(m_target_list_mutex);
5661
if (target_sp && result.Success())
5762
AddTargetInternal(target_sp, /*do_select*/ true);
5863
return result;
@@ -63,11 +68,16 @@ Status TargetList::CreateTarget(Debugger &debugger,
6368
const ArchSpec &specified_arch,
6469
LoadDependentFiles load_dependent_files,
6570
PlatformSP &platform_sp, TargetSP &target_sp) {
66-
std::lock_guard<std::recursive_mutex> guard(m_target_list_mutex);
71+
// Create Target Internal does not modify and state
72+
// directly and instead calls into methods which
73+
// they themselves are thread-safe. We do this so
74+
// the load module call back doesn't cause a re-entry
75+
// dead-lock when creating the target.
6776
auto result = TargetList::CreateTargetInternal(
6877
debugger, user_exe_path, specified_arch, load_dependent_files,
6978
platform_sp, target_sp);
7079

80+
std::lock_guard<std::recursive_mutex> guard(m_target_list_mutex);
7181
if (target_sp && result.Success())
7282
AddTargetInternal(target_sp, /*do_select*/ true);
7383
return result;

0 commit comments

Comments
 (0)