brucem updated this revision to Diff 349895.
brucem added a comment.

Rebase and address feedback.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D103675/new/

https://reviews.llvm.org/D103675

Files:
  lldb/bindings/interface/SBProcessInfo.i
  lldb/include/lldb/API/SBEnvironment.h
  lldb/include/lldb/API/SBProcessInfo.h
  lldb/source/API/SBProcessInfo.cpp
  lldb/test/API/python_api/process/TestProcessAPI.py

Index: lldb/test/API/python_api/process/TestProcessAPI.py
===================================================================
--- lldb/test/API/python_api/process/TestProcessAPI.py
+++ lldb/test/API/python_api/process/TestProcessAPI.py
@@ -335,6 +335,8 @@
         # Launch the process and stop at the entry point.
         launch_info = target.GetLaunchInfo()
         launch_info.SetWorkingDirectory(self.get_process_working_directory())
+        launch_info.SetEnvironmentEntries(["FOO=BAR"], False)
+        launch_info.SetArguments(["--abc"], False)
         launch_flags = launch_info.GetLaunchFlags()
         launch_flags |= lldb.eLaunchFlagStopAtEntry
         launch_info.SetLaunchFlags(launch_flags)
@@ -358,6 +360,11 @@
             "Process ID is valid")
         triple = process_info.GetTriple()
         self.assertIsNotNone(triple, "Process has a triple")
+        env = process_info.GetEnvironment()
+        self.assertGreater(env.GetNumValues(), 0)
+        self.assertEqual("BAR", env.Get("FOO"))
+        self.assertEqual(process_info.GetNumArguments(), 1)
+        self.assertEqual("--abc", process_info.GetArgumentAtIndex(0))
 
         # Additional process info varies by platform, so just check that
         # whatever info was retrieved is consistent and nothing blows up.
Index: lldb/source/API/SBProcessInfo.cpp
===================================================================
--- lldb/source/API/SBProcessInfo.cpp
+++ lldb/source/API/SBProcessInfo.cpp
@@ -9,6 +9,7 @@
 #include "lldb/API/SBProcessInfo.h"
 #include "SBReproducerPrivate.h"
 #include "Utils.h"
+#include "lldb/API/SBEnvironment.h"
 #include "lldb/API/SBFileSpec.h"
 #include "lldb/Utility/ProcessInfo.h"
 
@@ -194,6 +195,38 @@
   return triple;
 }
 
+uint32_t SBProcessInfo::GetNumArguments() {
+  LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBProcessInfo, GetNumArguments);
+
+  uint32_t num = 0;
+  if (m_opaque_up) {
+    num = m_opaque_up->GetArguments().size();
+  }
+  return num;
+}
+
+const char *SBProcessInfo::GetArgumentAtIndex(uint32_t index) {
+  LLDB_RECORD_METHOD(const char *, SBProcessInfo, GetArgumentAtIndex,
+                     (uint32_t), index);
+
+  const char *argument = nullptr;
+  if (m_opaque_up) {
+    argument = m_opaque_up->GetArguments().GetArgumentAtIndex(index);
+  }
+  return argument;
+}
+
+SBEnvironment SBProcessInfo::GetEnvironment() {
+  LLDB_RECORD_METHOD_NO_ARGS(lldb::SBEnvironment, SBProcessInfo,
+                             GetEnvironment);
+
+  if (m_opaque_up) {
+    return LLDB_RECORD_RESULT(SBEnvironment(m_opaque_up->GetEnvironment()));
+  }
+
+  return LLDB_RECORD_RESULT(SBEnvironment());
+}
+
 namespace lldb_private {
 namespace repro {
 
@@ -220,6 +253,10 @@
   LLDB_REGISTER_METHOD(bool, SBProcessInfo, EffectiveGroupIDIsValid, ());
   LLDB_REGISTER_METHOD(lldb::pid_t, SBProcessInfo, GetParentProcessID, ());
   LLDB_REGISTER_METHOD(const char *, SBProcessInfo, GetTriple, ());
+  LLDB_REGISTER_METHOD(uint32_t, SBProcessInfo, GetNumArguments, ());
+  LLDB_REGISTER_METHOD(const char *, SBProcessInfo, GetArgumentAtIndex,
+                       (uint32_t));
+  LLDB_REGISTER_METHOD(lldb::SBEnvironment, SBProcessInfo, GetEnvironment, ());
 }
 
 }
Index: lldb/include/lldb/API/SBProcessInfo.h
===================================================================
--- lldb/include/lldb/API/SBProcessInfo.h
+++ lldb/include/lldb/API/SBProcessInfo.h
@@ -53,6 +53,19 @@
   /// Return the target triple (arch-vendor-os) for the described process.
   const char *GetTriple();
 
+  // Return the number of arguments given to the described process.
+  uint32_t GetNumArguments();
+
+  // Return the specified argument given to the described process.
+  const char *GetArgumentAtIndex(uint32_t index);
+
+  /// Return the environment variables for the described process.
+  ///
+  /// \return
+  ///     An lldb::SBEnvironment object which is a copy of the process
+  ///     environment.
+  SBEnvironment GetEnvironment();
+
 private:
   friend class SBProcess;
 
Index: lldb/include/lldb/API/SBEnvironment.h
===================================================================
--- lldb/include/lldb/API/SBEnvironment.h
+++ lldb/include/lldb/API/SBEnvironment.h
@@ -122,6 +122,7 @@
 protected:
   friend class SBPlatform;
   friend class SBTarget;
+  friend class SBProcessInfo;
   friend class SBLaunchInfo;
 
   SBEnvironment(lldb_private::Environment rhs);
Index: lldb/bindings/interface/SBProcessInfo.i
===================================================================
--- lldb/bindings/interface/SBProcessInfo.i
+++ lldb/bindings/interface/SBProcessInfo.i
@@ -68,6 +68,25 @@
     ) GetTriple;
     const char *
     GetTriple ();
+
+    %feature("docstring",
+    "Return the number of arguments given to the described process."
+    ) GetNumArguments;
+    uint32_t
+    GetNumArguments ();
+
+    %feature("autodoc", "
+    GetArgumentAtIndex(int index) -> string
+    Return the specified argument given to the described process."
+    ) GetArgumentAtIndex;
+    const char *
+    GetArgumentAtIndex (uint32_t index);
+
+    %feature("docstring",
+    "Return the environment variables for the described process."
+    ) GetEnvironment;
+    SBEnvironment
+    GetEnvironment ();
 };
 
 } // namespace lldb
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to