diff --git a/lldb/include/lldb/Target/Target.h b/lldb/include/lldb/Target/Target.h --- a/lldb/include/lldb/Target/Target.h +++ b/lldb/include/lldb/Target/Target.h @@ -441,6 +441,7 @@ public ModuleList::Notifier { public: friend class TargetList; + friend class Debugger; /// Broadcaster event bits definitions. enum { diff --git a/lldb/include/lldb/Target/TargetList.h b/lldb/include/lldb/Target/TargetList.h --- a/lldb/include/lldb/Target/TargetList.h +++ b/lldb/include/lldb/Target/TargetList.h @@ -183,28 +183,21 @@ typedef std::vector collection; // Member variables. collection m_target_list; - lldb::TargetSP m_dummy_target_sp; mutable std::recursive_mutex m_target_list_mutex; uint32_t m_selected_target_idx; private: - lldb::TargetSP GetDummyTarget(lldb_private::Debugger &debugger); - - Status CreateDummyTarget(Debugger &debugger, - llvm::StringRef specified_arch_name, - lldb::TargetSP &target_sp); - Status CreateTargetInternal(Debugger &debugger, llvm::StringRef user_exe_path, llvm::StringRef triple_str, LoadDependentFiles load_dependent_files, const OptionGroupPlatform *platform_options, - lldb::TargetSP &target_sp, bool is_dummy_target); + lldb::TargetSP &target_sp); Status CreateTargetInternal(Debugger &debugger, llvm::StringRef user_exe_path, const ArchSpec &arch, LoadDependentFiles get_dependent_modules, lldb::PlatformSP &platform_sp, - lldb::TargetSP &target_sp, bool is_dummy_target); + lldb::TargetSP &target_sp); TargetList(const TargetList &) = delete; const TargetList &operator=(const TargetList &) = delete; diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp --- a/lldb/source/Core/Debugger.cpp +++ b/lldb/source/Core/Debugger.cpp @@ -682,7 +682,16 @@ assert(default_platform_sp); m_platform_list.Append(default_platform_sp, true); - m_dummy_target_sp = m_target_list.GetDummyTarget(*this); + // Create the dummy target. + { + ArchSpec arch(Target::GetDefaultArchitecture()); + if (!arch.IsValid()) + arch = HostInfo::GetArchitecture(); + assert(arch.IsValid() && "No valid default or host archspec"); + const bool is_dummy_target = true; + m_dummy_target_sp.reset( + new Target(*this, arch, default_platform_sp, is_dummy_target)); + } assert(m_dummy_target_sp.get() && "Couldn't construct dummy target?"); m_collection_sp->Initialize(g_debugger_properties); diff --git a/lldb/source/Target/TargetList.cpp b/lldb/source/Target/TargetList.cpp --- a/lldb/source/Target/TargetList.cpp +++ b/lldb/source/Target/TargetList.cpp @@ -55,8 +55,8 @@ const OptionGroupPlatform *platform_options, TargetSP &target_sp) { return CreateTargetInternal(debugger, user_exe_path, triple_str, - load_dependent_files, platform_options, target_sp, - false); + load_dependent_files, platform_options, + target_sp); } Status TargetList::CreateTarget(Debugger &debugger, @@ -65,15 +65,13 @@ LoadDependentFiles load_dependent_files, PlatformSP &platform_sp, TargetSP &target_sp) { return CreateTargetInternal(debugger, user_exe_path, specified_arch, - load_dependent_files, platform_sp, target_sp, - false); + load_dependent_files, platform_sp, target_sp); } Status TargetList::CreateTargetInternal( Debugger &debugger, llvm::StringRef user_exe_path, llvm::StringRef triple_str, LoadDependentFiles load_dependent_files, - const OptionGroupPlatform *platform_options, TargetSP &target_sp, - bool is_dummy_target) { + const OptionGroupPlatform *platform_options, TargetSP &target_sp) { Status error; // Let's start by looking at the selected platform. @@ -256,7 +254,7 @@ if (!prefer_platform_arch && arch.IsValid()) { if (!platform_sp->IsCompatibleArchitecture(arch, false, nullptr)) { platform_sp = Platform::GetPlatformForArchitecture(arch, &platform_arch); - if (!is_dummy_target && platform_sp) + if (platform_sp) debugger.GetPlatformList().SetSelectedPlatform(platform_sp); } } else if (platform_arch.IsValid()) { @@ -266,7 +264,7 @@ if (!platform_sp->IsCompatibleArchitecture(platform_arch, false, nullptr)) { platform_sp = Platform::GetPlatformForArchitecture(platform_arch, &fixed_platform_arch); - if (!is_dummy_target && platform_sp) + if (platform_sp) debugger.GetPlatformList().SetSelectedPlatform(platform_sp); } } @@ -274,31 +272,9 @@ if (!platform_arch.IsValid()) platform_arch = arch; - return TargetList::CreateTargetInternal( - debugger, user_exe_path, platform_arch, load_dependent_files, platform_sp, - target_sp, is_dummy_target); -} - -lldb::TargetSP TargetList::GetDummyTarget(lldb_private::Debugger &debugger) { - // FIXME: Maybe the dummy target should be per-Debugger - if (!m_dummy_target_sp || !m_dummy_target_sp->IsValid()) { - ArchSpec arch(Target::GetDefaultArchitecture()); - if (!arch.IsValid()) - arch = HostInfo::GetArchitecture(); - Status err = CreateDummyTarget( - debugger, arch.GetTriple().getTriple().c_str(), m_dummy_target_sp); - } - - return m_dummy_target_sp; -} - -Status TargetList::CreateDummyTarget(Debugger &debugger, - llvm::StringRef specified_arch_name, - lldb::TargetSP &target_sp) { - PlatformSP host_platform_sp(Platform::GetHostPlatform()); - return CreateTargetInternal( - debugger, (const char *)nullptr, specified_arch_name, eLoadDependentsNo, - (const OptionGroupPlatform *)nullptr, target_sp, true); + return TargetList::CreateTargetInternal(debugger, user_exe_path, + platform_arch, load_dependent_files, + platform_sp, target_sp); } Status TargetList::CreateTargetInternal(Debugger &debugger, @@ -306,13 +282,13 @@ const ArchSpec &specified_arch, LoadDependentFiles load_dependent_files, lldb::PlatformSP &platform_sp, - lldb::TargetSP &target_sp, - bool is_dummy_target) { + lldb::TargetSP &target_sp) { static Timer::Category func_cat(LLVM_PRETTY_FUNCTION); Timer scoped_timer( func_cat, "TargetList::CreateTarget (file = '%s', arch = '%s')", user_exe_path.str().c_str(), specified_arch.GetArchitectureName()); Status error; + const bool is_dummy_target = false; ArchSpec arch(specified_arch); @@ -418,16 +394,11 @@ target_sp->AppendExecutableSearchPaths(file_dir); } - // Don't put the dummy target in the target list, it's held separately. - if (!is_dummy_target) { - std::lock_guard guard(m_target_list_mutex); - m_selected_target_idx = m_target_list.size(); - m_target_list.push_back(target_sp); - // Now prime this from the dummy target: - target_sp->PrimeFromDummyTarget(debugger.GetDummyTarget()); - } else { - m_dummy_target_sp = target_sp; - } + std::lock_guard guard(m_target_list_mutex); + m_selected_target_idx = m_target_list.size(); + m_target_list.push_back(target_sp); + // Now prime this from the dummy target: + target_sp->PrimeFromDummyTarget(debugger.GetDummyTarget()); return error; }