Skip to content

Commit

Permalink
Revert "Make it possible for lldb to launch a remote binary with no l…
Browse files Browse the repository at this point in the history
…ocal file."

The reworking of the gdb client tests into the PlatformClientTestBase broke
the test for this.  I did the mutatis mutandis for the move, but the test
still fails.  Reverting till I have time to figure out why.

This reverts commit b715b79.
  • Loading branch information
jimingham committed Nov 17, 2021
1 parent 47f76bb commit dd5505a
Show file tree
Hide file tree
Showing 4 changed files with 220 additions and 325 deletions.
40 changes: 10 additions & 30 deletions lldb/source/Commands/CommandObjectProcess.cpp
Expand Up @@ -159,12 +159,7 @@ class CommandObjectProcessLaunch : public CommandObjectProcessLaunchOrAttach {
// If our listener is nullptr, users aren't allows to launch
ModuleSP exe_module_sp = target->GetExecutableModule();

// If the target already has an executable module, then use that. If it
// doesn't then someone must be trying to launch using a path that will
// make sense to the remote stub, but doesn't exist on the local host.
// In that case use the ExecutableFile that was set in the target's
// ProcessLaunchInfo.
if (exe_module_sp == nullptr && !target->GetProcessLaunchInfo().GetExecutableFile()) {
if (exe_module_sp == nullptr) {
result.AppendError("no file in target, create a debug target using the "
"'target create' command");
return false;
Expand Down Expand Up @@ -224,17 +219,11 @@ class CommandObjectProcessLaunch : public CommandObjectProcessLaunchOrAttach {
if (!target_settings_argv0.empty()) {
m_options.launch_info.GetArguments().AppendArgument(
target_settings_argv0);
if (exe_module_sp)
m_options.launch_info.SetExecutableFile(
exe_module_sp->GetPlatformFileSpec(), false);
else
m_options.launch_info.SetExecutableFile(target->GetProcessLaunchInfo().GetExecutableFile(), false);
m_options.launch_info.SetExecutableFile(
exe_module_sp->GetPlatformFileSpec(), false);
} else {
if (exe_module_sp)
m_options.launch_info.SetExecutableFile(
exe_module_sp->GetPlatformFileSpec(), true);
else
m_options.launch_info.SetExecutableFile(target->GetProcessLaunchInfo().GetExecutableFile(), true);
m_options.launch_info.SetExecutableFile(
exe_module_sp->GetPlatformFileSpec(), true);
}

if (launch_args.GetArgumentCount() == 0) {
Expand All @@ -261,20 +250,11 @@ class CommandObjectProcessLaunch : public CommandObjectProcessLaunchOrAttach {
llvm::StringRef data = stream.GetString();
if (!data.empty())
result.AppendMessage(data);
// If we didn't have a local executable, then we wouldn't have had an
// executable module before launch.
if (!exe_module_sp)
exe_module_sp = target->GetExecutableModule();
if (!exe_module_sp) {
result.AppendWarning("Could not get executable module after launch.");
} else {

const char *archname =
exe_module_sp->GetArchitecture().GetArchitectureName();
result.AppendMessageWithFormat(
"Process %" PRIu64 " launched: '%s' (%s)\n", process_sp->GetID(),
exe_module_sp->GetFileSpec().GetPath().c_str(), archname);
}
const char *archname =
exe_module_sp->GetArchitecture().GetArchitectureName();
result.AppendMessageWithFormat(
"Process %" PRIu64 " launched: '%s' (%s)\n", process_sp->GetID(),
exe_module_sp->GetFileSpec().GetPath().c_str(), archname);
result.SetStatus(eReturnStatusSuccessFinishResult);
result.SetDidChangeProcessState(true);
} else {
Expand Down
224 changes: 117 additions & 107 deletions lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
Expand Up @@ -677,133 +677,143 @@ Status ProcessGDBRemote::DoLaunch(lldb_private::Module *exe_module,
// LLDB_LOG_OPTION_PREPEND_PROC_AND_THREAD);
// ::LogSetLogFile ("/dev/stdout");

error = EstablishConnectionIfNeeded(launch_info);
if (error.Success()) {
PseudoTerminal pty;
const bool disable_stdio = (launch_flags & eLaunchFlagDisableSTDIO) != 0;

PlatformSP platform_sp(GetTarget().GetPlatform());
if (disable_stdio) {
// set to /dev/null unless redirected to a file above
if (!stdin_file_spec)
stdin_file_spec.SetFile(FileSystem::DEV_NULL,
FileSpec::Style::native);
if (!stdout_file_spec)
stdout_file_spec.SetFile(FileSystem::DEV_NULL,
FileSpec::Style::native);
if (!stderr_file_spec)
stderr_file_spec.SetFile(FileSystem::DEV_NULL,
FileSpec::Style::native);
} else if (platform_sp && platform_sp->IsHost()) {
// If the debugserver is local and we aren't disabling STDIO, lets use
// a pseudo terminal to instead of relying on the 'O' packets for stdio
// since 'O' packets can really slow down debugging if the inferior
// does a lot of output.
if ((!stdin_file_spec || !stdout_file_spec || !stderr_file_spec) &&
!errorToBool(pty.OpenFirstAvailablePrimary(O_RDWR | O_NOCTTY))) {
FileSpec secondary_name(pty.GetSecondaryName());
ObjectFile *object_file = exe_module->GetObjectFile();
if (object_file) {
error = EstablishConnectionIfNeeded(launch_info);
if (error.Success()) {
PseudoTerminal pty;
const bool disable_stdio = (launch_flags & eLaunchFlagDisableSTDIO) != 0;

PlatformSP platform_sp(GetTarget().GetPlatform());
if (disable_stdio) {
// set to /dev/null unless redirected to a file above
if (!stdin_file_spec)
stdin_file_spec = secondary_name;

stdin_file_spec.SetFile(FileSystem::DEV_NULL,
FileSpec::Style::native);
if (!stdout_file_spec)
stdout_file_spec = secondary_name;

stdout_file_spec.SetFile(FileSystem::DEV_NULL,
FileSpec::Style::native);
if (!stderr_file_spec)
stderr_file_spec = secondary_name;
stderr_file_spec.SetFile(FileSystem::DEV_NULL,
FileSpec::Style::native);
} else if (platform_sp && platform_sp->IsHost()) {
// If the debugserver is local and we aren't disabling STDIO, lets use
// a pseudo terminal to instead of relying on the 'O' packets for stdio
// since 'O' packets can really slow down debugging if the inferior
// does a lot of output.
if ((!stdin_file_spec || !stdout_file_spec || !stderr_file_spec) &&
!errorToBool(pty.OpenFirstAvailablePrimary(O_RDWR | O_NOCTTY))) {
FileSpec secondary_name(pty.GetSecondaryName());

if (!stdin_file_spec)
stdin_file_spec = secondary_name;

if (!stdout_file_spec)
stdout_file_spec = secondary_name;

if (!stderr_file_spec)
stderr_file_spec = secondary_name;
}
LLDB_LOGF(
log,
"ProcessGDBRemote::%s adjusted STDIO paths for local platform "
"(IsHost() is true) using secondary: stdin=%s, stdout=%s, "
"stderr=%s",
__FUNCTION__,
stdin_file_spec ? stdin_file_spec.GetCString() : "<null>",
stdout_file_spec ? stdout_file_spec.GetCString() : "<null>",
stderr_file_spec ? stderr_file_spec.GetCString() : "<null>");
}
LLDB_LOGF(
log,
"ProcessGDBRemote::%s adjusted STDIO paths for local platform "
"(IsHost() is true) using secondary: stdin=%s, stdout=%s, "
"stderr=%s",
__FUNCTION__,
stdin_file_spec ? stdin_file_spec.GetCString() : "<null>",
stdout_file_spec ? stdout_file_spec.GetCString() : "<null>",
stderr_file_spec ? stderr_file_spec.GetCString() : "<null>");
}

LLDB_LOGF(log,
"ProcessGDBRemote::%s final STDIO paths after all "
"adjustments: stdin=%s, stdout=%s, stderr=%s",
__FUNCTION__,
stdin_file_spec ? stdin_file_spec.GetCString() : "<null>",
stdout_file_spec ? stdout_file_spec.GetCString() : "<null>",
stderr_file_spec ? stderr_file_spec.GetCString() : "<null>");

if (stdin_file_spec)
m_gdb_comm.SetSTDIN(stdin_file_spec);
if (stdout_file_spec)
m_gdb_comm.SetSTDOUT(stdout_file_spec);
if (stderr_file_spec)
m_gdb_comm.SetSTDERR(stderr_file_spec);

m_gdb_comm.SetDisableASLR(launch_flags & eLaunchFlagDisableASLR);
m_gdb_comm.SetDetachOnError(launch_flags & eLaunchFlagDetachOnError);

m_gdb_comm.SendLaunchArchPacket(
GetTarget().GetArchitecture().GetArchitectureName());

const char *launch_event_data = launch_info.GetLaunchEventData();
if (launch_event_data != nullptr && *launch_event_data != '\0')
m_gdb_comm.SendLaunchEventDataPacket(launch_event_data);

if (working_dir) {
m_gdb_comm.SetWorkingDir(working_dir);
}
LLDB_LOGF(log,
"ProcessGDBRemote::%s final STDIO paths after all "
"adjustments: stdin=%s, stdout=%s, stderr=%s",
__FUNCTION__,
stdin_file_spec ? stdin_file_spec.GetCString() : "<null>",
stdout_file_spec ? stdout_file_spec.GetCString() : "<null>",
stderr_file_spec ? stderr_file_spec.GetCString() : "<null>");

// Send the environment and the program + arguments after we connect
m_gdb_comm.SendEnvironment(launch_info.GetEnvironment());
if (stdin_file_spec)
m_gdb_comm.SetSTDIN(stdin_file_spec);
if (stdout_file_spec)
m_gdb_comm.SetSTDOUT(stdout_file_spec);
if (stderr_file_spec)
m_gdb_comm.SetSTDERR(stderr_file_spec);

{
// Scope for the scoped timeout object
GDBRemoteCommunication::ScopedTimeout timeout(m_gdb_comm,
std::chrono::seconds(10));

int arg_packet_err = m_gdb_comm.SendArgumentsPacket(launch_info);
if (arg_packet_err == 0) {
std::string error_str;
if (m_gdb_comm.GetLaunchSuccess(error_str)) {
SetID(m_gdb_comm.GetCurrentProcessID());
m_gdb_comm.SetDisableASLR(launch_flags & eLaunchFlagDisableASLR);
m_gdb_comm.SetDetachOnError(launch_flags & eLaunchFlagDetachOnError);

m_gdb_comm.SendLaunchArchPacket(
GetTarget().GetArchitecture().GetArchitectureName());

const char *launch_event_data = launch_info.GetLaunchEventData();
if (launch_event_data != nullptr && *launch_event_data != '\0')
m_gdb_comm.SendLaunchEventDataPacket(launch_event_data);

if (working_dir) {
m_gdb_comm.SetWorkingDir(working_dir);
}

// Send the environment and the program + arguments after we connect
m_gdb_comm.SendEnvironment(launch_info.GetEnvironment());

{
// Scope for the scoped timeout object
GDBRemoteCommunication::ScopedTimeout timeout(m_gdb_comm,
std::chrono::seconds(10));

int arg_packet_err = m_gdb_comm.SendArgumentsPacket(launch_info);
if (arg_packet_err == 0) {
std::string error_str;
if (m_gdb_comm.GetLaunchSuccess(error_str)) {
SetID(m_gdb_comm.GetCurrentProcessID());
} else {
error.SetErrorString(error_str.c_str());
}
} else {
error.SetErrorString(error_str.c_str());
error.SetErrorStringWithFormat("'A' packet returned an error: %i",
arg_packet_err);
}
} else {
error.SetErrorStringWithFormat("'A' packet returned an error: %i",
arg_packet_err);
}
}

if (GetID() == LLDB_INVALID_PROCESS_ID) {
LLDB_LOGF(log, "failed to connect to debugserver: %s",
error.AsCString());
KillDebugserverProcess();
return error;
}
if (GetID() == LLDB_INVALID_PROCESS_ID) {
LLDB_LOGF(log, "failed to connect to debugserver: %s",
error.AsCString());
KillDebugserverProcess();
return error;
}

StringExtractorGDBRemote response;
if (m_gdb_comm.GetStopReply(response)) {
SetLastStopPacket(response);
StringExtractorGDBRemote response;
if (m_gdb_comm.GetStopReply(response)) {
SetLastStopPacket(response);

const ArchSpec &process_arch = m_gdb_comm.GetProcessArchitecture();
const ArchSpec &process_arch = m_gdb_comm.GetProcessArchitecture();

if (process_arch.IsValid()) {
GetTarget().MergeArchitecture(process_arch);
} else {
const ArchSpec &host_arch = m_gdb_comm.GetHostArchitecture();
if (host_arch.IsValid())
GetTarget().MergeArchitecture(host_arch);
}
if (process_arch.IsValid()) {
GetTarget().MergeArchitecture(process_arch);
} else {
const ArchSpec &host_arch = m_gdb_comm.GetHostArchitecture();
if (host_arch.IsValid())
GetTarget().MergeArchitecture(host_arch);
}

SetPrivateState(SetThreadStopInfo(response));
SetPrivateState(SetThreadStopInfo(response));

if (!disable_stdio) {
if (pty.GetPrimaryFileDescriptor() != PseudoTerminal::invalid_fd)
SetSTDIOFileDescriptor(pty.ReleasePrimaryFileDescriptor());
if (!disable_stdio) {
if (pty.GetPrimaryFileDescriptor() != PseudoTerminal::invalid_fd)
SetSTDIOFileDescriptor(pty.ReleasePrimaryFileDescriptor());
}
}
} else {
LLDB_LOGF(log, "failed to connect to debugserver: %s", error.AsCString());
}
} else {
LLDB_LOGF(log, "failed to connect to debugserver: %s", error.AsCString());
// Set our user ID to an invalid process ID.
SetID(LLDB_INVALID_PROCESS_ID);
error.SetErrorStringWithFormat(
"failed to get object file from '%s' for arch %s",
exe_module->GetFileSpec().GetFilename().AsCString(),
exe_module->GetArchitecture().GetArchitectureName());
}
return error;
}
Expand Down

0 comments on commit dd5505a

Please sign in to comment.