[Lldb-commits] [lldb] [lldb] Expose the process arguments in SBProcessInfo (PR #197719)

Ebuka Ezike via lldb-commits lldb-commits at lists.llvm.org
Thu May 14 08:17:29 PDT 2026


https://github.com/da-viper created https://github.com/llvm/llvm-project/pull/197719

Add GetNumArguments() and GetArgumentAtIndex() to SBProcessInfo. Add a convienence property `arguments` in the python api.

lldb-dap uses this to show more information to the user when picking a process.

Fixes: #197509

>From 05fe0d8236526dd15354d7345d620b902d1449da Mon Sep 17 00:00:00 2001
From: Ebuka Ezike <yerimyah1 at gmail.com>
Date: Thu, 14 May 2026 16:10:24 +0100
Subject: [PATCH] [lldb] Expose the process arguments in SBProcessInfo

Add GetNumArguments() and GetArgumentAtIndex() to SBProcessInfo.
Add a convienence property `arguments` in the python api.

lldb-dap uses this to show more information to the user when
picking a process.

Fixes: #197509
---
 .../interface/SBProcessInfoExtensions.i       | 18 +++++++++++++++++
 lldb/bindings/interfaces.swig                 |  1 +
 lldb/include/lldb/API/SBProcessInfo.h         |  7 +++++++
 lldb/source/API/SBProcessInfo.cpp             | 20 +++++++++++++++++++
 .../default-constructor/sb_process_info.py    |  2 ++
 .../API/python_api/process/TestProcessAPI.py  | 10 ++++++++++
 6 files changed, 58 insertions(+)
 create mode 100644 lldb/bindings/interface/SBProcessInfoExtensions.i

diff --git a/lldb/bindings/interface/SBProcessInfoExtensions.i b/lldb/bindings/interface/SBProcessInfoExtensions.i
new file mode 100644
index 0000000000000..079a50a6940ed
--- /dev/null
+++ b/lldb/bindings/interface/SBProcessInfoExtensions.i
@@ -0,0 +1,18 @@
+
+%extend lldb::SBProcessInfo {
+
+#ifdef SWIGPYTHON
+    %pythoncode %{ 
+    @property
+    def arguments(self):
+        """A read only property that returns a list of lldb.SBProcessInfo arguments."""
+        if not hasattr(self, "_arguments"):
+            self._arguments = [
+                self.GetArgumentAtIndex(idx)
+                for idx in range(self.GetNumArguments())
+            ]
+            
+        return self._arguments
+    %}
+#endif
+}
diff --git a/lldb/bindings/interfaces.swig b/lldb/bindings/interfaces.swig
index fddbedf02e835..5cdddd5136ac2 100644
--- a/lldb/bindings/interfaces.swig
+++ b/lldb/bindings/interfaces.swig
@@ -56,6 +56,7 @@
 %include "./interface/SBPlatformExtensions.i"
 %include "./interface/SBProcessDocstrings.i"
 %include "./interface/SBProcessInfoDocstrings.i"
+%include "./interface/SBProcessInfoExtensions.i"
 %include "./interface/SBProgressDocstrings.i"
 %include "./interface/SBQueueDocstrings.i"
 %include "./interface/SBQueueItemDocstrings.i"
diff --git a/lldb/include/lldb/API/SBProcessInfo.h b/lldb/include/lldb/API/SBProcessInfo.h
index aec5924e4704a..b3120bf5374ee 100644
--- a/lldb/include/lldb/API/SBProcessInfo.h
+++ b/lldb/include/lldb/API/SBProcessInfo.h
@@ -53,6 +53,13 @@ class LLDB_API SBProcessInfo {
   /// Return the target triple (arch-vendor-os) for the described process.
   const char *GetTriple();
 
+  /// Returns the number of command line arguments for the described process.
+  uint32_t GetNumArguments() const;
+
+  /// Returns the command line argument at the given index, or `nullptr` if
+  /// the index is out of range or if the process info is invalid..
+  const char *GetArgumentAtIndex(uint32_t idx) const;
+
 private:
   friend class SBProcess;
   friend class SBProcessInfoList;
diff --git a/lldb/source/API/SBProcessInfo.cpp b/lldb/source/API/SBProcessInfo.cpp
index 895fba95afbae..3f80983e8e2c3 100644
--- a/lldb/source/API/SBProcessInfo.cpp
+++ b/lldb/source/API/SBProcessInfo.cpp
@@ -185,3 +185,23 @@ const char *SBProcessInfo::GetTriple() {
 
   return ConstString(arch.GetTriple().getTriple().c_str()).GetCString();
 }
+
+uint32_t SBProcessInfo::GetNumArguments() const {
+  LLDB_INSTRUMENT_VA(this);
+
+  if (!m_opaque_up)
+    return 0;
+
+  const Args &args = m_opaque_up->GetArguments();
+  return args.GetArgumentCount();
+}
+
+const char *SBProcessInfo::GetArgumentAtIndex(uint32_t idx) const {
+  LLDB_INSTRUMENT_VA(this, idx);
+
+  if (!m_opaque_up)
+    return nullptr;
+
+  const Args &args = m_opaque_up->GetArguments();
+  return args.GetArgumentAtIndex(idx);
+}
diff --git a/lldb/test/API/python_api/default-constructor/sb_process_info.py b/lldb/test/API/python_api/default-constructor/sb_process_info.py
index 0c4562f9be92a..264a678cf1e66 100644
--- a/lldb/test/API/python_api/default-constructor/sb_process_info.py
+++ b/lldb/test/API/python_api/default-constructor/sb_process_info.py
@@ -19,3 +19,5 @@ def fuzz_obj(obj):
     obj.EffectiveUserIDIsValid()
     obj.EffectiveGroupIDIsValid()
     obj.GetParentProcessID()
+    obj.GetNumArguments()
+    obj.GetArgumentAtIndex(100)
diff --git a/lldb/test/API/python_api/process/TestProcessAPI.py b/lldb/test/API/python_api/process/TestProcessAPI.py
index 0b857fb033f1e..8cbbf610541c0 100644
--- a/lldb/test/API/python_api/process/TestProcessAPI.py
+++ b/lldb/test/API/python_api/process/TestProcessAPI.py
@@ -372,6 +372,8 @@ def test_get_process_info(self):
         launch_flags = launch_info.GetLaunchFlags()
         launch_flags |= lldb.eLaunchFlagStopAtEntry
         launch_info.SetLaunchFlags(launch_flags)
+        expected_arguments = ["10", "qu'o'tes\"", "hello", "מזל טוב"]
+        launch_info.SetArguments(expected_arguments, False)
         error = lldb.SBError()
         process = target.Launch(launch_info, error)
 
@@ -445,6 +447,14 @@ def test_get_process_info(self):
 
         process_info.GetParentProcessID()
 
+        self.assertListEqual(process_info.arguments, expected_arguments)
+        self.assertEqual(process_info.GetNumArguments(), 4)
+        self.assertEqual(process_info.GetArgumentAtIndex(0), "10")
+        self.assertEqual(process_info.GetArgumentAtIndex(1), "qu'o'tes\"")
+        self.assertEqual(process_info.GetArgumentAtIndex(2), "hello")
+        self.assertEqual(process_info.GetArgumentAtIndex(3), "מזל טוב")
+        self.assertEqual(process_info.GetArgumentAtIndex(4), None)
+
     def test_allocate_deallocate_memory(self):
         """Test Python SBProcess.AllocateMemory() and SBProcess.DeallocateMemory() APIs."""
         self.build()



More information about the lldb-commits mailing list