1*5ffd83dbSDimitry Andric //===-- SBEnvironment.h -----------------------------------------*- C++ -*-===// 2*5ffd83dbSDimitry Andric // 3*5ffd83dbSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*5ffd83dbSDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5*5ffd83dbSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*5ffd83dbSDimitry Andric // 7*5ffd83dbSDimitry Andric //===----------------------------------------------------------------------===// 8*5ffd83dbSDimitry Andric 9*5ffd83dbSDimitry Andric #ifndef LLDB_API_SBENVIRONMENT_H 10*5ffd83dbSDimitry Andric #define LLDB_API_SBENVIRONMENT_H 11*5ffd83dbSDimitry Andric 12*5ffd83dbSDimitry Andric #include "lldb/API/SBDefines.h" 13*5ffd83dbSDimitry Andric 14*5ffd83dbSDimitry Andric namespace lldb { 15*5ffd83dbSDimitry Andric 16*5ffd83dbSDimitry Andric class LLDB_API SBEnvironment { 17*5ffd83dbSDimitry Andric public: 18*5ffd83dbSDimitry Andric SBEnvironment(); 19*5ffd83dbSDimitry Andric 20*5ffd83dbSDimitry Andric SBEnvironment(const lldb::SBEnvironment &rhs); 21*5ffd83dbSDimitry Andric 22*5ffd83dbSDimitry Andric ~SBEnvironment(); 23*5ffd83dbSDimitry Andric 24*5ffd83dbSDimitry Andric const lldb::SBEnvironment &operator=(const lldb::SBEnvironment &rhs); 25*5ffd83dbSDimitry Andric 26*5ffd83dbSDimitry Andric /// Return the value of a given environment variable. 27*5ffd83dbSDimitry Andric /// 28*5ffd83dbSDimitry Andric /// \param [in] name 29*5ffd83dbSDimitry Andric /// The name of the environment variable. 30*5ffd83dbSDimitry Andric /// 31*5ffd83dbSDimitry Andric /// \return 32*5ffd83dbSDimitry Andric /// The value of the environment variable or null if not present. 33*5ffd83dbSDimitry Andric /// If the environment variable has no value but is present, a valid 34*5ffd83dbSDimitry Andric /// pointer to an empty string will be returned. 35*5ffd83dbSDimitry Andric const char *Get(const char *name); 36*5ffd83dbSDimitry Andric 37*5ffd83dbSDimitry Andric /// \return 38*5ffd83dbSDimitry Andric /// The number of environment variables. 39*5ffd83dbSDimitry Andric size_t GetNumValues(); 40*5ffd83dbSDimitry Andric 41*5ffd83dbSDimitry Andric /// Return the name of the environment variable at a given index from the 42*5ffd83dbSDimitry Andric /// internal list of environment variables. 43*5ffd83dbSDimitry Andric /// 44*5ffd83dbSDimitry Andric /// \param [in] index 45*5ffd83dbSDimitry Andric /// The index of the environment variable in the internal list. 46*5ffd83dbSDimitry Andric /// 47*5ffd83dbSDimitry Andric /// \return 48*5ffd83dbSDimitry Andric /// The name at the given index or null if the index is invalid. 49*5ffd83dbSDimitry Andric const char *GetNameAtIndex(size_t index); 50*5ffd83dbSDimitry Andric 51*5ffd83dbSDimitry Andric /// Return the value of the environment variable at a given index from the 52*5ffd83dbSDimitry Andric /// internal list of environment variables. 53*5ffd83dbSDimitry Andric /// 54*5ffd83dbSDimitry Andric /// \param [in] index 55*5ffd83dbSDimitry Andric /// The index of the environment variable in the internal list. 56*5ffd83dbSDimitry Andric /// 57*5ffd83dbSDimitry Andric /// \return 58*5ffd83dbSDimitry Andric /// The value at the given index or null if the index is invalid. 59*5ffd83dbSDimitry Andric /// If the environment variable has no value but is present, a valid 60*5ffd83dbSDimitry Andric /// pointer to an empty string will be returned. 61*5ffd83dbSDimitry Andric const char *GetValueAtIndex(size_t index); 62*5ffd83dbSDimitry Andric 63*5ffd83dbSDimitry Andric /// Return all environment variables contained in this object. Each variable 64*5ffd83dbSDimitry Andric /// is returned as a string with the following format 65*5ffd83dbSDimitry Andric /// name=value 66*5ffd83dbSDimitry Andric /// 67*5ffd83dbSDimitry Andric /// \return 68*5ffd83dbSDimitry Andric /// Return an lldb::SBStringList object with the environment variables. 69*5ffd83dbSDimitry Andric SBStringList GetEntries(); 70*5ffd83dbSDimitry Andric 71*5ffd83dbSDimitry Andric /// Add or replace an existing environment variable. The input must be a 72*5ffd83dbSDimitry Andric /// string with the format 73*5ffd83dbSDimitry Andric /// name=value 74*5ffd83dbSDimitry Andric /// 75*5ffd83dbSDimitry Andric /// \param [in] name_and_value 76*5ffd83dbSDimitry Andric /// The entry to set which conforms to the format mentioned above. 77*5ffd83dbSDimitry Andric void PutEntry(const char *name_and_value); 78*5ffd83dbSDimitry Andric 79*5ffd83dbSDimitry Andric /// Update this object with the given environment variables. The input is a 80*5ffd83dbSDimitry Andric /// list of entries with the same format required by SBEnvironment::PutEntry. 81*5ffd83dbSDimitry Andric /// 82*5ffd83dbSDimitry Andric /// If append is false, the provided environment will replace the existing 83*5ffd83dbSDimitry Andric /// environment. Otherwise, existing values will be updated of left untouched 84*5ffd83dbSDimitry Andric /// accordingly. 85*5ffd83dbSDimitry Andric /// 86*5ffd83dbSDimitry Andric /// \param [in] entries 87*5ffd83dbSDimitry Andric /// The environment variable entries. 88*5ffd83dbSDimitry Andric /// 89*5ffd83dbSDimitry Andric /// \param [in] append 90*5ffd83dbSDimitry Andric /// Flag that controls whether to replace the existing environment. 91*5ffd83dbSDimitry Andric void SetEntries(const SBStringList &entries, bool append); 92*5ffd83dbSDimitry Andric 93*5ffd83dbSDimitry Andric /// Set the value of a given environment variable. 94*5ffd83dbSDimitry Andric /// If the variable exists, its value is updated only if overwrite is true. 95*5ffd83dbSDimitry Andric /// 96*5ffd83dbSDimitry Andric /// \param [in] name 97*5ffd83dbSDimitry Andric /// The name of the environment variable to set. 98*5ffd83dbSDimitry Andric /// 99*5ffd83dbSDimitry Andric /// \param [in] value 100*5ffd83dbSDimitry Andric /// The value of the environment variable to set. 101*5ffd83dbSDimitry Andric /// 102*5ffd83dbSDimitry Andric /// \param [in] overwrite 103*5ffd83dbSDimitry Andric /// Flag that indicates whether to overwrite an existing environment 104*5ffd83dbSDimitry Andric /// variable. 105*5ffd83dbSDimitry Andric /// 106*5ffd83dbSDimitry Andric /// \return 107*5ffd83dbSDimitry Andric /// Return whether the variable was added or modified. 108*5ffd83dbSDimitry Andric bool Set(const char *name, const char *value, bool overwrite); 109*5ffd83dbSDimitry Andric 110*5ffd83dbSDimitry Andric /// Unset an environment variable if exists. 111*5ffd83dbSDimitry Andric /// 112*5ffd83dbSDimitry Andric /// \param [in] name 113*5ffd83dbSDimitry Andric /// The name of the environment variable to unset. 114*5ffd83dbSDimitry Andric /// 115*5ffd83dbSDimitry Andric /// \return 116*5ffd83dbSDimitry Andric /// Return whether a variable was actually unset. 117*5ffd83dbSDimitry Andric bool Unset(const char *name); 118*5ffd83dbSDimitry Andric 119*5ffd83dbSDimitry Andric /// Delete all the environment variables. 120*5ffd83dbSDimitry Andric void Clear(); 121*5ffd83dbSDimitry Andric 122*5ffd83dbSDimitry Andric protected: 123*5ffd83dbSDimitry Andric friend class SBPlatform; 124*5ffd83dbSDimitry Andric friend class SBTarget; 125*5ffd83dbSDimitry Andric friend class SBLaunchInfo; 126*5ffd83dbSDimitry Andric 127*5ffd83dbSDimitry Andric SBEnvironment(lldb_private::Environment rhs); 128*5ffd83dbSDimitry Andric 129*5ffd83dbSDimitry Andric lldb_private::Environment &ref() const; 130*5ffd83dbSDimitry Andric 131*5ffd83dbSDimitry Andric private: 132*5ffd83dbSDimitry Andric std::unique_ptr<lldb_private::Environment> m_opaque_up; 133*5ffd83dbSDimitry Andric }; 134*5ffd83dbSDimitry Andric 135*5ffd83dbSDimitry Andric } // namespace lldb 136*5ffd83dbSDimitry Andric 137*5ffd83dbSDimitry Andric #endif // LLDB_API_SBENVIRONMENT_H 138