llvm-project/lldb/source/API
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
..
CMakeLists.txt Fix LLVM_LINK_LLVM_DYLIB build (pr35053) 2017-10-31 13:23:19 +00:00
SBAddress.cpp [LLDB][MIPS] Fix TestStepOverBreakpoint.py failure. 2017-05-04 11:34:42 +00:00
SBAttachInfo.cpp *** This commit represents a complete reformatting of the LLDB source code 2016-09-06 20:57:50 +00:00
SBBlock.cpp Move Log from Core -> Utility. 2017-03-03 20:56:28 +00:00
SBBreakpoint.cpp Make breakpoint names real entities. 2017-09-14 20:22:49 +00:00
SBBreakpointLocation.cpp Cut and paste error from r23162. 2017-08-03 19:38:38 +00:00
SBBreakpointName.cpp [SBBreakpoint] Outline some functions to prevent to be exported. 2017-12-07 18:06:06 +00:00
SBBreakpointOptionCommon.cpp [SBBreakpointOptionCommon] Give this class an explicit destructor. 2017-12-07 18:06:06 +00:00
SBBreakpointOptionCommon.h [SBBreakpointOptionCommon] Give this class an explicit destructor. 2017-12-07 18:06:06 +00:00
SBBroadcaster.cpp Move Log from Core -> Utility. 2017-03-03 20:56:28 +00:00
SBCommandInterpreter.cpp Implement interactive command interruption 2017-10-05 23:41:28 +00:00
SBCommandReturnObject.cpp Rename Error -> Status. 2017-05-12 04:51:55 +00:00
SBCommunication.cpp Move Connection and IOObject interfaces to Utility module 2017-06-27 10:33:14 +00:00
SBCompileUnit.cpp Move Log from Core -> Utility. 2017-03-03 20:56:28 +00:00
SBData.cpp Move DataBuffer / DataExtractor and friends from Core -> Utility. 2017-03-04 01:30:05 +00:00
SBDebugger.cpp Revert r317182 for https://reviews.llvm.org/D39128 2017-11-02 03:17:07 +00:00
SBDeclaration.cpp Resubmit "Delete the remainder of platform specific code in FileSpec." 2017-03-22 17:33:23 +00:00
SBError.cpp Rename Error -> Status. 2017-05-12 04:51:55 +00:00
SBEvent.cpp Remove LIBLLDB_LOG_VERBOSE category 2017-02-05 00:44:54 +00:00
SBExecutionContext.cpp *** This commit represents a complete reformatting of the LLDB source code 2016-09-06 20:57:50 +00:00
SBExpressionOptions.cpp Use Timeout<> in EvaluateExpressionOptions class 2016-12-06 11:24:51 +00:00
SBFileSpec.cpp Move FileSpec from Host -> Utility. 2017-03-22 18:40:07 +00:00
SBFileSpecList.cpp Move FileSpec from Host -> Utility. 2017-03-22 18:40:07 +00:00
SBFrame.cpp Rename Error -> Status. 2017-05-12 04:51:55 +00:00
SBFunction.cpp Move Log from Core -> Utility. 2017-03-03 20:56:28 +00:00
SBHostOS.cpp Rename Error -> Status. 2017-05-12 04:51:55 +00:00
SBInstruction.cpp Move ArchSpec to the Utility module 2017-11-13 16:16:33 +00:00
SBInstructionList.cpp [LLDB][MIPS] Fix TestStepOverBreakpoint.py failure. 2017-05-04 11:34:42 +00:00
SBLanguageRuntime.cpp Update OptionGroup::SetValue to take StringRef. 2016-09-23 17:48:13 +00:00
SBLaunchInfo.cpp Add Utility/Environment class for handling... environments 2018-01-10 11:57:31 +00:00
SBLineEntry.cpp Resubmit "Delete the remainder of platform specific code in FileSpec." 2017-03-22 17:33:23 +00:00
SBListener.cpp Move the definition of SBListener::GetSP() to SBListener.cpp. 2017-03-29 19:32:59 +00:00
SBMemoryRegionInfo.cpp Move classes from Core -> Utility. 2017-02-02 21:39:50 +00:00
SBMemoryRegionInfoList.cpp Move Log from Core -> Utility. 2017-03-03 20:56:28 +00:00
SBModule.cpp Rename Error -> Status. 2017-05-12 04:51:55 +00:00
SBModuleSpec.cpp Move classes from Core -> Utility. 2017-02-02 21:39:50 +00:00
SBPlatform.cpp Add Utility/Environment class for handling... environments 2018-01-10 11:57:31 +00:00
SBProcess.cpp Add Utility/Environment class for handling... environments 2018-01-10 11:57:31 +00:00
SBProcessInfo.cpp Expose process instance info via SB API 2017-08-01 07:34:26 +00:00
SBQueue.cpp Move Log from Core -> Utility. 2017-03-03 20:56:28 +00:00
SBQueueItem.cpp Move Log from Core -> Utility. 2017-03-03 20:56:28 +00:00
SBSection.cpp Remove FileSpec::ReadFileContents. 2017-03-06 23:42:14 +00:00
SBSourceManager.cpp Move classes from Core -> Utility. 2017-02-02 21:39:50 +00:00
SBStream.cpp Rename Error -> Status. 2017-05-12 04:51:55 +00:00
SBStringList.cpp Move StringList from Core -> Utility. 2017-03-21 18:25:04 +00:00
SBStructuredData.cpp Move StructuredData from Core to Utility 2017-06-27 10:45:31 +00:00
SBSymbol.cpp Move Log from Core -> Utility. 2017-03-03 20:56:28 +00:00
SBSymbolContext.cpp Move Log from Core -> Utility. 2017-03-03 20:56:28 +00:00
SBSymbolContextList.cpp *** This commit represents a complete reformatting of the LLDB source code 2016-09-06 20:57:50 +00:00
SBTarget.cpp Add Utility/Environment class for handling... environments 2018-01-10 11:57:31 +00:00
SBThread.cpp Move StructuredData from Core to Utility 2017-06-27 10:45:31 +00:00
SBThreadCollection.cpp *** This commit represents a complete reformatting of the LLDB source code 2016-09-06 20:57:50 +00:00
SBThreadPlan.cpp Move StructuredData from Core to Utility 2017-06-27 10:45:31 +00:00
SBTrace.cpp Implementation of remote packets for Trace data. 2017-05-26 11:46:27 +00:00
SBTraceOptions.cpp Move Timer and TraceOptions from Core to Utility 2017-06-29 14:32:17 +00:00
SBType.cpp Fix assertion in ClangASTContext 2017-11-30 10:16:54 +00:00
SBTypeCategory.cpp Make lldb::Regex use StringRef. 2016-09-21 16:01:28 +00:00
SBTypeEnumMember.cpp Move classes from Core -> Utility. 2017-02-02 21:39:50 +00:00
SBTypeFilter.cpp *** This commit represents a complete reformatting of the LLDB source code 2016-09-06 20:57:50 +00:00
SBTypeFormat.cpp *** This commit represents a complete reformatting of the LLDB source code 2016-09-06 20:57:50 +00:00
SBTypeNameSpecifier.cpp *** This commit represents a complete reformatting of the LLDB source code 2016-09-06 20:57:50 +00:00
SBTypeSummary.cpp *** This commit represents a complete reformatting of the LLDB source code 2016-09-06 20:57:50 +00:00
SBTypeSynthetic.cpp *** This commit represents a complete reformatting of the LLDB source code 2016-09-06 20:57:50 +00:00
SBUnixSignals.cpp Move Log from Core -> Utility. 2017-03-03 20:56:28 +00:00
SBValue.cpp Rename Error -> Status. 2017-05-12 04:51:55 +00:00
SBValueList.cpp Move Log from Core -> Utility. 2017-03-03 20:56:28 +00:00
SBVariablesOptions.cpp *** This commit represents a complete reformatting of the LLDB source code 2016-09-06 20:57:50 +00:00
SBWatchpoint.cpp Move Log from Core -> Utility. 2017-03-03 20:56:28 +00:00
SystemInitializerFull.cpp Move StopInfoOverride callback to the new architecture plugin 2017-10-25 21:05:31 +00:00
liblldb-private.exports Limit LLDB_EXPORT_ALL_SYMBOLS to lldb symbols 2016-10-29 00:29:15 +00:00
liblldb.exports Fix OSX cmake build 2016-02-18 17:01:40 +00:00
liblldb.xcode.exports Only export public symbols with the cmake build. 2015-09-04 00:00:41 +00:00