diff --git a/lldb/bindings/interface/SBProcessInfo.i b/lldb/bindings/interface/SBProcessInfo.i --- a/lldb/bindings/interface/SBProcessInfo.i +++ b/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 diff --git a/lldb/include/lldb/API/SBEnvironment.h b/lldb/include/lldb/API/SBEnvironment.h --- a/lldb/include/lldb/API/SBEnvironment.h +++ b/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); diff --git a/lldb/include/lldb/API/SBProcessInfo.h b/lldb/include/lldb/API/SBProcessInfo.h --- a/lldb/include/lldb/API/SBProcessInfo.h +++ b/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; diff --git a/lldb/source/API/SBProcessInfo.cpp b/lldb/source/API/SBProcessInfo.cpp --- a/lldb/source/API/SBProcessInfo.cpp +++ b/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, ()); } } diff --git a/lldb/test/API/python_api/process/TestProcessAPI.py b/lldb/test/API/python_api/process/TestProcessAPI.py --- a/lldb/test/API/python_api/process/TestProcessAPI.py +++ b/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.