Skip to content

Commit 33ddbb9

Browse files
committed
[TargetList] Simplify dummy target creation
Factor out dummy target creation from CreateTargetInternal. This makes it impossible for dummy target creation to accidentally fail due to too-strict checking in one of the CreateTargetInternal overloads. Testing: check-lldb rdar://70630655 Differential Revision: https://reviews.llvm.org/D90872 (cherry picked from commit 16e5a34)
1 parent 7ef283a commit 33ddbb9

File tree

4 files changed

+29
-55
lines changed

4 files changed

+29
-55
lines changed

lldb/include/lldb/Target/Target.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ class Target : public std::enable_shared_from_this<Target>,
440440
public ModuleList::Notifier {
441441
public:
442442
friend class TargetList;
443+
friend class Debugger;
443444

444445
/// Broadcaster event bits definitions.
445446
enum {

lldb/include/lldb/Target/TargetList.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -183,28 +183,21 @@ class TargetList : public Broadcaster {
183183
typedef std::vector<lldb::TargetSP> collection;
184184
// Member variables.
185185
collection m_target_list;
186-
lldb::TargetSP m_dummy_target_sp;
187186
mutable std::recursive_mutex m_target_list_mutex;
188187
uint32_t m_selected_target_idx;
189188

190189
private:
191-
lldb::TargetSP GetDummyTarget(lldb_private::Debugger &debugger);
192-
193-
Status CreateDummyTarget(Debugger &debugger,
194-
llvm::StringRef specified_arch_name,
195-
lldb::TargetSP &target_sp);
196-
197190
Status CreateTargetInternal(Debugger &debugger, llvm::StringRef user_exe_path,
198191
llvm::StringRef triple_str,
199192
LoadDependentFiles load_dependent_files,
200193
const OptionGroupPlatform *platform_options,
201-
lldb::TargetSP &target_sp, bool is_dummy_target);
194+
lldb::TargetSP &target_sp);
202195

203196
Status CreateTargetInternal(Debugger &debugger, llvm::StringRef user_exe_path,
204197
const ArchSpec &arch,
205198
LoadDependentFiles get_dependent_modules,
206199
lldb::PlatformSP &platform_sp,
207-
lldb::TargetSP &target_sp, bool is_dummy_target);
200+
lldb::TargetSP &target_sp);
208201

209202
TargetList(const TargetList &) = delete;
210203
const TargetList &operator=(const TargetList &) = delete;

lldb/source/Core/Debugger.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,16 @@ Debugger::Debugger(lldb::LogOutputCallback log_callback, void *baton)
678678
assert(default_platform_sp);
679679
m_platform_list.Append(default_platform_sp, true);
680680

681-
m_dummy_target_sp = m_target_list.GetDummyTarget(*this);
681+
// Create the dummy target.
682+
{
683+
ArchSpec arch(Target::GetDefaultArchitecture());
684+
if (!arch.IsValid())
685+
arch = HostInfo::GetArchitecture();
686+
assert(arch.IsValid() && "No valid default or host archspec");
687+
const bool is_dummy_target = true;
688+
m_dummy_target_sp.reset(
689+
new Target(*this, arch, default_platform_sp, is_dummy_target));
690+
}
682691
assert(m_dummy_target_sp.get() && "Couldn't construct dummy target?");
683692

684693
m_collection_sp->Initialize(g_debugger_properties);

lldb/source/Target/TargetList.cpp

Lines changed: 16 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ Status TargetList::CreateTarget(Debugger &debugger,
5555
const OptionGroupPlatform *platform_options,
5656
TargetSP &target_sp) {
5757
return CreateTargetInternal(debugger, user_exe_path, triple_str,
58-
load_dependent_files, platform_options, target_sp,
59-
false);
58+
load_dependent_files, platform_options,
59+
target_sp);
6060
}
6161

6262
Status TargetList::CreateTarget(Debugger &debugger,
@@ -65,15 +65,13 @@ Status TargetList::CreateTarget(Debugger &debugger,
6565
LoadDependentFiles load_dependent_files,
6666
PlatformSP &platform_sp, TargetSP &target_sp) {
6767
return CreateTargetInternal(debugger, user_exe_path, specified_arch,
68-
load_dependent_files, platform_sp, target_sp,
69-
false);
68+
load_dependent_files, platform_sp, target_sp);
7069
}
7170

