[lldb][NFC] Fix all formatting errors in .cpp file headers
Summary:
A *.cpp file header in LLDB (and in LLDB) should like this:
```
//===-- TestUtilities.cpp -------------------------------------------------===//
```
However in LLDB most of our source files have arbitrary changes to this format and
these changes are spreading through LLDB as folks usually just use the existing
source files as templates for their new files (most notably the unnecessary
editor language indicator `-*- C++ -*-` is spreading and in every review
someone is pointing out that this is wrong, resulting in people pointing out that this
is done in the same way in other files).
This patch removes most of these inconsistencies including the editor language indicators,
all the different missing/additional '-' characters, files that center the file name, missing
trailing `===//` (mostly caused by clang-format breaking the line).
Reviewers: aprantl, espindola, jfb, shafik, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: dexonsmith, wuzish, emaste, sdardis, nemanjai, kbarton, MaskRay, atanasyan, arphaman, jfb, abidh, jsji, JDevlieghere, usaxena95, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D73258
2020-01-24 15:23:27 +08:00
|
|
|
//===-- SBLaunchInfo.cpp --------------------------------------------------===//
|
2015-02-05 07:19:15 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2015-02-05 07:19:15 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/API/SBLaunchInfo.h"
|
2019-03-06 08:06:00 +08:00
|
|
|
#include "SBReproducerPrivate.h"
|
2015-02-05 07:19:15 +08:00
|
|
|
|
|
|
|
#include "lldb/API/SBFileSpec.h"
|
|
|
|
#include "lldb/API/SBListener.h"
|
Move FileAction, ProcessInfo and ProcessLaunchInfo from Target to Host
Summary:
These classes describe the details of the process we are about to
launch, and so they are naturally used by the launching code in the Host
module. Previously they were present in Target because that is the most
important (but by far not the only) user of the launching code.
Since the launching code has other customers, must of which do not care
about Targets, it makes sense to move these classes to the Host layer,
next to the launching code.
This move reduces the number of times that Target is included from host
to 8 (it used to be 14).
Reviewers: zturner, clayborg, jingham, davide, teemperor
Subscribers: emaste, mgorny, lldb-commits
Differential Revision: https://reviews.llvm.org/D56602
llvm-svn: 353047
2019-02-04 22:28:08 +08:00
|
|
|
#include "lldb/Host/ProcessLaunchInfo.h"
|
2015-02-05 07:19:15 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
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 19:57:31 +08:00
|
|
|
class lldb_private::SBLaunchInfoImpl : public ProcessLaunchInfo {
|
|
|
|
public:
|
|
|
|
SBLaunchInfoImpl()
|
|
|
|
: ProcessLaunchInfo(), m_envp(GetEnvironment().getEnvp()) {}
|
|
|
|
|
|
|
|
const char *const *GetEnvp() const { return m_envp; }
|
|
|
|
void RegenerateEnvp() { m_envp = GetEnvironment().getEnvp(); }
|
|
|
|
|
|
|
|
SBLaunchInfoImpl &operator=(const ProcessLaunchInfo &rhs) {
|
|
|
|
ProcessLaunchInfo::operator=(rhs);
|
|
|
|
RegenerateEnvp();
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Environment::Envp m_envp;
|
|
|
|
};
|
|
|
|
|
2015-02-05 07:19:15 +08:00
|
|
|
SBLaunchInfo::SBLaunchInfo(const char **argv)
|
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 19:57:31 +08:00
|
|
|
: m_opaque_sp(new SBLaunchInfoImpl()) {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_CONSTRUCTOR(SBLaunchInfo, (const char **), argv);
|
|
|
|
|
2015-02-05 07:19:15 +08:00
|
|
|
m_opaque_sp->GetFlags().Reset(eLaunchFlagDebug | eLaunchFlagDisableASLR);
|
|
|
|
if (argv && argv[0])
|
|
|
|
m_opaque_sp->GetArguments().SetArguments(argv);
|
|
|
|
}
|
|
|
|
|
2020-01-29 08:44:30 +08:00
|
|
|
SBLaunchInfo::SBLaunchInfo(const SBLaunchInfo &rhs) {
|
|
|
|
LLDB_RECORD_CONSTRUCTOR(SBLaunchInfo, (const lldb::SBLaunchInfo &), rhs);
|
|
|
|
|
|
|
|
m_opaque_sp = rhs.m_opaque_sp;
|
|
|
|
}
|
|
|
|
|
2020-01-29 09:09:49 +08:00
|
|
|
SBLaunchInfo &SBLaunchInfo::operator=(const SBLaunchInfo &rhs) {
|
|
|
|
LLDB_RECORD_METHOD(SBLaunchInfo &,
|
|
|
|
SBLaunchInfo, operator=,(const lldb::SBLaunchInfo &), rhs);
|
2020-01-29 08:44:30 +08:00
|
|
|
|
|
|
|
m_opaque_sp = rhs.m_opaque_sp;
|
2020-01-29 09:09:49 +08:00
|
|
|
return LLDB_RECORD_RESULT(*this);
|
2020-01-29 08:44:30 +08:00
|
|
|
}
|
|
|
|
|
2020-02-18 14:57:06 +08:00
|
|
|
SBLaunchInfo::~SBLaunchInfo() = default;
|
2015-02-05 07:19:15 +08:00
|
|
|
|
2015-02-13 22:31:06 +08:00
|
|
|
const lldb_private::ProcessLaunchInfo &SBLaunchInfo::ref() const {
|
|
|
|
return *m_opaque_sp;
|
|
|
|
}
|
|
|
|
|
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 19:57:31 +08:00
|
|
|
void SBLaunchInfo::set_ref(const ProcessLaunchInfo &info) {
|
|
|
|
*m_opaque_sp = info;
|
|
|
|
}
|
|
|
|
|
2019-03-06 08:06:00 +08:00
|
|
|
lldb::pid_t SBLaunchInfo::GetProcessID() {
|
|
|
|
LLDB_RECORD_METHOD_NO_ARGS(lldb::pid_t, SBLaunchInfo, GetProcessID);
|
|
|
|
|
|
|
|
return m_opaque_sp->GetProcessID();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t SBLaunchInfo::GetUserID() {
|
|
|
|
LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBLaunchInfo, GetUserID);
|
|
|
|
|
|
|
|
return m_opaque_sp->GetUserID();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t SBLaunchInfo::GetGroupID() {
|
|
|
|
LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBLaunchInfo, GetGroupID);
|
|
|
|
|
|
|
|
return m_opaque_sp->GetGroupID();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SBLaunchInfo::UserIDIsValid() {
|
|
|
|
LLDB_RECORD_METHOD_NO_ARGS(bool, SBLaunchInfo, UserIDIsValid);
|
|
|
|
|
|
|
|
return m_opaque_sp->UserIDIsValid();
|
|
|
|
}
|
2015-02-05 07:19:15 +08:00
|
|
|
|
2019-03-06 08:06:00 +08:00
|
|
|
bool SBLaunchInfo::GroupIDIsValid() {
|
|
|
|
LLDB_RECORD_METHOD_NO_ARGS(bool, SBLaunchInfo, GroupIDIsValid);
|
2015-02-05 07:19:15 +08:00
|
|
|
|
2019-03-06 08:06:00 +08:00
|
|
|
return m_opaque_sp->GroupIDIsValid();
|
|
|
|
}
|
2015-02-05 07:19:15 +08:00
|
|
|
|
2019-03-06 08:06:00 +08:00
|
|
|
void SBLaunchInfo::SetUserID(uint32_t uid) {
|
|
|
|
LLDB_RECORD_METHOD(void, SBLaunchInfo, SetUserID, (uint32_t), uid);
|
2015-02-05 07:19:15 +08:00
|
|
|
|
2019-03-06 08:06:00 +08:00
|
|
|
m_opaque_sp->SetUserID(uid);
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2019-03-06 08:06:00 +08:00
|
|
|
void SBLaunchInfo::SetGroupID(uint32_t gid) {
|
|
|
|
LLDB_RECORD_METHOD(void, SBLaunchInfo, SetGroupID, (uint32_t), gid);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2019-03-06 08:06:00 +08:00
|
|
|
m_opaque_sp->SetGroupID(gid);
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-02-05 07:19:15 +08:00
|
|
|
SBFileSpec SBLaunchInfo::GetExecutableFile() {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_NO_ARGS(lldb::SBFileSpec, SBLaunchInfo, GetExecutableFile);
|
|
|
|
|
|
|
|
return LLDB_RECORD_RESULT(SBFileSpec(m_opaque_sp->GetExecutableFile()));
|
2015-02-05 07:19:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SBLaunchInfo::SetExecutableFile(SBFileSpec exe_file,
|
|
|
|
bool add_as_first_arg) {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD(void, SBLaunchInfo, SetExecutableFile,
|
|
|
|
(lldb::SBFileSpec, bool), exe_file, add_as_first_arg);
|
|
|
|
|
2015-02-05 07:19:15 +08:00
|
|
|
m_opaque_sp->SetExecutableFile(exe_file.ref(), add_as_first_arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
SBListener SBLaunchInfo::GetListener() {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_NO_ARGS(lldb::SBListener, SBLaunchInfo, GetListener);
|
|
|
|
|
|
|
|
return LLDB_RECORD_RESULT(SBListener(m_opaque_sp->GetListener()));
|
2015-02-05 07:19:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SBLaunchInfo::SetListener(SBListener &listener) {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD(void, SBLaunchInfo, SetListener, (lldb::SBListener &),
|
|
|
|
listener);
|
|
|
|
|
2015-02-05 07:19:15 +08:00
|
|
|
m_opaque_sp->SetListener(listener.GetSP());
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t SBLaunchInfo::GetNumArguments() {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBLaunchInfo, GetNumArguments);
|
|
|
|
|
2015-02-05 07:19:15 +08:00
|
|
|
return m_opaque_sp->GetArguments().GetArgumentCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *SBLaunchInfo::GetArgumentAtIndex(uint32_t idx) {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD(const char *, SBLaunchInfo, GetArgumentAtIndex, (uint32_t),
|
|
|
|
idx);
|
|
|
|
|
2015-02-05 07:19:15 +08:00
|
|
|
return m_opaque_sp->GetArguments().GetArgumentAtIndex(idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SBLaunchInfo::SetArguments(const char **argv, bool append) {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD(void, SBLaunchInfo, SetArguments, (const char **, bool),
|
|
|
|
argv, append);
|
|
|
|
|
2015-02-05 07:19:15 +08:00
|
|
|
if (append) {
|
|
|
|
if (argv)
|
|
|
|
m_opaque_sp->GetArguments().AppendArguments(argv);
|
|
|
|
} else {
|
|
|
|
if (argv)
|
|
|
|
m_opaque_sp->GetArguments().SetArguments(argv);
|
2016-09-07 04:57:50 +08:00
|
|
|
else
|
2015-02-05 07:19:15 +08:00
|
|
|
m_opaque_sp->GetArguments().Clear();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2015-02-05 07:19:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t SBLaunchInfo::GetNumEnvironmentEntries() {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBLaunchInfo, GetNumEnvironmentEntries);
|
|
|
|
|
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 19:57:31 +08:00
|
|
|
return m_opaque_sp->GetEnvironment().size();
|
2015-02-05 07:19:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *SBLaunchInfo::GetEnvironmentEntryAtIndex(uint32_t idx) {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD(const char *, SBLaunchInfo, GetEnvironmentEntryAtIndex,
|
|
|
|
(uint32_t), idx);
|
|
|
|
|
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 19:57:31 +08:00
|
|
|
if (idx > GetNumEnvironmentEntries())
|
|
|
|
return nullptr;
|
|
|
|
return m_opaque_sp->GetEnvp()[idx];
|
2015-02-05 07:19:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SBLaunchInfo::SetEnvironmentEntries(const char **envp, bool append) {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD(void, SBLaunchInfo, SetEnvironmentEntries,
|
|
|
|
(const char **, bool), envp, append);
|
|
|
|
|
2020-03-24 09:20:10 +08:00
|
|
|
Environment env(envp);
|
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 19:57:31 +08:00
|
|
|
if (append)
|
2020-03-24 09:20:10 +08:00
|
|
|
m_opaque_sp->GetEnvironment().insert(env.begin(), env.end());
|
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 19:57:31 +08:00
|
|
|
else
|
2020-03-24 09:20:10 +08:00
|
|
|
m_opaque_sp->GetEnvironment() = env;
|
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 19:57:31 +08:00
|
|
|
m_opaque_sp->RegenerateEnvp();
|
2015-02-05 07:19:15 +08:00
|
|
|
}
|
|
|
|
|
2019-03-06 08:06:00 +08:00
|
|
|
void SBLaunchInfo::Clear() {
|
|
|
|
LLDB_RECORD_METHOD_NO_ARGS(void, SBLaunchInfo, Clear);
|
|
|
|
|
|
|
|
m_opaque_sp->Clear();
|
|
|
|
}
|
2015-02-05 07:19:15 +08:00
|
|
|
|
|
|
|
const char *SBLaunchInfo::GetWorkingDirectory() const {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_CONST_NO_ARGS(const char *, SBLaunchInfo,
|
|
|
|
GetWorkingDirectory);
|
|
|
|
|
2015-05-30 03:52:29 +08:00
|
|
|
return m_opaque_sp->GetWorkingDirectory().GetCString();
|
2015-02-05 07:19:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SBLaunchInfo::SetWorkingDirectory(const char *working_dir) {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD(void, SBLaunchInfo, SetWorkingDirectory, (const char *),
|
|
|
|
working_dir);
|
|
|
|
|
2018-11-02 05:05:36 +08:00
|
|
|
m_opaque_sp->SetWorkingDirectory(FileSpec(working_dir));
|
2015-02-05 07:19:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t SBLaunchInfo::GetLaunchFlags() {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBLaunchInfo, GetLaunchFlags);
|
|
|
|
|
2015-02-05 07:19:15 +08:00
|
|
|
return m_opaque_sp->GetFlags().Get();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SBLaunchInfo::SetLaunchFlags(uint32_t flags) {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD(void, SBLaunchInfo, SetLaunchFlags, (uint32_t), flags);
|
|
|
|
|
2015-02-05 07:19:15 +08:00
|
|
|
m_opaque_sp->GetFlags().Reset(flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *SBLaunchInfo::GetProcessPluginName() {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_NO_ARGS(const char *, SBLaunchInfo, GetProcessPluginName);
|
|
|
|
|
2015-02-05 07:19:15 +08:00
|
|
|
return m_opaque_sp->GetProcessPluginName();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SBLaunchInfo::SetProcessPluginName(const char *plugin_name) {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD(void, SBLaunchInfo, SetProcessPluginName, (const char *),
|
|
|
|
plugin_name);
|
|
|
|
|
2015-02-05 07:19:15 +08:00
|
|
|
return m_opaque_sp->SetProcessPluginName(plugin_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *SBLaunchInfo::GetShell() {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_NO_ARGS(const char *, SBLaunchInfo, GetShell);
|
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// Constify this string so that it is saved in the string pool. Otherwise it
|
|
|
|
// would be freed when this function goes out of scope.
|
2015-02-05 07:19:15 +08:00
|
|
|
ConstString shell(m_opaque_sp->GetShell().GetPath().c_str());
|
|
|
|
return shell.AsCString();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SBLaunchInfo::SetShell(const char *path) {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD(void, SBLaunchInfo, SetShell, (const char *), path);
|
|
|
|
|
2018-11-02 05:05:36 +08:00
|
|
|
m_opaque_sp->SetShell(FileSpec(path));
|
2015-02-05 07:19:15 +08:00
|
|
|
}
|
|
|
|
|
2015-02-21 06:20:30 +08:00
|
|
|
bool SBLaunchInfo::GetShellExpandArguments() {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_NO_ARGS(bool, SBLaunchInfo, GetShellExpandArguments);
|
|
|
|
|
2015-02-21 06:20:30 +08:00
|
|
|
return m_opaque_sp->GetShellExpandArguments();
|
2015-02-10 11:16:55 +08:00
|
|
|
}
|
|
|
|
|
2015-02-21 06:20:30 +08:00
|
|
|
void SBLaunchInfo::SetShellExpandArguments(bool expand) {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD(void, SBLaunchInfo, SetShellExpandArguments, (bool),
|
|
|
|
expand);
|
|
|
|
|
2015-02-21 06:20:30 +08:00
|
|
|
m_opaque_sp->SetShellExpandArguments(expand);
|
2015-02-10 11:16:55 +08:00
|
|
|
}
|
|
|
|
|
2015-02-05 07:19:15 +08:00
|
|
|
uint32_t SBLaunchInfo::GetResumeCount() {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBLaunchInfo, GetResumeCount);
|
|
|
|
|
2015-02-05 07:19:15 +08:00
|
|
|
return m_opaque_sp->GetResumeCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SBLaunchInfo::SetResumeCount(uint32_t c) {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD(void, SBLaunchInfo, SetResumeCount, (uint32_t), c);
|
|
|
|
|
2015-02-05 07:19:15 +08:00
|
|
|
m_opaque_sp->SetResumeCount(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SBLaunchInfo::AddCloseFileAction(int fd) {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD(bool, SBLaunchInfo, AddCloseFileAction, (int), fd);
|
|
|
|
|
2015-02-05 07:19:15 +08:00
|
|
|
return m_opaque_sp->AppendCloseFileAction(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SBLaunchInfo::AddDuplicateFileAction(int fd, int dup_fd) {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD(bool, SBLaunchInfo, AddDuplicateFileAction, (int, int), fd,
|
|
|
|
dup_fd);
|
|
|
|
|
2015-02-05 07:19:15 +08:00
|
|
|
return m_opaque_sp->AppendDuplicateFileAction(fd, dup_fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SBLaunchInfo::AddOpenFileAction(int fd, const char *path, bool read,
|
|
|
|
bool write) {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD(bool, SBLaunchInfo, AddOpenFileAction,
|
|
|
|
(int, const char *, bool, bool), fd, path, read, write);
|
|
|
|
|
2018-11-02 05:05:36 +08:00
|
|
|
return m_opaque_sp->AppendOpenFileAction(fd, FileSpec(path), read, write);
|
2015-02-05 07:19:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool SBLaunchInfo::AddSuppressFileAction(int fd, bool read, bool write) {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD(bool, SBLaunchInfo, AddSuppressFileAction,
|
|
|
|
(int, bool, bool), fd, read, write);
|
|
|
|
|
2015-02-05 07:19:15 +08:00
|
|
|
return m_opaque_sp->AppendSuppressFileAction(fd, read, write);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SBLaunchInfo::SetLaunchEventData(const char *data) {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD(void, SBLaunchInfo, SetLaunchEventData, (const char *),
|
|
|
|
data);
|
|
|
|
|
2015-02-05 07:19:15 +08:00
|
|
|
m_opaque_sp->SetLaunchEventData(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *SBLaunchInfo::GetLaunchEventData() const {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_CONST_NO_ARGS(const char *, SBLaunchInfo,
|
|
|
|
GetLaunchEventData);
|
|
|
|
|
2015-02-05 07:19:15 +08:00
|
|
|
return m_opaque_sp->GetLaunchEventData();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SBLaunchInfo::SetDetachOnError(bool enable) {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD(void, SBLaunchInfo, SetDetachOnError, (bool), enable);
|
|
|
|
|
2015-02-05 07:19:15 +08:00
|
|
|
m_opaque_sp->SetDetachOnError(enable);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SBLaunchInfo::GetDetachOnError() const {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBLaunchInfo, GetDetachOnError);
|
|
|
|
|
2015-02-05 07:19:15 +08:00
|
|
|
return m_opaque_sp->GetDetachOnError();
|
|
|
|
}
|
2019-03-20 01:13:13 +08:00
|
|
|
|
|
|
|
namespace lldb_private {
|
|
|
|
namespace repro {
|
|
|
|
|
|
|
|
template <>
|
|
|
|
void RegisterMethods<SBLaunchInfo>(Registry &R) {
|
|
|
|
LLDB_REGISTER_CONSTRUCTOR(SBLaunchInfo, (const char **));
|
2020-01-29 08:44:30 +08:00
|
|
|
LLDB_REGISTER_CONSTRUCTOR(SBLaunchInfo, (const lldb::SBLaunchInfo &));
|
2020-01-29 09:09:49 +08:00
|
|
|
LLDB_REGISTER_METHOD(SBLaunchInfo &,
|
2020-01-29 08:44:30 +08:00
|
|
|
SBLaunchInfo, operator=,(const lldb::SBLaunchInfo &));
|
2019-03-20 01:13:13 +08:00
|
|
|
LLDB_REGISTER_METHOD(lldb::pid_t, SBLaunchInfo, GetProcessID, ());
|
|
|
|
LLDB_REGISTER_METHOD(uint32_t, SBLaunchInfo, GetUserID, ());
|
|
|
|
LLDB_REGISTER_METHOD(uint32_t, SBLaunchInfo, GetGroupID, ());
|
|
|
|
LLDB_REGISTER_METHOD(bool, SBLaunchInfo, UserIDIsValid, ());
|
|
|
|
LLDB_REGISTER_METHOD(bool, SBLaunchInfo, GroupIDIsValid, ());
|
|
|
|
LLDB_REGISTER_METHOD(void, SBLaunchInfo, SetUserID, (uint32_t));
|
|
|
|
LLDB_REGISTER_METHOD(void, SBLaunchInfo, SetGroupID, (uint32_t));
|
|
|
|
LLDB_REGISTER_METHOD(lldb::SBFileSpec, SBLaunchInfo, GetExecutableFile, ());
|
|
|
|
LLDB_REGISTER_METHOD(void, SBLaunchInfo, SetExecutableFile,
|
|
|
|
(lldb::SBFileSpec, bool));
|
|
|
|
LLDB_REGISTER_METHOD(lldb::SBListener, SBLaunchInfo, GetListener, ());
|
|
|
|
LLDB_REGISTER_METHOD(void, SBLaunchInfo, SetListener, (lldb::SBListener &));
|
|
|
|
LLDB_REGISTER_METHOD(uint32_t, SBLaunchInfo, GetNumArguments, ());
|
|
|
|
LLDB_REGISTER_METHOD(const char *, SBLaunchInfo, GetArgumentAtIndex,
|
|
|
|
(uint32_t));
|
|
|
|
LLDB_REGISTER_METHOD(void, SBLaunchInfo, SetArguments,
|
|
|
|
(const char **, bool));
|
|
|
|
LLDB_REGISTER_METHOD(uint32_t, SBLaunchInfo, GetNumEnvironmentEntries, ());
|
|
|
|
LLDB_REGISTER_METHOD(const char *, SBLaunchInfo, GetEnvironmentEntryAtIndex,
|
|
|
|
(uint32_t));
|
|
|
|
LLDB_REGISTER_METHOD(void, SBLaunchInfo, SetEnvironmentEntries,
|
|
|
|
(const char **, bool));
|
|
|
|
LLDB_REGISTER_METHOD(void, SBLaunchInfo, Clear, ());
|
|
|
|
LLDB_REGISTER_METHOD_CONST(const char *, SBLaunchInfo, GetWorkingDirectory,
|
|
|
|
());
|
|
|
|
LLDB_REGISTER_METHOD(void, SBLaunchInfo, SetWorkingDirectory,
|
|
|
|
(const char *));
|
|
|
|
LLDB_REGISTER_METHOD(uint32_t, SBLaunchInfo, GetLaunchFlags, ());
|
|
|
|
LLDB_REGISTER_METHOD(void, SBLaunchInfo, SetLaunchFlags, (uint32_t));
|
|
|
|
LLDB_REGISTER_METHOD(const char *, SBLaunchInfo, GetProcessPluginName, ());
|
|
|
|
LLDB_REGISTER_METHOD(void, SBLaunchInfo, SetProcessPluginName,
|
|
|
|
(const char *));
|
|
|
|
LLDB_REGISTER_METHOD(const char *, SBLaunchInfo, GetShell, ());
|
|
|
|
LLDB_REGISTER_METHOD(void, SBLaunchInfo, SetShell, (const char *));
|
|
|
|
LLDB_REGISTER_METHOD(bool, SBLaunchInfo, GetShellExpandArguments, ());
|
|
|
|
LLDB_REGISTER_METHOD(void, SBLaunchInfo, SetShellExpandArguments, (bool));
|
|
|
|
LLDB_REGISTER_METHOD(uint32_t, SBLaunchInfo, GetResumeCount, ());
|
|
|
|
LLDB_REGISTER_METHOD(void, SBLaunchInfo, SetResumeCount, (uint32_t));
|
|
|
|
LLDB_REGISTER_METHOD(bool, SBLaunchInfo, AddCloseFileAction, (int));
|
|
|
|
LLDB_REGISTER_METHOD(bool, SBLaunchInfo, AddDuplicateFileAction,
|
|
|
|
(int, int));
|
|
|
|
LLDB_REGISTER_METHOD(bool, SBLaunchInfo, AddOpenFileAction,
|
|
|
|
(int, const char *, bool, bool));
|
|
|
|
LLDB_REGISTER_METHOD(bool, SBLaunchInfo, AddSuppressFileAction,
|
|
|
|
(int, bool, bool));
|
|
|
|
LLDB_REGISTER_METHOD(void, SBLaunchInfo, SetLaunchEventData,
|
|
|
|
(const char *));
|
|
|
|
LLDB_REGISTER_METHOD_CONST(const char *, SBLaunchInfo, GetLaunchEventData,
|
|
|
|
());
|
|
|
|
LLDB_REGISTER_METHOD(void, SBLaunchInfo, SetDetachOnError, (bool));
|
|
|
|
LLDB_REGISTER_METHOD_CONST(bool, SBLaunchInfo, GetDetachOnError, ());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|