wallace created this revision.
wallace added reviewers: labath, clayborg.
Herald added subscribers: lldb-commits, mgorny.
Herald added a project: LLDB.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76111

Files:
  lldb/bindings/headers.swig
  lldb/bindings/interface/SBEnvironment.i
  lldb/bindings/interface/SBPlatform.i
  lldb/bindings/interfaces.swig
  lldb/include/lldb/API/LLDB.h
  lldb/include/lldb/API/SBDefines.h
  lldb/include/lldb/API/SBEnvironment.h
  lldb/include/lldb/API/SBPlatform.h
  lldb/include/lldb/lldb-forward.h
  lldb/source/API/CMakeLists.txt
  lldb/source/API/SBEnvironment.cpp
  lldb/source/API/SBPlatform.cpp

Index: lldb/source/API/SBPlatform.cpp
===================================================================
--- lldb/source/API/SBPlatform.cpp
+++ lldb/source/API/SBPlatform.cpp
@@ -8,9 +8,11 @@
 
 #include "lldb/API/SBPlatform.h"
 #include "SBReproducerPrivate.h"
+#include "lldb/API/SBEnvironment.h"
 #include "lldb/API/SBError.h"
 #include "lldb/API/SBFileSpec.h"
 #include "lldb/API/SBLaunchInfo.h"
+#include "lldb/API/SBPlatform.h"
 #include "lldb/API/SBUnixSignals.h"
 #include "lldb/Host/File.h"
 #include "lldb/Target/Platform.h"
@@ -649,6 +651,17 @@
   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 repro {
 
@@ -740,6 +753,7 @@
                        (const char *));
   LLDB_REGISTER_METHOD(lldb::SBError, SBPlatform, SetFilePermissions,
                        (const char *, uint32_t));
+  LLDB_REGISTER_METHOD(lldb::SBEnvironment, SBPlatform, GetEnvironment, ());                     
   LLDB_REGISTER_METHOD_CONST(lldb::SBUnixSignals, SBPlatform, GetUnixSignals,
                              ());
 }
Index: lldb/source/API/SBEnvironment.cpp
===================================================================
--- /dev/null
+++ lldb/source/API/SBEnvironment.cpp
@@ -0,0 +1,66 @@
+//===-- 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/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(new Environment()) {
+  LLDB_RECORD_CONSTRUCTOR(SBEnvironment, (const lldb::SBEnvironment &), rhs);
+
+  m_opaque_up = clone(rhs.m_opaque_up);
+}
+
+SBEnvironment::SBEnvironment(const Environment &rhs) : m_opaque_up(new Environment()) {
+  *m_opaque_up = rhs; 
+}
+
+SBEnvironment::~SBEnvironment() = default;
+
+const SBEnvironment &SBEnvironment::operator=(const SBEnvironment &rhs) {
+  LLDB_RECORD_METHOD(const lldb::SBEnvironment &,
+                     SBEnvironment, operator=,(const lldb::SBEnvironment &), rhs);
+
+  if (this != &rhs)
+    m_opaque_up = clone(rhs.m_opaque_up);
+  return LLDB_RECORD_RESULT(*this);
+}
+
+int SBEnvironment::Size() {
+  LLDB_RECORD_METHOD_NO_ARGS(int, SBEnvironment, Size);
+  return LLDB_RECORD_RESULT(m_opaque_up->size());
+}
+
+const char *SBEnvironment::GetEntryAtIndex(int idx) {
+  LLDB_RECORD_METHOD(const char *, SBEnvironment, GetEntryAtIndex, (int), idx);
+  return LLDB_RECORD_RESULT(m_opaque_up->getEnvp().get()[idx]);
+}
+
+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(const lldb::SBEnvironment &,
+                       SBEnvironment, operator=,(const lldb::SBEnvironment &));
+  LLDB_REGISTER_METHOD(int, SBEnvironment, Size, ()); 
+  LLDB_REGISTER_METHOD(const char *, SBEnvironment, GetEntryAtIndex, (int));
+}
+
+}
+}
Index: lldb/source/API/CMakeLists.txt
===================================================================
--- lldb/source/API/CMakeLists.txt
+++ lldb/source/API/CMakeLists.txt
@@ -35,6 +35,7 @@
   SBData.cpp
   SBDebugger.cpp
   SBDeclaration.cpp
+  SBEnvironment.cpp
   SBError.cpp
   SBEvent.cpp
   SBExecutionContext.cpp