7271
Status TargetList::CreateTargetInternal(
7372
Debugger &debugger, llvm::StringRef user_exe_path,
7473
llvm::StringRef triple_str, LoadDependentFiles load_dependent_files,
75-
const OptionGroupPlatform *platform_options, TargetSP &target_sp,
76-
bool is_dummy_target) {
74+
const OptionGroupPlatform *platform_options, TargetSP &target_sp) {
7775
Status error;
7876

7977
// Let's start by looking at the selected platform.
@@ -256,7 +254,7 @@ Status TargetList::CreateTargetInternal(
256254
if (!prefer_platform_arch && arch.IsValid()) {
257255
if (!platform_sp->IsCompatibleArchitecture(arch, false, nullptr)) {
258256
platform_sp = Platform::GetPlatformForArchitecture(arch, &platform_arch);
259-
if (!is_dummy_target && platform_sp)
257+
if (platform_sp)
260258
debugger.GetPlatformList().SetSelectedPlatform(platform_sp);
261259
}
262260
} else if (platform_arch.IsValid()) {
@@ -266,53 +264,31 @@ Status TargetList::CreateTargetInternal(
266264
if (!platform_sp->IsCompatibleArchitecture(platform_arch, false, nullptr)) {
267265
platform_sp = Platform::GetPlatformForArchitecture(platform_arch,
268266
&fixed_platform_arch);
269-
if (!is_dummy_target && platform_sp)
267+
if (platform_sp)
270268
debugger.GetPlatformList().SetSelectedPlatform(platform_sp);
271269
}
272270
}
273271

274272
if (!platform_arch.IsValid())
275273
platform_arch = arch;
276274

277-
return TargetList::CreateTargetInternal(
278-
debugger, user_exe_path, platform_arch, load_dependent_files, platform_sp,
279-
target_sp, is_dummy_target);
280-
}
281-
282-
lldb::TargetSP TargetList::GetDummyTarget(lldb_private::Debugger &debugger) {
283-
// FIXME: Maybe the dummy target should be per-Debugger
284-
if (!m_dummy_target_sp || !m_dummy_target_sp->IsValid()) {
285-
ArchSpec arch(Target::GetDefaultArchitecture());
286-
if (!arch.IsValid())
287-
arch = HostInfo::GetArchitecture();
288-
Status err = CreateDummyTarget(
289-
debugger, arch.GetTriple().getTriple().c_str(), m_dummy_target_sp);
290-
}
291-
292-
return m_dummy_target_sp;
293-
}
294-
295-
Status TargetList::CreateDummyTarget(Debugger &debugger,
296-
llvm::StringRef specified_arch_name,
297-
lldb::TargetSP &target_sp) {
298-
PlatformSP host_platform_sp(Platform::GetHostPlatform());
299-
return CreateTargetInternal(
300-
debugger, (const char *)nullptr, specified_arch_name, eLoadDependentsNo,
301-
(const OptionGroupPlatform *)nullptr, target_sp, true);
275+
return TargetList::CreateTargetInternal(debugger, user_exe_path,
276+
platform_arch, load_dependent_files,
277+
platform_sp, target_sp);
302278
}
303279

304280
Status TargetList::CreateTargetInternal(Debugger &debugger,
305281
llvm::StringRef user_exe_path,
306282
const ArchSpec &specified_arch,
307283
LoadDependentFiles load_dependent_files,
308284
lldb::PlatformSP &platform_sp,
309-
lldb::TargetSP &target_sp,
310-
bool is_dummy_target) {
285+
lldb::TargetSP &target_sp) {
311286
static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
312287
Timer scoped_timer(
313288
func_cat, "TargetList::CreateTarget (file = '%s', arch = '%s')",
314289
user_exe_path.str().c_str(), specified_arch.GetArchitectureName());
315290
Status error;
291+
const bool is_dummy_target = false;
316292

317293
ArchSpec arch(specified_arch);
318294

@@ -418,16 +394,11 @@ Status TargetList::CreateTargetInternal(Debugger &debugger,
418394
target_sp->AppendExecutableSearchPaths(file_dir);
419395
}
420396

421-
// Don't put the dummy target in the target list, it's held separately.
422-
if (!is_dummy_target) {
423-
std::lock_guard<std::recursive_mutex> guard(m_target_list_mutex);
424-
m_selected_target_idx = m_target_list.size();
425-
m_target_list.push_back(target_sp);
426-
// Now prime this from the dummy target:
427-
target_sp->PrimeFromDummyTarget(debugger.GetDummyTarget());
428-
} else {
429-
m_dummy_target_sp = target_sp;
430-
}
397+
std::lock_guard<std::recursive_mutex> guard(m_target_list_mutex);
398+
m_selected_target_idx = m_target_list.size();
399+
m_target_list.push_back(target_sp);
400+
// Now prime this from the dummy target:
401+
target_sp->PrimeFromDummyTarget(debugger.GetDummyTarget());
431402

432403
return error;
433404
}

0 commit comments

Comments
 (0)