llvm-project/lldb/tools/lldb-server
Pavel Labath 62930e57eb Add Utility/Environment class for handling... environments
Summary:
There was some confusion in the code about how to represent process
environment. Most of the code (ab)used the Args class for this purpose,
but some of it used a more basic StringList class instead. In either
case, the fact that the underlying abstraction did not provide primitive
operations for the typical environment operations meant that even a
simple operation like checking for an environment variable value was
several lines of code.

This patch adds a separate Environment class, which is essentialy a
llvm::StringMap<std::string> in disguise. To standard StringMap
functionality, it adds a couple of new functions, which are specific to
the environment use case:
- (most important) envp conversion for passing into execve() and likes.
  Instead of trying to maintain a constantly up-to-date envp view, it
  provides a function which creates a envp view on demand, with the
  expectation that this will be called as the very last thing before
  handing the value to the system function.
- insert(StringRef KeyEqValue) - splits KeyEqValue into (key, value)
  pair and inserts it into the environment map.
- compose(value_type KeyValue) - takes a map entry and converts in back
  into "KEY=VALUE" representation.

With this interface most of the environment-manipulating code becomes
one-liners. The only tricky part was maintaining compatibility in
SBLaunchInfo, which expects that the environment entries are accessible
by index and that the returned const char* is backed by the launch info
object (random access into maps is hard and the map stores the entry in
a deconstructed form, so we cannot just return a .c_str() value). To
solve this, I have the SBLaunchInfo convert the environment into the
"envp" form, and use it to answer the environment queries. Extra code is
added to make sure the envp version is always in sync.

(This also improves the layering situation as Args was in the Interpreter module
whereas Environment is in Utility.)

Reviewers: zturner, davide, jingham, clayborg

Subscribers: emaste, lldb-commits, mgorny

Differential Revision: https://reviews.llvm.org/D41359

llvm-svn: 322174
2018-01-10 11:57:31 +00:00
..
Darwin/resources [NFC] Darwin llgs support from Week of Code 2016-09-04 00:18:56 +00:00
Acceptor.cpp Rename Error -> Status. 2017-05-12 04:51:55 +00:00
Acceptor.h Move Connection and IOObject interfaces to Utility module 2017-06-27 10:33:14 +00:00
CMakeLists.txt [lldb] Use PRIVATE in target_link_libraries 2017-12-06 20:53:03 +00:00
LLDBServerUtilities.cpp Remove lldb streams from the Log class completely 2017-03-15 09:06:58 +00:00
LLDBServerUtilities.h *** This commit represents a complete reformatting of the LLDB source code 2016-09-06 20:57:50 +00:00
lldb-gdbserver.cpp Add Utility/Environment class for handling... environments 2018-01-10 11:57:31 +00:00
lldb-platform.cpp Fix a copy-paste error in r307161 2017-07-06 11:43:25 +00:00
lldb-server.cpp *** This commit represents a complete reformatting of the LLDB source code 2016-09-06 20:57:50 +00:00
lldb-server.exports