[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.
This commit is contained in:
Pavel Labath 2021-09-16 11:14:16 +02:00
parent 85f2ae57f7
commit bd590a5f89
14 changed files with 51 additions and 100 deletions

View File

@ -363,11 +363,9 @@ public:
/// platforms will want to subclass this function in order to be able to
/// intercept STDIO and possibly launch a separate process that will debug
/// the debuggee.
virtual lldb::ProcessSP
DebugProcess(ProcessLaunchInfo &launch_info, Debugger &debugger,
Target *target, // Can be nullptr, if nullptr create a new
// target, else use existing one
Status &error);
virtual lldb::ProcessSP DebugProcess(ProcessLaunchInfo &launch_info,
Debugger &debugger, Target &target,
Status &error);
virtual lldb::ProcessSP ConnectProcess(llvm::StringRef connect_url,
llvm::StringRef plugin_name,

View File

@ -1171,7 +1171,7 @@ protected:
target->GetRunArguments(m_options.launch_info.GetArguments());
ProcessSP process_sp(platform_sp->DebugProcess(
m_options.launch_info, debugger, target, error));
m_options.launch_info, debugger, *target, error));
if (process_sp && process_sp->IsAlive()) {
result.SetStatus(eReturnStatusSuccessFinishNoResult);
return true;

View File

@ -177,11 +177,10 @@ Status PlatformAppleSimulator::DisconnectRemote() {
#endif
}
lldb::ProcessSP PlatformAppleSimulator::DebugProcess(
ProcessLaunchInfo &launch_info, Debugger &debugger,
Target *target, // Can be NULL, if NULL create a new target, else use
// existing one
Status &error) {
lldb::ProcessSP
PlatformAppleSimulator::DebugProcess(ProcessLaunchInfo &launch_info,
Debugger &debugger, Target &target,
Status &error) {
#if defined(__APPLE__)
ProcessSP process_sp;
// Make sure we stop at the entry point
@ -195,7 +194,7 @@ lldb::ProcessSP PlatformAppleSimulator::DebugProcess(
if (error.Success()) {
if (launch_info.GetProcessID() != LLDB_INVALID_PROCESS_ID) {
ProcessAttachInfo attach_info(launch_info);
process_sp = Attach(attach_info, debugger, target, error);
process_sp = Attach(attach_info, debugger, &target, error);
if (process_sp) {
launch_info.SetHijackListener(attach_info.GetHijackListener());

View File

@ -60,7 +60,7 @@ public:
lldb::ProcessSP DebugProcess(lldb_private::ProcessLaunchInfo &launch_info,
lldb_private::Debugger &debugger,
lldb_private::Target *target,
lldb_private::Target &target,
lldb_private::Status &error) override;
bool GetSupportedArchitectureAtIndex(uint32_t idx,

View File

@ -1226,12 +1226,9 @@ PlatformDarwin::GetResumeCountForLaunchInfo(ProcessLaunchInfo &launch_info) {
return 1;
}
lldb::ProcessSP
PlatformDarwin::DebugProcess(ProcessLaunchInfo &launch_info, Debugger &debugger,
Target *target, // Can be NULL, if NULL create
// a new target, else use existing
// one
Status &error) {
lldb::ProcessSP PlatformDarwin::DebugProcess(ProcessLaunchInfo &launch_info,
Debugger &debugger, Target &target,
Status &error) {
ProcessSP process_sp;
if (IsHost()) {

View File

@ -71,7 +71,7 @@ public:
lldb::ProcessSP DebugProcess(lldb_private::ProcessLaunchInfo &launch_info,
lldb_private::Debugger &debugger,
lldb_private::Target *target,
lldb_private::Target &target,
lldb_private::Status &error) override;
void CalculateTrapHandlerSymbolNames() override;

View File

@ -410,13 +410,11 @@ lldb::ProcessSP PlatformPOSIX::Attach(ProcessAttachInfo &attach_info,
return process_sp;
}
lldb::ProcessSP
PlatformPOSIX::DebugProcess(ProcessLaunchInfo &launch_info, Debugger &debugger,
Target *target, // Can be NULL, if NULL create a new
// target, else use existing one
Status &error) {
lldb::ProcessSP PlatformPOSIX::DebugProcess(ProcessLaunchInfo &launch_info,
Debugger &debugger, Target &target,
Status &error) {
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM));
LLDB_LOG(log, "target {0}", target);
LLDB_LOG(log, "target {0}", &target);
ProcessSP process_sp;
@ -442,29 +440,10 @@ PlatformPOSIX::DebugProcess(ProcessLaunchInfo &launch_info, Debugger &debugger,
// worry about the target getting them as well.
launch_info.SetLaunchInSeparateProcessGroup(true);
// Ensure we have a target.
if (target == nullptr) {
LLDB_LOG(log, "creating new target");
TargetSP new_target_sp;
error = debugger.GetTargetList().CreateTarget(
debugger, "", "", eLoadDependentsNo, nullptr, new_target_sp);
if (error.Fail()) {
LLDB_LOG(log, "failed to create new target: {0}", error);
return process_sp;
}
target = new_target_sp.get();
if (!target) {
error.SetErrorString("CreateTarget() returned nullptr");
LLDB_LOG(log, "error: {0}", error);
return process_sp;
}
}
// Now create the gdb-remote process.
LLDB_LOG(log, "having target create process with gdb-remote plugin");
process_sp =
target->CreateProcess(launch_info.GetListener(), "gdb-remote", nullptr,
target.CreateProcess(launch_info.GetListener(), "gdb-remote", nullptr,
true);
if (!process_sp) {
@ -518,8 +497,8 @@ PlatformPOSIX::DebugProcess(ProcessLaunchInfo &launch_info, Debugger &debugger,
LLDB_LOG(log, "not using process STDIO pty");
} else {
LLDB_LOG(log, "{0}", error);
// FIXME figure out appropriate cleanup here. Do we delete the target? Do
// we delete the process? Does our caller do that?
// FIXME figure out appropriate cleanup here. Do we delete the process?
// Does our caller do that?
}
return process_sp;

View File

@ -47,11 +47,7 @@ public:
lldb::ProcessSP DebugProcess(lldb_private::ProcessLaunchInfo &launch_info,
lldb_private::Debugger &debugger,
lldb_private::Target *target, // Can be nullptr,
// if nullptr
// create a new
// target, else use
// existing one
lldb_private::Target &target,
lldb_private::Status &error) override;
std::string GetPlatformSpecificConnectionInformation() override;

View File

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

View File

@ -42,7 +42,7 @@ public:
lldb::ProcessSP DebugProcess(lldb_private::ProcessLaunchInfo &launch_info,
lldb_private::Debugger &debugger,
lldb_private::Target *target,
lldb_private::Target &target,
lldb_private::Status &error) override;
lldb::ProcessSP Attach(lldb_private::ProcessAttachInfo &attach_info,

View File

@ -475,11 +475,10 @@ Status PlatformRemoteGDBServer::KillProcess(const lldb::pid_t pid) {
return Status();
}
lldb::ProcessSP PlatformRemoteGDBServer::DebugProcess(
ProcessLaunchInfo &launch_info, Debugger &debugger,
Target *target, // Can be NULL, if NULL create a new target, else use
// existing one
Status &error) {
lldb::ProcessSP
PlatformRemoteGDBServer::DebugProcess(ProcessLaunchInfo &launch_info,
Debugger &debugger, Target &target,
Status &error) {
lldb::ProcessSP process_sp;
if (IsRemote()) {
if (IsConnected()) {
@ -489,32 +488,21 @@ lldb::ProcessSP PlatformRemoteGDBServer::DebugProcess(
error.SetErrorStringWithFormat("unable to launch a GDB server on '%s'",
GetHostname());
} else {
if (target == nullptr) {
TargetSP new_target_sp;
// The darwin always currently uses the GDB remote debugger plug-in
// so even when debugging locally we are debugging remotely!
process_sp = target.CreateProcess(launch_info.GetListener(),
"gdb-remote", nullptr, true);
error = debugger.GetTargetList().CreateTarget(
debugger, "", "", eLoadDependentsNo, nullptr, new_target_sp);
target = new_target_sp.get();
} else
error.Clear();
if (target && error.Success()) {
// The darwin always currently uses the GDB remote debugger plug-in
// so even when debugging locally we are debugging remotely!
process_sp = target->CreateProcess(launch_info.GetListener(),
"gdb-remote", nullptr, true);
if (process_sp) {
if (process_sp) {
error = process_sp->ConnectRemote(connect_url.c_str());
// Retry the connect remote one time...
if (error.Fail())
error = process_sp->ConnectRemote(connect_url.c_str());
// Retry the connect remote one time...
if (error.Fail())
error = process_sp->ConnectRemote(connect_url.c_str());
if (error.Success())
error = process_sp->Launch(launch_info);
else if (debugserver_pid != LLDB_INVALID_PROCESS_ID) {
printf("error: connect remote failed (%s)\n", error.AsCString());
KillSpawnedProcess(debugserver_pid);
}
if (error.Success())
error = process_sp->Launch(launch_info);
else if (debugserver_pid != LLDB_INVALID_PROCESS_ID) {
printf("error: connect remote failed (%s)\n", error.AsCString());
KillSpawnedProcess(debugserver_pid);
}
}
}

View File

@ -62,10 +62,7 @@ public:
Status KillProcess(const lldb::pid_t pid) override;
lldb::ProcessSP DebugProcess(ProcessLaunchInfo &launch_info,
Debugger &debugger,
Target *target, // Can be NULL, if NULL create a
// new target, else use existing
// one
Debugger &debugger, Target &target,
Status &error) override;
lldb::ProcessSP Attach(ProcessAttachInfo &attach_info, Debugger &debugger,

View File

@ -1088,14 +1088,11 @@ Status Platform::KillProcess(const lldb::pid_t pid) {
return Status();
}
lldb::ProcessSP
Platform::DebugProcess(ProcessLaunchInfo &launch_info, Debugger &debugger,
Target *target, // Can be nullptr, if nullptr create a
// new target, else use existing one
Status &error) {
lldb::ProcessSP Platform::DebugProcess(ProcessLaunchInfo &launch_info,
Debugger &debugger, Target &target,
Status &error) {
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM));
LLDB_LOGF(log, "Platform::%s entered (target %p)", __FUNCTION__,
static_cast<void *>(target));
LLDB_LOG(log, "target = {0})", &target);
ProcessSP process_sp;
// Make sure we stop at the entry point
@ -1117,7 +1114,7 @@ Platform::DebugProcess(ProcessLaunchInfo &launch_info, Debugger &debugger,
filter_callback = get_filter_func(++i, iteration_complete)) {
if (filter_callback) {
// Give this ProcessLaunchInfo filter a chance to adjust the launch info.
error = (*filter_callback)(launch_info, target);
error = (*filter_callback)(launch_info, &target);
if (!error.Success()) {
LLDB_LOGF(log,
"Platform::%s() StructuredDataPlugin launch "
@ -1135,7 +1132,7 @@ Platform::DebugProcess(ProcessLaunchInfo &launch_info, Debugger &debugger,
__FUNCTION__, launch_info.GetProcessID());
if (launch_info.GetProcessID() != LLDB_INVALID_PROCESS_ID) {
ProcessAttachInfo attach_info(launch_info);
process_sp = Attach(attach_info, debugger, target, error);
process_sp = Attach(attach_info, debugger, &target, error);
if (process_sp) {
LLDB_LOGF(log, "Platform::%s Attach() succeeded, Process plugin: %s",
__FUNCTION__, process_sp->GetPluginName().AsCString());

View File

@ -2993,7 +2993,7 @@ Status Target::Launch(ProcessLaunchInfo &launch_info, Stream *stream) {
DeleteCurrentProcess();
m_process_sp =
GetPlatform()->DebugProcess(launch_info, debugger, this, error);
GetPlatform()->DebugProcess(launch_info, debugger, *this, error);
} else {
LLDB_LOGF(log,