@@ -176,7 +176,7 @@ Status TargetList::CreateTargetInternal(
176176 module_spec.GetArchitecture () = arch;
177177 if (module_specs.FindMatchingModuleSpec (module_spec,
178178 matching_module_spec))
179- update_platform_arch (matching_module_spec.GetArchitecture ());
179+ update_platform_arch (matching_module_spec.GetArchitecture ());
180180 } else {
181181 // Fat binary. No architecture specified, check if there is
182182 // only one platform for all of the architectures.
@@ -256,6 +256,9 @@ Status TargetList::CreateTargetInternal(Debugger &debugger,
256256 Status error;
257257 const bool is_dummy_target = false ;
258258
259+ // Global static counter for assigning unique IDs to targets
260+ static uint32_t g_target_unique_id = 0 ;
261+
259262 ArchSpec arch (specified_arch);
260263
261264 if (arch.IsValid ()) {
@@ -294,7 +297,7 @@ Status TargetList::CreateTargetInternal(Debugger &debugger,
294297
295298 if (file.IsRelative () && !user_exe_path.empty ()) {
296299 llvm::SmallString<64 > cwd;
297- if (! llvm::sys::fs::current_path (cwd)) {
300+ if (!llvm::sys::fs::current_path (cwd)) {
298301 FileSpec cwd_file (cwd.c_str ());
299302 cwd_file.AppendPathComponent (file);
300303 if (FileSystem::Instance ().Exists (cwd_file))
@@ -344,6 +347,8 @@ Status TargetList::CreateTargetInternal(Debugger &debugger,
344347 if (!target_sp)
345348 return error;
346349
350+ target_sp->m_target_unique_id = ++g_target_unique_id;
351+
347352 // Set argv0 with what the user typed, unless the user specified a
348353 // directory. If the user specified a directory, then it is probably a
349354 // bundle that was resolved and we need to use the resolved bundle path
@@ -431,8 +436,7 @@ TargetSP TargetList::FindTargetWithProcess(Process *process) const {
431436TargetSP TargetList::FindTargetWithUniqueID (uint32_t id) const {
432437 std::lock_guard<std::recursive_mutex> guard (m_target_list_mutex);
433438 auto it = llvm::find_if (m_target_list, [id](const TargetSP &item) {
434- auto *process_ptr = item->GetProcessSP ().get ();
435- return process_ptr && (process_ptr->GetUniqueID () == id);
439+ return item->GetUniqueID () == id;
436440 });
437441
438442 if (it != m_target_list.end ())
@@ -567,29 +571,27 @@ bool TargetList::AnyTargetContainsModule(Module &module) {
567571 if (target_sp->GetImages ().FindModule (&module ))
568572 return true ;
569573 }
570- for (const auto &target_sp: m_in_process_target_list) {
574+ for (const auto &target_sp : m_in_process_target_list) {
571575 if (target_sp->GetImages ().FindModule (&module ))
572576 return true ;
573577 }
574578 return false ;
575579}
576580
577- void TargetList::RegisterInProcessTarget (TargetSP target_sp) {
578- std::lock_guard<std::recursive_mutex> guard (m_target_list_mutex);
579- [[maybe_unused]] bool was_added;
580- std::tie (std::ignore, was_added) =
581- m_in_process_target_list.insert (target_sp);
582- assert (was_added && " Target pointer was left in the in-process map" );
583- }
584-
585- void TargetList::UnregisterInProcessTarget (TargetSP target_sp) {
586- std::lock_guard<std::recursive_mutex> guard (m_target_list_mutex);
587- [[maybe_unused]] bool was_present =
588- m_in_process_target_list.erase (target_sp);
589- assert (was_present && " Target pointer being removed was not registered" );
590- }
591-
592- bool TargetList::IsTargetInProcess (TargetSP target_sp) {
593- std::lock_guard<std::recursive_mutex> guard (m_target_list_mutex);
594- return m_in_process_target_list.count (target_sp) == 1 ;
595- }
581+ void TargetList::RegisterInProcessTarget (TargetSP target_sp) {
582+ std::lock_guard<std::recursive_mutex> guard (m_target_list_mutex);
583+ [[maybe_unused]] bool was_added;
584+ std::tie (std::ignore, was_added) = m_in_process_target_list.insert (target_sp);
585+ assert (was_added && " Target pointer was left in the in-process map" );
586+ }
587+
588+ void TargetList::UnregisterInProcessTarget (TargetSP target_sp) {
589+ std::lock_guard<std::recursive_mutex> guard (m_target_list_mutex);
590+ [[maybe_unused]] bool was_present = m_in_process_target_list.erase (target_sp);
591+ assert (was_present && " Target pointer being removed was not registered" );
592+ }
593+
594+ bool TargetList::IsTargetInProcess (TargetSP target_sp) {
595+ std::lock_guard<std::recursive_mutex> guard (m_target_list_mutex);
596+ return m_in_process_target_list.count (target_sp) == 1 ;
597+ }
0 commit comments