Skip to content

Commit bd590a5

Browse files
committed
[lldb] Make Platform::DebugProcess take a Target reference
instead of a pointer. There are just two callers of this function, and both of them have a valid target pointer, so there's no need for all implementations to concern themselves with whether the pointer is null.
1 parent 85f2ae5 commit bd590a5

File tree

14 files changed

+52
-101
lines changed

14 files changed

+52
-101
lines changed

lldb/include/lldb/Target/Platform.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -363,11 +363,9 @@ class Platform : public PluginInterface {
363363
/// platforms will want to subclass this function in order to be able to
364364
/// intercept STDIO and possibly launch a separate process that will debug
365365
/// the debuggee.
366-
virtual lldb::ProcessSP
367-
DebugProcess(ProcessLaunchInfo &launch_info, Debugger &debugger,
368-
Target *target, // Can be nullptr, if nullptr create a new
369-
// target, else use existing one
370-
Status &error);
366+
virtual lldb::ProcessSP DebugProcess(ProcessLaunchInfo &launch_info,
367+
Debugger &debugger, Target &target,
368+
Status &error);
371369

372370
virtual lldb::ProcessSP ConnectProcess(llvm::StringRef connect_url,
373371
llvm::StringRef plugin_name,

lldb/source/Commands/CommandObjectPlatform.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,7 @@ class CommandObjectPlatformProcessLaunch : public CommandObjectParsed {
11711171
target->GetRunArguments(m_options.launch_info.GetArguments());
11721172

11731173
ProcessSP process_sp(platform_sp->DebugProcess(
1174-
m_options.launch_info, debugger, target, error));
1174+
m_options.launch_info, debugger, *target, error));
11751175
if (process_sp && process_sp->IsAlive()) {
11761176
result.SetStatus(eReturnStatusSuccessFinishNoResult);
11771177
return true;

lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,10 @@ Status PlatformAppleSimulator::DisconnectRemote() {
177177
#endif
178178
}
179179

180-
lldb::ProcessSP PlatformAppleSimulator::DebugProcess(
181-
ProcessLaunchInfo &launch_info, Debugger &debugger,
182-
Target *target, // Can be NULL, if NULL create a new target, else use
183-
// existing one
184-
Status &error) {
180+
lldb::ProcessSP
181+
PlatformAppleSimulator::DebugProcess(ProcessLaunchInfo &launch_info,
182+
Debugger &debugger, Target &target,
183+
Status &error) {
185184
#if defined(__APPLE__)
186185
ProcessSP process_sp;
187186
// Make sure we stop at the entry point
@@ -195,7 +194,7 @@ lldb::ProcessSP PlatformAppleSimulator::DebugProcess(
195194
if (error.Success()) {
196195
if (launch_info.GetProcessID() != LLDB_INVALID_PROCESS_ID) {
197196
ProcessAttachInfo attach_info(launch_info);
198-
process_sp = Attach(attach_info, debugger, target, error);
197+
process_sp = Attach(attach_info, debugger, &target, error);
199198
if (process_sp) {
200199
launch_info.SetHijackListener(attach_info.GetHijackListener());
201200

lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class PlatformAppleSimulator : public PlatformDarwin {
6060

6161
lldb::ProcessSP DebugProcess(lldb_private::ProcessLaunchInfo &launch_info,
6262
lldb_private::Debugger &debugger,
63-
lldb_private::Target *target,
63+
lldb_private::Target &target,
6464
lldb_private::Status &error) override;
6565

6666
bool GetSupportedArchitectureAtIndex(uint32_t idx,

lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,12 +1226,9 @@ PlatformDarwin::GetResumeCountForLaunchInfo(ProcessLaunchInfo &launch_info) {
12261226
return 1;
12271227
}
12281228

1229-
lldb::ProcessSP
1230-
PlatformDarwin::DebugProcess(ProcessLaunchInfo &launch_info, Debugger &debugger,
1231-
Target *target, // Can be NULL, if NULL create
1232-
// a new target, else use existing
1233-
// one
1234-
Status &error) {
1229+
lldb::ProcessSP PlatformDarwin::DebugProcess(ProcessLaunchInfo &launch_info,
1230+
Debugger &debugger, Target &target,
1231+
Status &error) {
12351232
ProcessSP process_sp;
12361233

12371234
if (IsHost()) {

lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class PlatformDarwin : public PlatformPOSIX {
7171

7272
lldb::ProcessSP DebugProcess(lldb_private::ProcessLaunchInfo &launch_info,
7373
lldb_private::Debugger &debugger,
74-
lldb_private::Target *target,
74+
lldb_private::Target &target,
7575
lldb_private::Status &error) override;
7676

7777
void CalculateTrapHandlerSymbolNames() override;

lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -410,13 +410,11 @@ lldb::ProcessSP PlatformPOSIX::Attach(ProcessAttachInfo &attach_info,
410410
return process_sp;
411411
}
412412

413-
lldb::ProcessSP
414-
PlatformPOSIX::DebugProcess(ProcessLaunchInfo &launch_info, Debugger &debugger,
415-
Target *target, // Can be NULL, if NULL create a new
416-
// target, else use existing one
417-
Status &error) {
413+
lldb::ProcessSP PlatformPOSIX::DebugProcess(ProcessLaunchInfo &launch_info,
414+
Debugger &debugger, Target &target,
415+
Status &error) {
418416
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM));
419-
LLDB_LOG(log, "target {0}", target);
417+
LLDB_LOG(log, "target {0}", &target);
420418

421419
ProcessSP process_sp;
422420

@@ -442,29 +440,10 @@ PlatformPOSIX::DebugProcess(ProcessLaunchInfo &launch_info, Debugger &debugger,
442440
// worry about the target getting them as well.
443441
launch_info.SetLaunchInSeparateProcessGroup(true);
444442

445-
// Ensure we have a target.
446-
if (target == nullptr) {
447-
LLDB_LOG(log, "creating new target");
448-
TargetSP new_target_sp;
449-
error = debugger.GetTargetList().CreateTarget(
450-
debugger, "", "", eLoadDependentsNo, nullptr, new_target_sp);
451-
if (error.Fail()) {
452-
LLDB_LOG(log, "failed to create new target: {0}", error);
453-
return process_sp;
454-
}
455-
456-
target = new_target_sp.get();
457-
if (!target) {
458-
error.SetErrorString("CreateTarget() returned nullptr");
459-
LLDB_LOG(log, "error: {0}", error);
460-
return process_sp;
461-
}
462-
}
463-
464443
// Now create the gdb-remote process.
465444
LLDB_LOG(log, "having target create process with gdb-remote plugin");
466445
process_sp =
467-
target->CreateProcess(launch_info.GetListener(), "gdb-remote", nullptr,
446+
target.CreateProcess(launch_info.GetListener(), "gdb-remote", nullptr,
468447
true);
469448

470449
if (!process_sp) {
@@ -518,8 +497,8 @@ PlatformPOSIX::DebugProcess(ProcessLaunchInfo &launch_info, Debugger &debugger,
518497
LLDB_LOG(log, "not using process STDIO pty");
519498
} else {
520499
LLDB_LOG(log, "{0}", error);
521-
// FIXME figure out appropriate cleanup here. Do we delete the target? Do
522-
// we delete the process? Does our caller do that?
500+
// FIXME figure out appropriate cleanup here. Do we delete the process?
501+
// Does our caller do that?
523502
}
524503

525504
return process_sp;

lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,7 @@ class PlatformPOSIX : public lldb_private::RemoteAwarePlatform {
4747

4848
lldb::ProcessSP DebugProcess(lldb_private::ProcessLaunchInfo &launch_info,
4949
lldb_private::Debugger &debugger,
50-
lldb_private::Target *target, // Can be nullptr,
51-
// if nullptr
52-
// create a new
53-
// target, else use
54-
// existing one
50+
lldb_private::Target &target,
5551
lldb_private::Status &error) override;
5652

5753
std::string GetPlatformSpecificConnectionInformation() override;

lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ Status PlatformWindows::DisconnectRemote() {
198198
}
199199

200200
ProcessSP PlatformWindows::DebugProcess(ProcessLaunchInfo &launch_info,
201-
Debugger &debugger, Target *target,
201+
Debugger &debugger, Target &target,
202202
Status &error) {
203203
// Windows has special considerations that must be followed when launching or
204204
// attaching to a process. The key requirement is that when launching or
@@ -230,9 +230,9 @@ ProcessSP PlatformWindows::DebugProcess(ProcessLaunchInfo &launch_info,
230230
if (launch_info.GetProcessID() != LLDB_INVALID_PROCESS_ID) {
231231
// This is a process attach. Don't need to launch anything.
232232
ProcessAttachInfo attach_info(launch_info);
233-
return Attach(attach_info, debugger, target, error);
233+
return Attach(attach_info, debugger, &target, error);
234234
} else {
235-
ProcessSP process_sp = target->CreateProcess(
235+
ProcessSP process_sp = target.CreateProcess(
236236
launch_info.GetListener(), launch_info.GetProcessPluginName(), nullptr,
237237
false);
238238

lldb/source/Plugins/Platform/Windows/PlatformWindows.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class PlatformWindows : public RemoteAwarePlatform {
4242

4343
lldb::ProcessSP DebugProcess(lldb_private::ProcessLaunchInfo &launch_info,
4444
lldb_private::Debugger &debugger,
45-
lldb_private::Target *target,
45+
lldb_private::Target &target,
4646
lldb_private::Status &error) override;
4747

4848
lldb::ProcessSP Attach(lldb_private::ProcessAttachInfo &attach_info,

lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -475,11 +475,10 @@ Status PlatformRemoteGDBServer::KillProcess(const lldb::pid_t pid) {
475475
return Status();
476476
}
477477

478-
lldb::ProcessSP PlatformRemoteGDBServer::DebugProcess(
479-
ProcessLaunchInfo &launch_info, Debugger &debugger,
480-
Target *target, // Can be NULL, if NULL create a new target, else use
481-
// existing one
482-
Status &error) {
478+
lldb::ProcessSP
479+
PlatformRemoteGDBServer::DebugProcess(ProcessLaunchInfo &launch_info,
480+
Debugger &debugger, Target &target,
481+
Status &error) {
483482
lldb::ProcessSP process_sp;
484483
if (IsRemote()) {
485484
if (IsConnected()) {
@@ -489,32 +488,21 @@ lldb::ProcessSP PlatformRemoteGDBServer::DebugProcess(
489488
error.SetErrorStringWithFormat("unable to launch a GDB server on '%s'",
490489
GetHostname());
491490
} else {
492-
if (target == nullptr) {
493-
TargetSP new_target_sp;
494-
495-
error = debugger.GetTargetList().CreateTarget(
496-
debugger, "", "", eLoadDependentsNo, nullptr, new_target_sp);
497-
target = new_target_sp.get();
498-
} else
499-
error.Clear();
500-
501-
if (target && error.Success()) {
502-
// The darwin always currently uses the GDB remote debugger plug-in
503-
// so even when debugging locally we are debugging remotely!
504-
process_sp = target->CreateProcess(launch_info.GetListener(),
505-
"gdb-remote", nullptr, true);
506-
507-
if (process_sp) {
491+
// The darwin always currently uses the GDB remote debugger plug-in
492+
// so even when debugging locally we are debugging remotely!
493+
process_sp = target.CreateProcess(launch_info.GetListener(),
494+
"gdb-remote", nullptr, true);
495+
496+
if (process_sp) {
497+
error = process_sp->ConnectRemote(connect_url.c_str());
498+
// Retry the connect remote one time...
499+
if (error.Fail())
508500
error = process_sp->ConnectRemote(connect_url.c_str());
509-
// Retry the connect remote one time...
510-
if (error.Fail())
511-
error = process_sp->ConnectRemote(connect_url.c_str());
512-
if (error.Success())
513-
error = process_sp->Launch(launch_info);
514-
else if (debugserver_pid != LLDB_INVALID_PROCESS_ID) {
515-
printf("error: connect remote failed (%s)\n", error.AsCString());
516-
KillSpawnedProcess(debugserver_pid);
517-
}
501+
if (error.Success())
502+
error = process_sp->Launch(launch_info);
503+
else if (debugserver_pid != LLDB_INVALID_PROCESS_ID) {
504+
printf("error: connect remote failed (%s)\n", error.AsCString());
505+
KillSpawnedProcess(debugserver_pid);
518506
}
519507
}
520508
}

lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,7 @@ class PlatformRemoteGDBServer : public Platform, private UserIDResolver {
6262
Status KillProcess(const lldb::pid_t pid) override;
6363

6464
lldb::ProcessSP DebugProcess(ProcessLaunchInfo &launch_info,
65-
Debugger &debugger,
66-
Target *target, // Can be NULL, if NULL create a
67-
// new target, else use existing
68-
// one
65+
Debugger &debugger, Target &target,
6966
Status &error) override;
7067

7168
lldb::ProcessSP Attach(ProcessAttachInfo &attach_info, Debugger &debugger,

lldb/source/Target/Platform.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,14 +1088,11 @@ Status Platform::KillProcess(const lldb::pid_t pid) {
10881088
return Status();
10891089
}
10901090

1091-
lldb::ProcessSP
1092-
Platform::DebugProcess(ProcessLaunchInfo &launch_info, Debugger &debugger,
1093-
Target *target, // Can be nullptr, if nullptr create a
1094-
// new target, else use existing one
1095-
Status &error) {
1091+
lldb::ProcessSP Platform::DebugProcess(ProcessLaunchInfo &launch_info,
1092+
Debugger &debugger, Target &target,
1093+
Status &error) {
10961094
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM));
1097-
LLDB_LOGF(log, "Platform::%s entered (target %p)", __FUNCTION__,
1098-
static_cast<void *>(target));
1095+
LLDB_LOG(log, "target = {0})", &target);
10991096

11001097
ProcessSP process_sp;
11011098
// Make sure we stop at the entry point
@@ -1117,7 +1114,7 @@ Platform::DebugProcess(ProcessLaunchInfo &launch_info, Debugger &debugger,
11171114
filter_callback = get_filter_func(++i, iteration_complete)) {
11181115
if (filter_callback) {
11191116
// Give this ProcessLaunchInfo filter a chance to adjust the launch info.
1120-
error = (*filter_callback)(launch_info, target);
1117+
error = (*filter_callback)(launch_info, &target);
11211118
if (!error.Success()) {
11221119
LLDB_LOGF(log,
11231120
"Platform::%s() StructuredDataPlugin launch "
@@ -1135,7 +1132,7 @@ Platform::DebugProcess(ProcessLaunchInfo &launch_info, Debugger &debugger,
11351132
__FUNCTION__, launch_info.GetProcessID());
11361133
if (launch_info.GetProcessID() != LLDB_INVALID_PROCESS_ID) {
11371134
ProcessAttachInfo attach_info(launch_info);
1138-
process_sp = Attach(attach_info, debugger, target, error);
1135+
process_sp = Attach(attach_info, debugger, &target, error);
11391136
if (process_sp) {
11401137
LLDB_LOGF(log, "Platform::%s Attach() succeeded, Process plugin: %s",
11411138
__FUNCTION__, process_sp->GetPluginName().AsCString());

lldb/source/Target/Target.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2993,7 +2993,7 @@ Status Target::Launch(ProcessLaunchInfo &launch_info, Stream *stream) {
29932993
DeleteCurrentProcess();
29942994

29952995
m_process_sp =
2996-
GetPlatform()->DebugProcess(launch_info, debugger, this, error);
2996+
GetPlatform()->DebugProcess(launch_info, debugger, *this, error);
29972997

29982998
} else {
29992999
LLDB_LOGF(log,

0 commit comments

Comments
 (0)