Skip to content

Commit 62930e5

Browse files
committedJan 10, 2018
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
1 parent a7ec090 commit 62930e5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+429
-459
lines changed
 

‎lldb/include/lldb/API/SBLaunchInfo.h

+6-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212

1313
#include "lldb/API/SBDefines.h"
1414

15+
namespace lldb_private {
16+
class SBLaunchInfoImpl;
17+
}
18+
1519
namespace lldb {
1620

1721
class SBPlatform;
@@ -141,11 +145,10 @@ class LLDB_API SBLaunchInfo {
141145
friend class SBPlatform;
142146
friend class SBTarget;
143147

144-
lldb_private::ProcessLaunchInfo &ref();
145-
146148
const lldb_private::ProcessLaunchInfo &ref() const;
149+
void set_ref(const lldb_private::ProcessLaunchInfo &info);
147150

148-
ProcessLaunchInfoSP m_opaque_sp;
151+
std::shared_ptr<lldb_private::SBLaunchInfoImpl> m_opaque_sp;
149152
};
150153

151154
} // namespace lldb

‎lldb/include/lldb/Host/Host.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
#include "lldb/Host/File.h"
1414
#include "lldb/Host/HostThread.h"
15+
#include "lldb/Utility/Environment.h"
1516
#include "lldb/Utility/FileSpec.h"
16-
#include "lldb/Utility/StringList.h"
1717
#include "lldb/lldb-private-forward.h"
1818
#include "lldb/lldb-private.h"
1919
#include <cerrno>
@@ -242,7 +242,7 @@ class Host {
242242
static bool OpenFileInExternalEditor(const FileSpec &file_spec,
243243
uint32_t line_no);
244244

245-
static size_t GetEnvironment(StringList &env);
245+
static Environment GetEnvironment();
246246

247247
static std::unique_ptr<Connection>
248248
CreateDefaultConnection(llvm::StringRef url);

0 commit comments

Comments
 (0)