SBEnvironment.h 4.3 KB

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