Skip to content

Commit dd5505a

Browse files
committed
Revert "Make it possible for lldb to launch a remote binary with no local 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.
1 parent 47f76bb commit dd5505a

File tree

4 files changed

+220
-325
lines changed

4 files changed

+220
-325
lines changed

lldb/source/Commands/CommandObjectProcess.cpp

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,7 @@ class CommandObjectProcessLaunch : public CommandObjectProcessLaunchOrAttach {
159159
// If our listener is nullptr, users aren't allows to launch
160160
ModuleSP exe_module_sp = target->GetExecutableModule();
161161

162-
// If the target already has an executable module, then use that. If it
163-
// doesn't then someone must be trying to launch using a path that will
164-
// make sense to the remote stub, but doesn't exist on the local host.
165-
// In that case use the ExecutableFile that was set in the target's
166-
// ProcessLaunchInfo.
167-
if (exe_module_sp == nullptr && !target->GetProcessLaunchInfo().GetExecutableFile()) {
162+
if (exe_module_sp == nullptr) {
168163
result.AppendError("no file in target, create a debug target using the "
169164
"'target create' command");
170165
return false;
@@ -224,17 +219,11 @@ class CommandObjectProcessLaunch : public CommandObjectProcessLaunchOrAttach {
224219
if (!target_settings_argv0.empty()) {
225220
m_options.launch_info.GetArguments().AppendArgument(
226221
target_settings_argv0);
227-
if (exe_module_sp)
228-
m_options.launch_info.SetExecutableFile(
229-
exe_module_sp->GetPlatformFileSpec(), false);
230-
else
231-
m_options.launch_info.SetExecutableFile(target->GetProcessLaunchInfo().GetExecutableFile(), false);
222+
m_options.launch_info.SetExecutableFile(
223+
exe_module_sp->GetPlatformFileSpec(), false);
232224
} else {
233-
if (exe_module_sp)
234-
m_options.launch_info.SetExecutableFile(
235-
exe_module_sp->GetPlatformFileSpec(), true);
236-
else
237-
m_options.launch_info.SetExecutableFile(target->GetProcessLaunchInfo().GetExecutableFile(), true);
225+
m_options.launch_info.SetExecutableFile(
226+
exe_module_sp->GetPlatformFileSpec(), true);
238227
}
239228

240229
if (launch_args.GetArgumentCount() == 0) {
@@ -261,20 +250,11 @@ class CommandObjectProcessLaunch : public CommandObjectProcessLaunchOrAttach {
261250
llvm::StringRef data = stream.GetString();
262251
if (!data.empty())
263252
result.AppendMessage(data);
264-
// If we didn't have a local executable, then we wouldn't have had an
265-
// executable module before launch.
266-
if (!exe_module_sp)
267-
exe_module_sp = target->GetExecutableModule();
268-
if (!exe_module_sp) {
269-
result.AppendWarning("Could not get executable module after launch.");
270-
} else {
271-
272-
const char *archname =
273-
exe_module_sp->GetArchitecture().GetArchitectureName();
274-
result.AppendMessageWithFormat(
275-
"Process %" PRIu64 " launched: '%s' (%s)\n", process_sp->GetID(),
276-
exe_module_sp->GetFileSpec().GetPath().c_str(), archname);
277-
}
253+
const char *archname =
254+
exe_module_sp->GetArchitecture().GetArchitectureName();
255+
result.AppendMessageWithFormat(
256+
"Process %" PRIu64 " launched: '%s' (%s)\n", process_sp->GetID(),
257+
exe_module_sp->GetFileSpec().GetPath().c_str(), archname);
278258
result.SetStatus(eReturnStatusSuccessFinishResult);
279259
result.SetDidChangeProcessState(true);
280260
} else {

lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp

Lines changed: 117 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -677,133 +677,143 @@ Status ProcessGDBRemote::DoLaunch(lldb_private::Module *exe_module,
677677
// LLDB_LOG_OPTION_PREPEND_PROC_AND_THREAD);
678678
// ::LogSetLogFile ("/dev/stdout");
679679

680-
error = EstablishConnectionIfNeeded(launch_info);
681-
if (error.Success()) {
682-
PseudoTerminal pty;
683-
const bool disable_stdio = (launch_flags & eLaunchFlagDisableSTDIO) != 0;
684-
685-
PlatformSP platform_sp(GetTarget().GetPlatform());
686-
if (disable_stdio) {
687-
// set to /dev/null unless redirected to a file above
688-
if (!stdin_file_spec)
689-
stdin_file_spec.SetFile(FileSystem::DEV_NULL,
690-
FileSpec::Style::native);
691-
if (!stdout_file_spec)
692-
stdout_file_spec.SetFile(FileSystem::DEV_NULL,
693-
FileSpec::Style::native);
694-
if (!stderr_file_spec)
695-
stderr_file_spec.SetFile(FileSystem::DEV_NULL,
696-
FileSpec::Style::native);
697-
} else if (platform_sp && platform_sp->IsHost()) {
698-
// If the debugserver is local and we aren't disabling STDIO, lets use
699-
// a pseudo terminal to instead of relying on the 'O' packets for stdio
700-
// since 'O' packets can really slow down debugging if the inferior
701-
// does a lot of output.
702-
if ((!stdin_file_spec || !stdout_file_spec || !stderr_file_spec) &&
703-
!errorToBool(pty.OpenFirstAvailablePrimary(O_RDWR | O_NOCTTY))) {
704-
FileSpec secondary_name(pty.GetSecondaryName());
680+
ObjectFile *object_file = exe_module->GetObjectFile();
681+
if (object_file) {
682+
error = EstablishConnectionIfNeeded(launch_info);
683+
if (error.Success()) {
684+
PseudoTerminal pty;
685+
const bool disable_stdio = (launch_flags & eLaunchFlagDisableSTDIO) != 0;
705686

687+
PlatformSP platform_sp(GetTarget().GetPlatform());
688+
if (disable_stdio) {
689+
// set to /dev/null unless redirected to a file above
706690
if (!stdin_file_spec)
707-
stdin_file_spec = secondary_name;
708-
691+
stdin_file_spec.SetFile(FileSystem::DEV_NULL,
692+
FileSpec::Style::native);
709693
if (!stdout_file_spec)
710-
stdout_file_spec = secondary_name;
711-
694+
stdout_file_spec.SetFile(FileSystem::DEV_NULL,
695+
FileSpec::Style::native);
712696
if (!stderr_file_spec)
713-
stderr_file_spec = secondary_name;
697+
stderr_file_spec.SetFile(FileSystem::DEV_NULL,
698+
FileSpec::Style::native);
699+
} else if (platform_sp && platform_sp->IsHost()) {
700+
// If the debugserver is local and we aren't disabling STDIO, lets use
701+
// a pseudo terminal to instead of relying on the 'O' packets for stdio
702+
// since 'O' packets can really slow down debugging if the inferior
703+
// does a lot of output.
704+
if ((!stdin_file_spec || !stdout_file_spec || !stderr_file_spec) &&
705+
!errorToBool(pty.OpenFirstAvailablePrimary(O_RDWR | O_NOCTTY))) {
706+
FileSpec secondary_name(pty.GetSecondaryName());
707+
708+
if (!stdin_file_spec)
709+
stdin_file_spec = secondary_name;
710+
711+
if (!stdout_file_spec)
712+
stdout_file_spec = secondary_name;
713+
714+
if (!stderr_file_spec)
715+
stderr_file_spec = secondary_name;
716+
}
717+
LLDB_LOGF(
718+
log,
719+
"ProcessGDBRemote::%s adjusted STDIO paths for local platform "
720+
"(IsHost() is true) using secondary: stdin=%s, stdout=%s, "
721+
"stderr=%s",
722+
__FUNCTION__,
723+
stdin_file_spec ? stdin_file_spec.GetCString() : "<null>",
724+
stdout_file_spec ? stdout_file_spec.GetCString() : "<null>",
725+
stderr_file_spec ? stderr_file_spec.GetCString() : "<null>");
714726
}
715-
LLDB_LOGF(
716-
log,
717-
"ProcessGDBRemote::%s adjusted STDIO paths for local platform "
718-
"(IsHost() is true) using secondary: stdin=%s, stdout=%s, "
719-
"stderr=%s",
720-
__FUNCTION__,
721-
stdin_file_spec ? stdin_file_spec.GetCString() : "<null>",
722-
stdout_file_spec ? stdout_file_spec.GetCString() : "<null>",
723-
stderr_file_spec ? stderr_file_spec.GetCString() : "<null>");
724-
}
725727

726-
LLDB_LOGF(log,
727-
"ProcessGDBRemote::%s final STDIO paths after all "
728-
"adjustments: stdin=%s, stdout=%s, stderr=%s",
729-
__FUNCTION__,
730-
stdin_file_spec ? stdin_file_spec.GetCString() : "<null>",
731-
stdout_file_spec ? stdout_file_spec.GetCString() : "<null>",
732-
stderr_file_spec ? stderr_file_spec.GetCString() : "<null>");
733-
734-
if (stdin_file_spec)
735-
m_gdb_comm.SetSTDIN(stdin_file_spec);
736-
if (stdout_file_spec)
737-
m_gdb_comm.SetSTDOUT(stdout_file_spec);
738-
if (stderr_file_spec)
739-
m_gdb_comm.SetSTDERR(stderr_file_spec);
740-
741-
m_gdb_comm.SetDisableASLR(launch_flags & eLaunchFlagDisableASLR);
742-
m_gdb_comm.SetDetachOnError(launch_flags & eLaunchFlagDetachOnError);
743-
744-
m_gdb_comm.SendLaunchArchPacket(
745-
GetTarget().GetArchitecture().GetArchitectureName());
746-
747-
const char *launch_event_data = launch_info.GetLaunchEventData();
748-
if (launch_event_data != nullptr && *launch_event_data != '\0')
749-
m_gdb_comm.SendLaunchEventDataPacket(launch_event_data);
750-
751-
if (working_dir) {
752-
m_gdb_comm.SetWorkingDir(working_dir);
753-
}
728+
LLDB_LOGF(log,
729+
"ProcessGDBRemote::%s final STDIO paths after all "
730+
"adjustments: stdin=%s, stdout=%s, stderr=%s",
731+
__FUNCTION__,
732+
stdin_file_spec ? stdin_file_spec.GetCString() : "<null>",
733+
stdout_file_spec ? stdout_file_spec.GetCString() : "<null>",
734+
stderr_file_spec ? stderr_file_spec.GetCString() : "<null>");
754735

755-
// Send the environment and the program + arguments after we connect
756-
m_gdb_comm.SendEnvironment(launch_info.GetEnvironment());
736+
if (stdin_file_spec)
737+
m_gdb_comm.SetSTDIN(stdin_file_spec);
738+
if (stdout_file_spec)
739+
m_gdb_comm.SetSTDOUT(stdout_file_spec);
740+
if (stderr_file_spec)
741+
m_gdb_comm.SetSTDERR(stderr_file_spec);
757742

758-
{
759-
// Scope for the scoped timeout object
760-
GDBRemoteCommunication::ScopedTimeout timeout(m_gdb_comm,
761-
std::chrono::seconds(10));
762-
763-
int arg_packet_err = m_gdb_comm.SendArgumentsPacket(launch_info);
764-
if (arg_packet_err == 0) {
765-
std::string error_str;
766-
if (m_gdb_comm.GetLaunchSuccess(error_str)) {
767-
SetID(m_gdb_comm.GetCurrentProcessID());
743+
m_gdb_comm.SetDisableASLR(launch_flags & eLaunchFlagDisableASLR);
744+
m_gdb_comm.SetDetachOnError(launch_flags & eLaunchFlagDetachOnError);
745+
746+
m_gdb_comm.SendLaunchArchPacket(
747+
GetTarget().GetArchitecture().GetArchitectureName());
748+
749+
const char *launch_event_data = launch_info.GetLaunchEventData();
750+
if (launch_event_data != nullptr && *launch_event_data != '\0')
751+
m_gdb_comm.SendLaunchEventDataPacket(launch_event_data);
752+
753+
if (working_dir) {
754+
m_gdb_comm.SetWorkingDir(working_dir);
755+
}
756+
757+
// Send the environment and the program + arguments after we connect
758+
m_gdb_comm.SendEnvironment(launch_info.GetEnvironment());
759+
760+
{
761+
// Scope for the scoped timeout object
762+
GDBRemoteCommunication::ScopedTimeout timeout(m_gdb_comm,
763+
std::chrono::seconds(10));
764+
765+
int arg_packet_err = m_gdb_comm.SendArgumentsPacket(launch_info);
766+
if (arg_packet_err == 0) {
767+
std::string error_str;
768+
if (m_gdb_comm.GetLaunchSuccess(error_str)) {
769+
SetID(m_gdb_comm.GetCurrentProcessID());
770+
} else {
771+
error.SetErrorString(error_str.c_str());
772+
}
768773
} else {
769-
error.SetErrorString(error_str.c_str());
774+
error.SetErrorStringWithFormat("'A' packet returned an error: %i",
775+
arg_packet_err);
770776
}
771-
} else {
772-
error.SetErrorStringWithFormat("'A' packet returned an error: %i",
773-
arg_packet_err);
774777
}
775-
}
776778

777-
if (GetID() == LLDB_INVALID_PROCESS_ID) {
778-
LLDB_LOGF(log, "failed to connect to debugserver: %s",
779-
error.AsCString());
780-
KillDebugserverProcess();
781-
return error;
782-
}
779+
if (GetID() == LLDB_INVALID_PROCESS_ID) {
780+
LLDB_LOGF(log, "failed to connect to debugserver: %s",
781+
error.AsCString());
782+
KillDebugserverProcess();
783+
return error;
784+
}
783785

784-
StringExtractorGDBRemote response;
785-
if (m_gdb_comm.GetStopReply(response)) {
786-
SetLastStopPacket(response);
786+
StringExtractorGDBRemote response;
787+
if (m_gdb_comm.GetStopReply(response)) {
788+
SetLastStopPacket(response);
787789

788-
const ArchSpec &process_arch = m_gdb_comm.GetProcessArchitecture();
790+
const ArchSpec &process_arch = m_gdb_comm.GetProcessArchitecture();
789791

790-
if (process_arch.IsValid()) {
791-
GetTarget().MergeArchitecture(process_arch);
792-
} else {
793-
const ArchSpec &host_arch = m_gdb_comm.GetHostArchitecture();
794-
if (host_arch.IsValid())
795-
GetTarget().MergeArchitecture(host_arch);
796-
}
792+
if (process_arch.IsValid()) {
793+
GetTarget().MergeArchitecture(process_arch);
794+
} else {
795+
const ArchSpec &host_arch = m_gdb_comm.GetHostArchitecture();
796+
if (host_arch.IsValid())
797+
GetTarget().MergeArchitecture(host_arch);
798+
}
797799

798-
SetPrivateState(SetThreadStopInfo(response));
800+
SetPrivateState(SetThreadStopInfo(response));
799801

800-
if (!disable_stdio) {
801-
if (pty.GetPrimaryFileDescriptor() != PseudoTerminal::invalid_fd)
802-
SetSTDIOFileDescriptor(pty.ReleasePrimaryFileDescriptor());
802+
if (!disable_stdio) {
803+
if (pty.GetPrimaryFileDescriptor() != PseudoTerminal::invalid_fd)
804+
SetSTDIOFileDescriptor(pty.ReleasePrimaryFileDescriptor());
805+
}
803806
}
807+
} else {
808+
LLDB_LOGF(log, "failed to connect to debugserver: %s", error.AsCString());
804809
}
805810
} else {
806-
LLDB_LOGF(log, "failed to connect to debugserver: %s", error.AsCString());
811+
// Set our user ID to an invalid process ID.
812+
SetID(LLDB_INVALID_PROCESS_ID);
813+
error.SetErrorStringWithFormat(
814+
"failed to get object file from '%s' for arch %s",
815+
exe_module->GetFileSpec().GetFilename().AsCString(),
816+
exe_module->GetArchitecture().GetArchitectureName());
807817
}
808818
return error;
809819
}

0 commit comments

Comments
 (0)