summaryrefslogtreecommitdiffstats
path: root/lldb/include/lldb/Interpreter
diff options
context:
space:
mode:
authorPavel Labath <labath@google.com>2018-01-10 11:57:31 +0000
committerPavel Labath <labath@google.com>2018-01-10 11:57:31 +0000
commit62930e57eb9e753951a79df790aa18caaac27690 (patch)
tree62856989fcd998c294b16849aa9d006ad2a7204b /lldb/include/lldb/Interpreter
parenta7ec090eaacd393a41c70197b248702d0e999da0 (diff)
downloadbcm5719-llvm-62930e57eb9e753951a79df790aa18caaac27690.tar.gz
bcm5719-llvm-62930e57eb9e753951a79df790aa18caaac27690.zip
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
Diffstat (limited to 'lldb/include/lldb/Interpreter')
-rw-r--r--lldb/include/lldb/Interpreter/Args.h39
1 files changed, 7 insertions, 32 deletions
diff --git a/lldb/include/lldb/Interpreter/Args.h b/lldb/include/lldb/Interpreter/Args.h
index 19d7ac41856..9bc862e04b3 100644
--- a/lldb/include/lldb/Interpreter/Args.h
+++ b/lldb/include/lldb/Interpreter/Args.h
@@ -21,6 +21,7 @@
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringRef.h"
// Project includes
+#include "lldb/Utility/Environment.h"
#include "lldb/Utility/Status.h"
#include "lldb/lldb-private-types.h"
#include "lldb/lldb-types.h"
@@ -95,6 +96,12 @@ public:
//------------------------------------------------------------------
~Args();
+ explicit Args(const Environment &env) : Args() {
+ SetArguments(const_cast<const char **>(env.getEnvp().get()));
+ }
+
+ explicit operator Environment() const { return GetConstArgumentVector(); }
+
//------------------------------------------------------------------
/// Dump all entries to the stream \a s using label \a label_name.
///
@@ -433,38 +440,6 @@ public:
static std::string EscapeLLDBCommandArgument(const std::string &arg,
char quote_char);
- //------------------------------------------------------------------
- /// Add or replace an environment variable with the given value.
- ///
- /// This command adds the environment variable if it is not already
- /// present using the given value. If the environment variable is
- /// already in the list, it replaces the first such occurrence
- /// with the new value.
- //------------------------------------------------------------------
- void AddOrReplaceEnvironmentVariable(llvm::StringRef env_var_name,
- llvm::StringRef new_value);
-
- /// Return whether a given environment variable exists.
- ///
- /// This command treats Args like a list of environment variables,
- /// as used in ProcessLaunchInfo. It treats each argument as
- /// an {env_var_name}={value} or an {env_var_name} entry.
- ///
- /// @param[in] env_var_name
- /// Specifies the name of the environment variable to check.
- ///
- /// @param[out] argument_index
- /// If non-null, then when the environment variable is found,
- /// the index of the argument position will be returned in
- /// the size_t pointed to by this argument.
- ///
- /// @return
- /// true if the specified env var name exists in the list in
- /// either of the above-mentioned formats; otherwise, false.
- //------------------------------------------------------------------
- bool ContainsEnvironmentVariable(llvm::StringRef env_var_name,
- size_t *argument_index = nullptr) const;
-
private:
size_t FindArgumentIndexForOption(Option *long_options,
int long_options_index) const;
OpenPOWER on IntegriCloud