Index: lldb/include/lldb/lldb-forward.h
===================================================================
--- lldb/include/lldb/lldb-forward.h
+++ lldb/include/lldb/lldb-forward.h
@@ -76,6 +76,7 @@
 class DynamicLoader;
 class Editline;
 class EmulateInstruction;
+class Environment;
 class EvaluateExpressionOptions;
 class Event;
 class EventData;
Index: lldb/include/lldb/API/SBPlatform.h
===================================================================
--- lldb/include/lldb/API/SBPlatform.h
+++ lldb/include/lldb/API/SBPlatform.h
@@ -154,6 +154,8 @@
 
   SBUnixSignals GetUnixSignals() const;
 
+  SBEnvironment GetEnvironment();
+
 protected:
   friend class SBDebugger;
   friend class SBTarget;
Index: lldb/include/lldb/API/SBEnvironment.h
===================================================================
--- /dev/null
+++ lldb/include/lldb/API/SBEnvironment.h
@@ -0,0 +1,41 @@
+//===-- 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();
+
+  const lldb::SBEnvironment &operator =(const lldb::SBEnvironment &rhs);
+
+  int Size();
+
+  const char *GetEntryAtIndex(int idx);
+
+protected:
+  friend class SBPlatform;
+ 
+  SBEnvironment(const lldb_private::Environment &rhs);
+
+private:
+  std::unique_ptr<lldb_private::Environment> m_opaque_up;
+};
+
+} // namespace lldb
+
+#endif // LLDB_API_SBENVIRONMENT_H
Index: lldb/include/lldb/API/SBDefines.h
===================================================================
--- lldb/include/lldb/API/SBDefines.h
+++ lldb/include/lldb/API/SBDefines.h
@@ -35,6 +35,7 @@
 class LLDB_API SBData;
 class LLDB_API SBDebugger;
 class LLDB_API SBDeclaration;
+class LLDB_API SBEnvironment;
 class LLDB_API SBError;
 class LLDB_API SBEvent;
 class LLDB_API SBEventList;
Index: lldb/include/lldb/API/LLDB.h
===================================================================
--- lldb/include/lldb/API/LLDB.h
+++ lldb/include/lldb/API/LLDB.h
@@ -24,6 +24,7 @@
 #include "lldb/API/SBDebugger.h"
 #include "lldb/API/SBDeclaration.h"
 #include "lldb/API/SBDefines.h"
+#include "lldb/API/SBEnvironment.h"
 #include "lldb/API/SBError.h"
 #include "lldb/API/SBEvent.h"
 #include "lldb/API/SBExecutionContext.h"
Index: lldb/bindings/interfaces.swig
===================================================================
--- lldb/bindings/interfaces.swig
+++ lldb/bindings/interfaces.swig
@@ -29,6 +29,7 @@
 %include "./interface/SBDebugger.i"
 %include "./interface/SBDeclaration.i"
 %include "./interface/SBError.i"
+%include "./interface/SBEnvironment.i"
 %include "./interface/SBEvent.i"
 %include "./interface/SBExecutionContext.i"
 %include "./interface/SBExpressionOptions.i"
Index: lldb/bindings/interface/SBPlatform.i
===================================================================
--- lldb/bindings/interface/SBPlatform.i
+++ lldb/bindings/interface/SBPlatform.i
@@ -194,6 +194,9 @@
     lldb::SBUnixSignals
     GetUnixSignals();
 
+    lldb::SBEnvironment
+    GetEnvironment();
+
 };
 
 } // namespace lldb
Index: lldb/bindings/interface/SBEnvironment.i
===================================================================
--- /dev/null
+++ lldb/bindings/interface/SBEnvironment.i
@@ -0,0 +1,30 @@
+//===-- 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 or platform.
+
+Example:
+  lldb.debugger.GetSelectedPlatform().GetEnvironment()
+") SBEnvironment;
+class SBEnvironment {
+public:
+    SBEnvironment ();
+
+    SBEnvironment (const lldb::SBEnvironment &rhs);
+
+    ~SBEnvironment();
+
+    int Size();
+
+    const char *GetEntryAtIndex(int idx);
+};
+
+} // namespace lldb
Index: lldb/bindings/headers.swig
===================================================================
--- lldb/bindings/headers.swig
+++ lldb/bindings/headers.swig
@@ -21,6 +21,7 @@
 #include "lldb/API/SBData.h"
 #include "lldb/API/SBDebugger.h"
 #include "lldb/API/SBDeclaration.h"
+#include "lldb/API/SBEnvironment.h"
 #include "lldb/API/SBError.h"
 #include "lldb/API/SBEvent.h"
 #include "lldb/API/SBExecutionContext.h"
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to