forked from OSchip/llvm-project
Create basic SBEnvironment class
Summary: Inspired by https://reviews.llvm.org/D74636, I'm introducing a basic version of Environment in the API. More functionalities can be added as needed. Reviewers: labath, clayborg Subscribers: mgorny, lldb-commits, diazhector98 Tags: #lldb Differential Revision: https://reviews.llvm.org/D76111
This commit is contained in:
parent
576105c322
commit
2dec82652e
|
@ -21,6 +21,7 @@
|
||||||
#include "lldb/API/SBData.h"
|
#include "lldb/API/SBData.h"
|
||||||
#include "lldb/API/SBDebugger.h"
|
#include "lldb/API/SBDebugger.h"
|
||||||
#include "lldb/API/SBDeclaration.h"
|
#include "lldb/API/SBDeclaration.h"
|
||||||
|
#include "lldb/API/SBEnvironment.h"
|
||||||
#include "lldb/API/SBError.h"
|
#include "lldb/API/SBError.h"
|
||||||
#include "lldb/API/SBEvent.h"
|
#include "lldb/API/SBEvent.h"
|
||||||
#include "lldb/API/SBExecutionContext.h"
|
#include "lldb/API/SBExecutionContext.h"
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
//===-- SWIG Interface for SBEnvironment-------------------------*- C++ -*-===//
|
||||||
|
//
|
||||||
|
// 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
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
namespace lldb {
|
||||||
|
|
||||||
|
%feature("docstring",
|
||||||
|
"Represents the environment of a certain process.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
for entry in lldb.debugger.GetSelectedTarget().GetEnvironment().GetEntries():
|
||||||
|
print(entry)
|
||||||
|
|
||||||
|
") SBEnvironment;
|
||||||
|
class SBEnvironment {
|
||||||
|
public:
|
||||||
|
SBEnvironment ();
|
||||||
|
|
||||||
|
SBEnvironment (const lldb::SBEnvironment &rhs);
|
||||||
|
|
||||||
|
~SBEnvironment();
|
||||||
|
|
||||||
|
size_t GetNumValues();
|
||||||
|
|
||||||
|
const char *Get(const char *name);
|
||||||
|
|
||||||
|
const char *GetNameAtIndex(size_t index);
|
||||||
|
|
||||||
|
const char *GetValueAtIndex(size_t index);
|
||||||
|
|
||||||
|
SBStringList GetEntries();
|
||||||
|
|
||||||
|
void PutEntry(const char *name_and_value);
|
||||||
|
|
||||||
|
void SetEntries(const SBStringList &entries, bool append);
|
||||||
|
|
||||||
|
bool Set(const char *name, const char *value, bool overwrite);
|
||||||
|
|
||||||
|
bool Unset(const char *name);
|
||||||
|
|
||||||
|
void Clear();
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace lldb
|
|
@ -64,6 +64,12 @@ public:
|
||||||
void
|
void
|
||||||
SetEnvironmentEntries (const char **envp, bool append);
|
SetEnvironmentEntries (const char **envp, bool append);
|
||||||
|
|
||||||
|
void
|
||||||
|
SetEnvironment(const SBEnvironment &env, bool append);
|
||||||
|
|
||||||
|
SBEnvironment
|
||||||
|
GetEnvironment();
|
||||||
|
|
||||||
void
|
void
|
||||||
Clear ();
|
Clear ();
|
||||||
|
|
||||||
|
|
|
@ -194,6 +194,9 @@ public:
|
||||||
lldb::SBUnixSignals
|
lldb::SBUnixSignals
|
||||||
GetUnixSignals();
|
GetUnixSignals();
|
||||||
|
|
||||||
|
lldb::SBEnvironment
|
||||||
|
GetEnvironment();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace lldb
|
} // namespace lldb
|
||||||
|
|
|
@ -677,6 +677,9 @@ public:
|
||||||
lldb::SBBreakpoint
|
lldb::SBBreakpoint
|
||||||
BreakpointCreateByAddress (addr_t address);
|
BreakpointCreateByAddress (addr_t address);
|
||||||
|
|
||||||
|
lldb::SBEnvironment
|
||||||
|
GetEnvironment();
|
||||||
|
|
||||||
lldb::SBBreakpoint
|
lldb::SBBreakpoint
|
||||||
BreakpointCreateBySBAddress (SBAddress &sb_address);
|
BreakpointCreateBySBAddress (SBAddress &sb_address);
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
%include "./interface/SBDebugger.i"
|
%include "./interface/SBDebugger.i"
|
||||||
%include "./interface/SBDeclaration.i"
|
%include "./interface/SBDeclaration.i"
|
||||||
%include "./interface/SBError.i"
|
%include "./interface/SBError.i"
|
||||||
|
%include "./interface/SBEnvironment.i"
|
||||||
%include "./interface/SBEvent.i"
|
%include "./interface/SBEvent.i"
|
||||||
%include "./interface/SBExecutionContext.i"
|
%include "./interface/SBExecutionContext.i"
|
||||||
%include "./interface/SBExpressionOptions.i"
|
%include "./interface/SBExpressionOptions.i"
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include "lldb/API/SBDebugger.h"
|
#include "lldb/API/SBDebugger.h"
|
||||||
#include "lldb/API/SBDeclaration.h"
|
#include "lldb/API/SBDeclaration.h"
|
||||||
#include "lldb/API/SBDefines.h"
|
#include "lldb/API/SBDefines.h"
|
||||||
|
#include "lldb/API/SBEnvironment.h"
|
||||||
#include "lldb/API/SBError.h"
|
#include "lldb/API/SBError.h"
|
||||||
#include "lldb/API/SBEvent.h"
|
#include "lldb/API/SBEvent.h"
|
||||||
#include "lldb/API/SBExecutionContext.h"
|
#include "lldb/API/SBExecutionContext.h"
|
||||||
|
|
|
@ -35,6 +35,7 @@ class LLDB_API SBCompileUnit;
|
||||||
class LLDB_API SBData;
|
class LLDB_API SBData;
|
||||||
class LLDB_API SBDebugger;
|
class LLDB_API SBDebugger;
|
||||||
class LLDB_API SBDeclaration;
|
class LLDB_API SBDeclaration;
|
||||||
|
class LLDB_API SBEnvironment;
|
||||||
class LLDB_API SBError;
|
class LLDB_API SBError;
|
||||||
class LLDB_API SBEvent;
|
class LLDB_API SBEvent;
|
||||||
class LLDB_API SBEventList;
|
class LLDB_API SBEventList;
|
||||||
|
|
|
@ -0,0 +1,137 @@
|
||||||
|
//===-- SBEnvironment.h -----------------------------------------*- C++ -*-===//
|
||||||
|
//
|
||||||
|
// 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
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#ifndef LLDB_API_SBENVIRONMENT_H
|
||||||
|
#define LLDB_API_SBENVIRONMENT_H
|
||||||
|
|
||||||
|
#include "lldb/API/SBDefines.h"
|
||||||
|
|
||||||
|
namespace lldb {
|
||||||
|
|
||||||
|
class LLDB_API SBEnvironment {
|
||||||
|
public:
|
||||||
|
SBEnvironment();
|
||||||
|
|
||||||
|
SBEnvironment(const lldb::SBEnvironment &rhs);
|
||||||
|
|
||||||
|
~SBEnvironment();
|
||||||
|
|
||||||
|
lldb::SBEnvironment &operator=(const lldb::SBEnvironment &rhs);
|
||||||
|
|
||||||
|
/// Return the value of a given environment variable.
|
||||||
|
///
|
||||||
|
/// \param [in] name
|
||||||
|
/// The name of the environment variable.
|
||||||
|
///
|
||||||
|
/// \return
|
||||||
|
/// The value of the enviroment variable or null if not present.
|
||||||
|
/// If the environment variable has no value but is present, a valid
|
||||||
|
/// pointer to an empty string will be returned.
|
||||||
|
const char *Get(const char *name);
|
||||||
|
|
||||||
|
/// \return
|
||||||
|
/// The number of environment variables.
|
||||||
|
size_t GetNumValues();
|
||||||
|
|
||||||
|
/// Return the name of the environment variable at a given index from the
|
||||||
|
/// internal list of environment variables.
|
||||||
|
///
|
||||||
|
/// \param [in] index
|
||||||
|
/// The index of the environment variable in the internal list.
|
||||||
|
///
|
||||||
|
/// \return
|
||||||
|
/// The name at the given index or null if the index is invalid.
|
||||||
|
const char *GetNameAtIndex(size_t index);
|
||||||
|
|
||||||
|
/// Return the value of the environment variable at a given index from the
|
||||||
|
/// internal list of environment variables.
|
||||||
|
///
|
||||||
|
/// \param [in] index
|
||||||
|
/// The index of the environment variable in the internal list.
|
||||||
|
///
|
||||||
|
/// \return
|
||||||
|
/// The value at the given index or null if the index is invalid.
|
||||||
|
/// If the environment variable has no value but is present, a valid
|
||||||
|
/// pointer to an empty string will be returned.
|
||||||
|
const char *GetValueAtIndex(size_t index);
|
||||||
|
|
||||||
|
/// Return all environment variables contained in this object. Each variable
|
||||||
|
/// is returned as a string with the following format
|
||||||
|
/// name=value
|
||||||
|
///
|
||||||
|
/// \return
|
||||||
|
/// Return an lldb::SBStringList object with the environment variables.
|
||||||
|
SBStringList GetEntries();
|
||||||
|
|
||||||
|
/// Add or replace an existing environment variable. The input must be a
|
||||||
|
/// string with the format
|
||||||
|
/// name=value
|
||||||
|
///
|
||||||
|
/// \param [in] name_and_value
|
||||||
|
/// The entry to set which conforms to the format mentioned above.
|
||||||
|
void PutEntry(const char *name_and_value);
|
||||||
|
|
||||||
|
/// Update this object with the given environment variables. The input is a
|
||||||
|
/// list of entries with the same format required by SBEnvironment::PutEntry.
|
||||||
|
///
|
||||||
|
/// If append is false, the provided environment will replace the existing
|
||||||
|
/// environment. Otherwise, existing values will be updated of left untouched
|
||||||
|
/// accordingly.
|
||||||
|
///
|
||||||
|
/// \param [in] entries
|
||||||
|
/// The environment variable entries.
|
||||||
|
///
|
||||||
|
/// \param [in] append
|
||||||
|
/// Flag that controls whether to replace the existing environment.
|
||||||
|
void SetEntries(const SBStringList &entries, bool append);
|
||||||
|
|
||||||
|
/// Set the value of a given environment variable.
|
||||||
|
/// If the variable exists, its value is updated only if overwrite is true.
|
||||||
|
///
|
||||||
|
/// \param [in] name
|
||||||
|
/// The name of the environment variable to set.
|
||||||
|
///
|
||||||
|
/// \param [in] value
|
||||||
|
/// The value of the environment variable to set.
|
||||||
|
///
|
||||||
|
/// \param [in] overwrite
|
||||||
|
/// Flag that indicates whether to overwrite an existing environment
|
||||||
|
/// variable.
|
||||||
|
///
|
||||||
|
/// \return
|
||||||
|
/// Return whether the variable was added or modified.
|
||||||
|
bool Set(const char *name, const char *value, bool overwrite);
|
||||||
|
|
||||||
|
/// Unset an environment variable if exists.
|
||||||
|
///
|
||||||
|
/// \param [in] name
|
||||||
|
/// The name of the environment variable to unset.
|
||||||
|
///
|
||||||
|
/// \return
|
||||||
|
/// Return whether a variable was actually unset.
|
||||||
|
bool Unset(const char *name);
|
||||||
|
|
||||||
|
/// Delete all the environment variables.
|
||||||
|
void Clear();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
friend class SBPlatform;
|
||||||
|
friend class SBTarget;
|
||||||
|
friend class SBLaunchInfo;
|
||||||
|
|
||||||
|
SBEnvironment(lldb_private::Environment rhs);
|
||||||
|
|
||||||
|
lldb_private::Environment &ref() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::unique_ptr<lldb_private::Environment> m_opaque_up;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace lldb
|
||||||
|
|
||||||
|
#endif // LLDB_API_SBENVIRONMENT_H
|
|
@ -94,8 +94,41 @@ public:
|
||||||
|
|
||||||
const char *GetEnvironmentEntryAtIndex(uint32_t idx);
|
const char *GetEnvironmentEntryAtIndex(uint32_t idx);
|
||||||
|
|
||||||
|
/// Update this object with the given environment variables.
|
||||||
|
///
|
||||||
|
/// If append is false, the provided environment will replace the existing
|
||||||
|
/// environment. Otherwise, existing values will be updated of left untouched
|
||||||
|
/// accordingly.
|
||||||
|
///
|
||||||
|
/// \param [in] envp
|
||||||
|
/// The new environment variables as a list of strings with the following
|
||||||
|
/// format
|
||||||
|
/// name=value
|
||||||
|
///
|
||||||
|
/// \param [in] append
|
||||||
|
/// Flag that controls whether to replace the existing environment.
|
||||||
void SetEnvironmentEntries(const char **envp, bool append);
|
void SetEnvironmentEntries(const char **envp, bool append);
|
||||||
|
|
||||||
|
/// Update this object with the given environment variables.
|
||||||
|
///
|
||||||
|
/// If append is false, the provided environment will replace the existing
|
||||||
|
/// environment. Otherwise, existing values will be updated of left untouched
|
||||||
|
/// accordingly.
|
||||||
|
///
|
||||||
|
/// \param [in] env
|
||||||
|
/// The new environment variables.
|
||||||
|
///
|
||||||
|
/// \param [in] append
|
||||||
|
/// Flag that controls whether to replace the existing environment.
|
||||||
|
void SetEnvironment(const SBEnvironment &env, bool append);
|
||||||
|
|
||||||
|
/// Return the environment variables of this object.
|
||||||
|
///
|
||||||
|
/// \return
|
||||||
|
/// An lldb::SBEnvironment object which is a copy of the SBLaunchInfo's
|
||||||
|
/// environment.
|
||||||
|
SBEnvironment GetEnvironment();
|
||||||
|
|
||||||
void Clear();
|
void Clear();
|
||||||
|
|
||||||
const char *GetWorkingDirectory() const;
|
const char *GetWorkingDirectory() const;
|
||||||
|
|
|
@ -154,6 +154,14 @@ public:
|
||||||
|
|
||||||
SBUnixSignals GetUnixSignals() const;
|
SBUnixSignals GetUnixSignals() const;
|
||||||
|
|
||||||
|
/// Return the environment variables of the remote platform connection
|
||||||
|
/// process.
|
||||||
|
///
|
||||||
|
/// \return
|
||||||
|
/// An lldb::SBEnvironment object which is a copy of the platform's
|
||||||
|
/// enviroment.
|
||||||
|
SBEnvironment GetEnvironment();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
friend class SBDebugger;
|
friend class SBDebugger;
|
||||||
friend class SBTarget;
|
friend class SBTarget;
|
||||||
|
|
|
@ -94,6 +94,15 @@ public:
|
||||||
/// A platform object.
|
/// A platform object.
|
||||||
lldb::SBPlatform GetPlatform();
|
lldb::SBPlatform GetPlatform();
|
||||||
|
|
||||||
|
/// Return the environment variables that would be used to launch a new
|
||||||
|
/// process.
|
||||||
|
///
|
||||||
|
/// \return
|
||||||
|
/// An lldb::SBEnvironment object which is a copy of the target's
|
||||||
|
/// environment.
|
||||||
|
|
||||||
|
SBEnvironment GetEnvironment();
|
||||||
|
|
||||||
/// Install any binaries that need to be installed.
|
/// Install any binaries that need to be installed.
|
||||||
///
|
///
|
||||||
/// This function does nothing when debugging on the host system.
|
/// This function does nothing when debugging on the host system.
|
||||||
|
|
|
@ -50,6 +50,7 @@ public:
|
||||||
using Base::erase;
|
using Base::erase;
|
||||||
using Base::find;
|
using Base::find;
|
||||||
using Base::insert;
|
using Base::insert;
|
||||||
|
using Base::insert_or_assign;
|
||||||
using Base::lookup;
|
using Base::lookup;
|
||||||
using Base::size;
|
using Base::size;
|
||||||
using Base::try_emplace;
|
using Base::try_emplace;
|
||||||
|
|
|
@ -76,6 +76,7 @@ class DynamicCheckerFunctions;
|
||||||
class DynamicLoader;
|
class DynamicLoader;
|
||||||
class Editline;
|
class Editline;
|
||||||
class EmulateInstruction;
|
class EmulateInstruction;
|
||||||
|
class Environment;
|
||||||
class EvaluateExpressionOptions;
|
class EvaluateExpressionOptions;
|
||||||
class Event;
|
class Event;
|
||||||
class EventData;
|
class EventData;
|
||||||
|
|
|
@ -35,6 +35,7 @@ add_lldb_library(liblldb SHARED ${option_framework}
|
||||||
SBData.cpp
|
SBData.cpp
|
||||||
SBDebugger.cpp
|
SBDebugger.cpp
|
||||||
SBDeclaration.cpp
|
SBDeclaration.cpp
|
||||||
|
SBEnvironment.cpp
|
||||||
SBError.cpp
|
SBError.cpp
|
||||||
SBEvent.cpp
|
SBEvent.cpp
|
||||||
SBExecutionContext.cpp
|
SBExecutionContext.cpp
|
||||||
|
|
|
@ -0,0 +1,147 @@
|
||||||
|
//===-- SBEnvironment.cpp -------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// 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
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#include "lldb/API/SBEnvironment.h"
|
||||||
|
#include "SBReproducerPrivate.h"
|
||||||
|
#include "Utils.h"
|
||||||
|
#include "lldb/API/SBStringList.h"
|
||||||
|
#include "lldb/Utility/Environment.h"
|
||||||
|
|
||||||
|
using namespace lldb;
|
||||||
|
using namespace lldb_private;
|
||||||
|
|
||||||
|
SBEnvironment::SBEnvironment() : m_opaque_up(new Environment()) {
|
||||||
|
LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBEnvironment);
|
||||||
|
}
|
||||||
|
|
||||||
|
SBEnvironment::SBEnvironment(const SBEnvironment &rhs)
|
||||||
|
: m_opaque_up(clone(rhs.m_opaque_up)) {
|
||||||
|
LLDB_RECORD_CONSTRUCTOR(SBEnvironment, (const lldb::SBEnvironment &), rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
SBEnvironment::SBEnvironment(Environment rhs)
|
||||||
|
: m_opaque_up(new Environment(std::move(rhs))) {}
|
||||||
|
|
||||||
|
SBEnvironment::~SBEnvironment() = default;
|
||||||
|
|
||||||
|
SBEnvironment &SBEnvironment::operator=(const SBEnvironment &rhs) {
|
||||||
|
LLDB_RECORD_METHOD(lldb::SBEnvironment &,
|
||||||
|
SBEnvironment, operator=,(const lldb::SBEnvironment &),
|
||||||
|
rhs);
|
||||||
|
|
||||||
|
if (this != &rhs)
|
||||||
|
m_opaque_up = clone(rhs.m_opaque_up);
|
||||||
|
return LLDB_RECORD_RESULT(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t SBEnvironment::GetNumValues() {
|
||||||
|
LLDB_RECORD_METHOD_NO_ARGS(size_t, SBEnvironment, GetNumValues);
|
||||||
|
return LLDB_RECORD_RESULT(m_opaque_up->size());
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *SBEnvironment::Get(const char *name) {
|
||||||
|
LLDB_RECORD_METHOD(const char *, SBEnvironment, Get, (const char *), name);
|
||||||
|
auto entry = m_opaque_up->find(name);
|
||||||
|
if (entry == m_opaque_up->end())
|
||||||
|
return LLDB_RECORD_RESULT(nullptr);
|
||||||
|
return LLDB_RECORD_RESULT(ConstString(entry->second).AsCString(""));
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *SBEnvironment::GetNameAtIndex(size_t index) {
|
||||||
|
LLDB_RECORD_METHOD(const char *, SBEnvironment, GetNameAtIndex, (size_t),
|
||||||
|
index);
|
||||||
|
if (index >= GetNumValues())
|
||||||
|
return LLDB_RECORD_RESULT(nullptr);
|
||||||
|
return LLDB_RECORD_RESULT(
|
||||||
|
ConstString(std::next(m_opaque_up->begin(), index)->first())
|
||||||
|
.AsCString(""));
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *SBEnvironment::GetValueAtIndex(size_t index) {
|
||||||
|
LLDB_RECORD_METHOD(const char *, SBEnvironment, GetValueAtIndex, (size_t),
|
||||||
|
index);
|
||||||
|
if (index < 0 || index >= GetNumValues())
|
||||||
|
return LLDB_RECORD_RESULT(nullptr);
|
||||||
|
return LLDB_RECORD_RESULT(
|
||||||
|
ConstString(std::next(m_opaque_up->begin(), index)->second)
|
||||||
|
.AsCString(""));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SBEnvironment::Set(const char *name, const char *value, bool overwrite) {
|
||||||
|
LLDB_RECORD_METHOD(bool, SBEnvironment, Set,
|
||||||
|
(const char *, const char *, bool), name, value,
|
||||||
|
overwrite);
|
||||||
|
if (overwrite) {
|
||||||
|
m_opaque_up->insert_or_assign(name, std::string(value));
|
||||||
|
return LLDB_RECORD_RESULT(true);
|
||||||
|
}
|
||||||
|
return LLDB_RECORD_RESULT(
|
||||||
|
m_opaque_up->try_emplace(name, std::string(value)).second);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SBEnvironment::Unset(const char *name) {
|
||||||
|
LLDB_RECORD_METHOD(bool, SBEnvironment, Unset, (const char *), name);
|
||||||
|
return LLDB_RECORD_RESULT(m_opaque_up->erase(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
SBStringList SBEnvironment::GetEntries() {
|
||||||
|
LLDB_RECORD_METHOD_NO_ARGS(lldb::SBStringList, SBEnvironment, GetEntries);
|
||||||
|
SBStringList entries;
|
||||||
|
for (const auto &KV : *m_opaque_up) {
|
||||||
|
entries.AppendString(Environment::compose(KV).c_str());
|
||||||
|
}
|
||||||
|
return LLDB_RECORD_RESULT(entries);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SBEnvironment::PutEntry(const char *name_and_value) {
|
||||||
|
LLDB_RECORD_METHOD(void, SBEnvironment, PutEntry, (const char *),
|
||||||
|
name_and_value);
|
||||||
|
auto split = llvm::StringRef(name_and_value).split('=');
|
||||||
|
m_opaque_up->insert_or_assign(split.first.str(), split.second.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
void SBEnvironment::SetEntries(const SBStringList &entries, bool append) {
|
||||||
|
LLDB_RECORD_METHOD(void, SBEnvironment, SetEntries,
|
||||||
|
(const SBStringList &, bool), entries, append);
|
||||||
|
if (!append)
|
||||||
|
m_opaque_up->clear();
|
||||||
|
for (size_t i = 0; i < entries.GetSize(); i++) {
|
||||||
|
PutEntry(entries.GetStringAtIndex(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SBEnvironment::Clear() {
|
||||||
|
LLDB_RECORD_METHOD_NO_ARGS(void, SBEnvironment, Clear);
|
||||||
|
m_opaque_up->clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
Environment &SBEnvironment::ref() const { return *m_opaque_up; }
|
||||||
|
|
||||||
|
namespace lldb_private {
|
||||||
|
namespace repro {
|
||||||
|
|
||||||
|
template <> void RegisterMethods<SBEnvironment>(Registry &R) {
|
||||||
|
LLDB_REGISTER_CONSTRUCTOR(SBEnvironment, ());
|
||||||
|
LLDB_REGISTER_CONSTRUCTOR(SBEnvironment, (const lldb::SBEnvironment &));
|
||||||
|
LLDB_REGISTER_METHOD(lldb::SBEnvironment &,
|
||||||
|
SBEnvironment, operator=,(const lldb::SBEnvironment &));
|
||||||
|
LLDB_REGISTER_METHOD(size_t, SBEnvironment, GetNumValues, ());
|
||||||
|
LLDB_REGISTER_METHOD(const char *, SBEnvironment, GetNameAtIndex, (size_t));
|
||||||
|
LLDB_REGISTER_METHOD(const char *, SBEnvironment, GetValueAtIndex, (size_t));
|
||||||
|
LLDB_REGISTER_METHOD(const char *, SBEnvironment, Get, (const char *));
|
||||||
|
LLDB_REGISTER_METHOD(bool, SBEnvironment, Set,
|
||||||
|
(const char *, const char *, bool));
|
||||||
|
LLDB_REGISTER_METHOD(bool, SBEnvironment, Unset, (const char *));
|
||||||
|
LLDB_REGISTER_METHOD(lldb::SBStringList, SBEnvironment, GetEntries, ());
|
||||||
|
LLDB_REGISTER_METHOD(void, SBEnvironment, PutEntry, (const char *));
|
||||||
|
LLDB_REGISTER_METHOD(void, SBEnvironment, SetEntries,
|
||||||
|
(const SBStringList &, bool));
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace repro
|
||||||
|
} // namespace lldb_private
|
|
@ -9,6 +9,7 @@
|
||||||
#include "lldb/API/SBLaunchInfo.h"
|
#include "lldb/API/SBLaunchInfo.h"
|
||||||
#include "SBReproducerPrivate.h"
|
#include "SBReproducerPrivate.h"
|
||||||
|
|
||||||
|
#include "lldb/API/SBEnvironment.h"
|
||||||
#include "lldb/API/SBFileSpec.h"
|
#include "lldb/API/SBFileSpec.h"
|
||||||
#include "lldb/API/SBListener.h"
|
#include "lldb/API/SBListener.h"
|
||||||
#include "lldb/Host/ProcessLaunchInfo.h"
|
#include "lldb/Host/ProcessLaunchInfo.h"
|
||||||
|
@ -182,15 +183,26 @@ const char *SBLaunchInfo::GetEnvironmentEntryAtIndex(uint32_t idx) {
|
||||||
void SBLaunchInfo::SetEnvironmentEntries(const char **envp, bool append) {
|
void SBLaunchInfo::SetEnvironmentEntries(const char **envp, bool append) {
|
||||||
LLDB_RECORD_METHOD(void, SBLaunchInfo, SetEnvironmentEntries,
|
LLDB_RECORD_METHOD(void, SBLaunchInfo, SetEnvironmentEntries,
|
||||||
(const char **, bool), envp, append);
|
(const char **, bool), envp, append);
|
||||||
|
SetEnvironment(SBEnvironment(Environment(envp)), append);
|
||||||
|
}
|
||||||
|
|
||||||
Environment env(envp);
|
void SBLaunchInfo::SetEnvironment(const SBEnvironment &env, bool append) {
|
||||||
|
LLDB_RECORD_METHOD(void, SBLaunchInfo, SetEnvironment,
|
||||||
|
(const lldb::SBEnvironment &, bool), env, append);
|
||||||
|
Environment &refEnv = env.ref();
|
||||||
if (append)
|
if (append)
|
||||||
m_opaque_sp->GetEnvironment().insert(env.begin(), env.end());
|
m_opaque_sp->GetEnvironment().insert(refEnv.begin(), refEnv.end());
|
||||||
else
|
else
|
||||||
m_opaque_sp->GetEnvironment() = env;
|
m_opaque_sp->GetEnvironment() = refEnv;
|
||||||
m_opaque_sp->RegenerateEnvp();
|
m_opaque_sp->RegenerateEnvp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SBEnvironment SBLaunchInfo::GetEnvironment() {
|
||||||
|
LLDB_RECORD_METHOD_NO_ARGS(lldb::SBEnvironment, SBLaunchInfo, GetEnvironment);
|
||||||
|
return LLDB_RECORD_RESULT(
|
||||||
|
SBEnvironment(Environment(m_opaque_sp->GetEnvironment())));
|
||||||
|
}
|
||||||
|
|
||||||
void SBLaunchInfo::Clear() {
|
void SBLaunchInfo::Clear() {
|
||||||
LLDB_RECORD_METHOD_NO_ARGS(void, SBLaunchInfo, Clear);
|
LLDB_RECORD_METHOD_NO_ARGS(void, SBLaunchInfo, Clear);
|
||||||
|
|
||||||
|
@ -390,6 +402,9 @@ void RegisterMethods<SBLaunchInfo>(Registry &R) {
|
||||||
());
|
());
|
||||||
LLDB_REGISTER_METHOD(void, SBLaunchInfo, SetDetachOnError, (bool));
|
LLDB_REGISTER_METHOD(void, SBLaunchInfo, SetDetachOnError, (bool));
|
||||||
LLDB_REGISTER_METHOD_CONST(bool, SBLaunchInfo, GetDetachOnError, ());
|
LLDB_REGISTER_METHOD_CONST(bool, SBLaunchInfo, GetDetachOnError, ());
|
||||||
|
LLDB_REGISTER_METHOD(void, SBLaunchInfo, SetEnvironment,
|
||||||
|
(const lldb::SBEnvironment &, bool));
|
||||||
|
LLDB_REGISTER_METHOD(lldb::SBEnvironment, SBLaunchInfo, GetEnvironment, ());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,9 +8,11 @@
|
||||||
|
|
||||||
#include "lldb/API/SBPlatform.h"
|
#include "lldb/API/SBPlatform.h"
|
||||||
#include "SBReproducerPrivate.h"
|
#include "SBReproducerPrivate.h"
|
||||||
|
#include "lldb/API/SBEnvironment.h"
|
||||||
#include "lldb/API/SBError.h"
|
#include "lldb/API/SBError.h"
|
||||||
#include "lldb/API/SBFileSpec.h"
|
#include "lldb/API/SBFileSpec.h"
|
||||||
#include "lldb/API/SBLaunchInfo.h"
|
#include "lldb/API/SBLaunchInfo.h"
|
||||||
|
#include "lldb/API/SBPlatform.h"
|
||||||
#include "lldb/API/SBUnixSignals.h"
|
#include "lldb/API/SBUnixSignals.h"
|
||||||
#include "lldb/Host/File.h"
|
#include "lldb/Host/File.h"
|
||||||
#include "lldb/Target/Platform.h"
|
#include "lldb/Target/Platform.h"
|
||||||
|
@ -649,6 +651,17 @@ SBUnixSignals SBPlatform::GetUnixSignals() const {
|
||||||
return LLDB_RECORD_RESULT(SBUnixSignals());
|
return LLDB_RECORD_RESULT(SBUnixSignals());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SBEnvironment SBPlatform::GetEnvironment() {
|
||||||
|
LLDB_RECORD_METHOD_NO_ARGS(lldb::SBEnvironment, SBPlatform, GetEnvironment);
|
||||||
|
PlatformSP platform_sp(GetSP());
|
||||||
|
|
||||||
|
if (platform_sp) {
|
||||||
|
return LLDB_RECORD_RESULT(SBEnvironment(platform_sp->GetEnvironment()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return LLDB_RECORD_RESULT(SBEnvironment());
|
||||||
|
}
|
||||||
|
|
||||||
namespace lldb_private {
|
namespace lldb_private {
|
||||||
namespace repro {
|
namespace repro {
|
||||||
|
|
||||||
|
@ -740,6 +753,7 @@ void RegisterMethods<SBPlatform>(Registry &R) {
|
||||||
(const char *));
|
(const char *));
|
||||||
LLDB_REGISTER_METHOD(lldb::SBError, SBPlatform, SetFilePermissions,
|
LLDB_REGISTER_METHOD(lldb::SBError, SBPlatform, SetFilePermissions,
|
||||||
(const char *, uint32_t));
|
(const char *, uint32_t));
|
||||||
|
LLDB_REGISTER_METHOD(lldb::SBEnvironment, SBPlatform, GetEnvironment, ());
|
||||||
LLDB_REGISTER_METHOD_CONST(lldb::SBUnixSignals, SBPlatform, GetUnixSignals,
|
LLDB_REGISTER_METHOD_CONST(lldb::SBUnixSignals, SBPlatform, GetUnixSignals,
|
||||||
());
|
());
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
|
|
||||||
#include "lldb/API/SBBreakpoint.h"
|
#include "lldb/API/SBBreakpoint.h"
|
||||||
#include "lldb/API/SBDebugger.h"
|
#include "lldb/API/SBDebugger.h"
|
||||||
|
#include "lldb/API/SBEnvironment.h"
|
||||||
#include "lldb/API/SBEvent.h"
|
#include "lldb/API/SBEvent.h"
|
||||||
#include "lldb/API/SBExpressionOptions.h"
|
#include "lldb/API/SBExpressionOptions.h"
|
||||||
#include "lldb/API/SBFileSpec.h"
|
#include "lldb/API/SBFileSpec.h"
|
||||||
|
@ -2388,6 +2389,17 @@ void SBTarget::SetLaunchInfo(const lldb::SBLaunchInfo &launch_info) {
|
||||||
m_opaque_sp->SetProcessLaunchInfo(launch_info.ref());
|
m_opaque_sp->SetProcessLaunchInfo(launch_info.ref());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SBEnvironment SBTarget::GetEnvironment() {
|
||||||
|
LLDB_RECORD_METHOD_NO_ARGS(lldb::SBEnvironment, SBTarget, GetEnvironment);
|
||||||
|
TargetSP target_sp(GetSP());
|
||||||
|
|
||||||
|
if (target_sp) {
|
||||||
|
return LLDB_RECORD_RESULT(SBEnvironment(target_sp->GetEnvironment()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return LLDB_RECORD_RESULT(SBEnvironment());
|
||||||
|
}
|
||||||
|
|
||||||
namespace lldb_private {
|
namespace lldb_private {
|
||||||
namespace repro {
|
namespace repro {
|
||||||
|
|
||||||
|
@ -2643,6 +2655,7 @@ void RegisterMethods<SBTarget>(Registry &R) {
|
||||||
LLDB_REGISTER_METHOD(lldb::SBInstructionList, SBTarget,
|
LLDB_REGISTER_METHOD(lldb::SBInstructionList, SBTarget,
|
||||||
GetInstructionsWithFlavor,
|
GetInstructionsWithFlavor,
|
||||||
(lldb::addr_t, const char *, const void *, size_t));
|
(lldb::addr_t, const char *, const void *, size_t));
|
||||||
|
LLDB_REGISTER_METHOD(lldb::SBEnvironment, SBTarget, GetEnvironment, ());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,125 @@
|
||||||
|
"""Test the SBEnvironment APIs."""
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
from math import fabs
|
||||||
|
import lldb
|
||||||
|
from lldbsuite.test.decorators import *
|
||||||
|
from lldbsuite.test.lldbtest import *
|
||||||
|
from lldbsuite.test import lldbutil
|
||||||
|
|
||||||
|
class SBEnvironmentAPICase(TestBase):
|
||||||
|
|
||||||
|
mydir = TestBase.compute_mydir(__file__)
|
||||||
|
NO_DEBUG_INFO_TESTCASE = True
|
||||||
|
|
||||||
|
# We use this function to test both kind of accessors:
|
||||||
|
# . Get*AtIndex and GetEntries
|
||||||
|
def assertEqualEntries(self, env, entries):
|
||||||
|
self.assertEqual(env.GetNumValues(), len(entries))
|
||||||
|
for i in range(env.GetNumValues()):
|
||||||
|
name = env.GetNameAtIndex(i)
|
||||||
|
value = env.GetValueAtIndex(i)
|
||||||
|
self.assertIn(name + "=" + value, entries)
|
||||||
|
|
||||||
|
entries = env.GetEntries()
|
||||||
|
self.assertEqual(entries.GetSize(), len(entries))
|
||||||
|
for i in range(entries.GetSize()):
|
||||||
|
(name, value) = entries.GetStringAtIndex(i).split("=")
|
||||||
|
self.assertIn(name + "=" + value, entries)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@add_test_categories(['pyapi'])
|
||||||
|
def test_platform_environment(self):
|
||||||
|
env = self.dbg.GetSelectedPlatform().GetEnvironment()
|
||||||
|
# We assume at least PATH is set
|
||||||
|
self.assertNotEqual(env.Get("PATH"), None)
|
||||||
|
|
||||||
|
|
||||||
|
@add_test_categories(['pyapi'])
|
||||||
|
def test_launch_info(self):
|
||||||
|
target = self.dbg.CreateTarget("")
|
||||||
|
launch_info = target.GetLaunchInfo()
|
||||||
|
env = launch_info.GetEnvironment()
|
||||||
|
self.assertEqual(env.GetNumValues(), 0)
|
||||||
|
|
||||||
|
env.Set("FOO", "bar", overwrite=True)
|
||||||
|
self.assertEqual(env.GetNumValues(), 1)
|
||||||
|
|
||||||
|
# Make sure we only modify the copy of the launchInfo's environment
|
||||||
|
self.assertEqual(launch_info.GetEnvironment().GetNumValues(), 0)
|
||||||
|
|
||||||
|
launch_info.SetEnvironment(env, append=True)
|
||||||
|
self.assertEqual(launch_info.GetEnvironment().GetNumValues(), 1)
|
||||||
|
|
||||||
|
# Make sure we can replace the launchInfo's environment
|
||||||
|
env.Clear()
|
||||||
|
env.Set("BAR", "foo", overwrite=True)
|
||||||
|
env.PutEntry("X=y")
|
||||||
|
launch_info.SetEnvironment(env, append=False)
|
||||||
|
self.assertEqualEntries(launch_info.GetEnvironment(), ["BAR=foo", "X=y"])
|
||||||
|
|
||||||
|
|
||||||
|
@add_test_categories(['pyapi'])
|
||||||
|
def test_target_environment(self):
|
||||||
|
env = self.dbg.GetSelectedTarget().GetEnvironment()
|
||||||
|
# There is no target, so env should be empty
|
||||||
|
self.assertEqual(env.GetNumValues(), 0)
|
||||||
|
self.assertEqual(env.Get("PATH"), None)
|
||||||
|
|
||||||
|
target = self.dbg.CreateTarget("")
|
||||||
|
env = target.GetEnvironment()
|
||||||
|
path = env.Get("PATH")
|
||||||
|
# Now there's a target, so at least PATH should exist
|
||||||
|
self.assertNotEqual(path, None)
|
||||||
|
|
||||||
|
# Make sure we are getting a copy by modifying the env we just got
|
||||||
|
env.PutEntry("PATH=#" + path)
|
||||||
|
self.assertEqual(target.GetEnvironment().Get("PATH"), path)
|
||||||
|
|
||||||
|
@add_test_categories(['pyapi'])
|
||||||
|
def test_creating_and_modifying_environment(self):
|
||||||
|
env = lldb.SBEnvironment()
|
||||||
|
|
||||||
|
self.assertEqual(env.Get("FOO"), None)
|
||||||
|
self.assertEqual(env.Get("BAR"), None)
|
||||||
|
|
||||||
|
# We also test empty values
|
||||||
|
self.assertTrue(env.Set("FOO", "", overwrite=False))
|
||||||
|
env.Set("BAR", "foo", overwrite=False)
|
||||||
|
|
||||||
|
self.assertEqual(env.Get("FOO"), "")
|
||||||
|
self.assertEqual(env.Get("BAR"), "foo")
|
||||||
|
|
||||||
|
self.assertEqual(env.GetNumValues(), 2)
|
||||||
|
|
||||||
|
self.assertEqualEntries(env, ["FOO=", "BAR=foo"])
|
||||||
|
|
||||||
|
# Make sure modifications work
|
||||||
|
self.assertFalse(env.Set("FOO", "bar", overwrite=False))
|
||||||
|
self.assertEqual(env.Get("FOO"), "")
|
||||||
|
|
||||||
|
env.PutEntry("FOO=bar")
|
||||||
|
self.assertEqual(env.Get("FOO"), "bar")
|
||||||
|
|
||||||
|
self.assertEqualEntries(env, ["FOO=bar", "BAR=foo"])
|
||||||
|
|
||||||
|
# Make sure we can unset
|
||||||
|
self.assertTrue(env.Unset("FOO"))
|
||||||
|
self.assertFalse(env.Unset("FOO"))
|
||||||
|
self.assertEqual(env.Get("FOO"), None)
|
||||||
|
|
||||||
|
# Test SetEntries
|
||||||
|
entries = lldb.SBStringList()
|
||||||
|
entries.AppendList(["X=x", "Y=y"], 2)
|
||||||
|
|
||||||
|
env.SetEntries(entries, append=True)
|
||||||
|
self.assertEqualEntries(env, ["BAR=foo", "X=x", "Y=y"])
|
||||||
|
|
||||||
|
env.SetEntries(entries, append=False)
|
||||||
|
self.assertEqualEntries(env, ["X=x", "Y=y"])
|
||||||
|
|
||||||
|
# Test clear
|
||||||
|
env.Clear()
|
||||||
|
self.assertEqualEntries(env, [])
|
Loading…
Reference in New Issue