Skip to content

Commit 15fdd40

Browse files
committed
[lldb] Allow for getting the current/inherited environment separately
This is a partial cherry-pick of 82507f1
1 parent ccdf744 commit 15fdd40

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

lldb/include/lldb/Target/Target.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,16 @@ class TargetProperties : public Properties {
135135

136136
void SetRunArguments(const Args &args);
137137

138+
// Get the whole environment including the platform inherited environment and
139+
// the target specific environment, excluding the unset environment variables.
138140
Environment GetEnvironment() const;
141+
// Get the platform inherited environment, excluding the unset environment
142+
// variables.
143+
Environment GetInheritedEnvironment() const;
144+
// Get the target specific environment only, without the platform inherited
145+
// environment.
146+
Environment GetTargetEnvironment() const;
147+
// Set the target specific environment.
139148
void SetEnvironment(Environment env);
140149

141150
bool GetSkipPrologue() const;

lldb/source/Target/Target.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4341,6 +4341,46 @@ Environment TargetProperties::GetEnvironment() const {
43414341
return ComputeEnvironment();
43424342
}
43434343

4344+
Environment TargetProperties::GetInheritedEnvironment() const {
4345+
Environment environment;
4346+
4347+
if (m_target == nullptr)
4348+
return environment;
4349+
4350+
if (!m_collection_sp->GetPropertyAtIndexAsBoolean(
4351+
nullptr, ePropertyInheritEnv,
4352+
g_target_properties[ePropertyInheritEnv].default_uint_value != 0))
4353+
return environment;
4354+
4355+
PlatformSP platform_sp = m_target->GetPlatform();
4356+
if (platform_sp == nullptr)
4357+
return environment;
4358+
4359+
Environment platform_environment = platform_sp->GetEnvironment();
4360+
for (const auto &KV : platform_environment)
4361+
environment[KV.first()] = KV.second;
4362+
4363+
Args property_unset_environment;
4364+
m_collection_sp->GetPropertyAtIndexAsArgs(nullptr, ePropertyUnsetEnvVars,
4365+
property_unset_environment);
4366+
for (const auto &var : property_unset_environment)
4367+
environment.erase(var.ref());
4368+
4369+
return environment;
4370+
}
4371+
4372+
Environment TargetProperties::GetTargetEnvironment() const {
4373+
Args property_environment;
4374+
m_collection_sp->GetPropertyAtIndexAsArgs(nullptr, ePropertyEnvVars,
4375+
property_environment);
4376+
Environment environment;
4377+
for (const auto &KV : Environment(property_environment))
4378+
environment[KV.first()] = KV.second;
4379+
4380+
return environment;
4381+
}
4382+
4383+
43444384
void TargetProperties::SetEnvironment(Environment env) {
43454385
// TODO: Get rid of the Args intermediate step
43464386
const uint32_t idx = ePropertyEnvVars;

0 commit comments

Comments
 (0)