This is an archive of the discontinued LLVM Phabricator instance.

llgs: Propagate the environment when launching the inferior from command line
ClosedPublic

Authored by labath on Dec 11 2017, 7:53 AM.

Details

Summary

We were failing to propagate the environment when lldb-server was
started with a pre-loaded process
(e.g.: lldb-server gdbserver -- inferior --inferior_args)

This patch makes sure the environment is propagated. Instead of adding a
new GDBRemoteCommunicationServerLLGS::SetLaunchEnvironment function to
complement SetLaunchArgs and SetLaunchFlags, I replace these with a
more generic SetLaunchInfo, which can be used to set any launch-related
property.

The accompanying test also verifies that the server correctly terminates
the connection after sending the exit packet (specifically, that it does
not send the exit packet twice).

Diff Detail

Repository
rL LLVM

Event Timeline

labath created this revision.Dec 11 2017, 7:53 AM
clayborg accepted this revision.Dec 11 2017, 9:14 AM

Anything that launches a process should use the ProcessLaunchInfo. Nice patch.

source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h
46 ↗(On Diff #126367)

We might want a "ProcessLaunchInfo &" accessor so we can modify the flags after they have initially been set?

ProcessLaunchInfo &GetLaunchInfo() { return m_process_launch_info; }

If we don't need it, we shouldn't add it yet, just thinking out loud here.

tools/lldb-server/lldb-gdbserver.cpp
181–182 ↗(On Diff #126367)

How many places do we set these flags like this? Wondering if we should add a method like:

info.SetFlagsForDebugging();

That way if we add new flags that must be set later, it will be easier than updating all sites that modify these flags for debugging a process.

This revision is now accepted and ready to land.Dec 11 2017, 9:14 AM
labath added inline comments.Dec 12 2017, 8:56 AM
source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h
46 ↗(On Diff #126367)

We don't need that at the moment. The launching process is a fire-and-forget kind of thing right now.

tools/lldb-server/lldb-gdbserver.cpp
181–182 ↗(On Diff #126367)

I've found two places that blindly set the launch flags: here and SBLaunchInfo (the other launches do the dance of consulting the target property for the value). I can make a eLaunchFlagStandardDebug which would include Debug and DisableASLR flags (since we can assume that one normally wants to disable aslr when debugging). However, the StopAtEntry flag could not be there, as it's appropriateness depends on the environment the launch is happening in (here we want it because we need to wait for the client to connect, but this is not appropriate as the SBLaunchInfo default).

No worries then. No need to make a new enum if this is just two places and they aren't all setting the same flags.

This revision was automatically updated to reflect the committed changes.