[Lldb-commits] [lldb] 251a5d9 - [lldb/API] Expose triple for SBProcessInfo.

Bruce Mitchener via lldb-commits lldb-commits at lists.llvm.org
Tue Jun 1 21:35:37 PDT 2021


Author: Bruce Mitchener
Date: 2021-06-02T11:35:11+07:00
New Revision: 251a5d9d5239c0402e0ab68718aa194c2b4f04bb

URL: https://github.com/llvm/llvm-project/commit/251a5d9d5239c0402e0ab68718aa194c2b4f04bb
DIFF: https://github.com/llvm/llvm-project/commit/251a5d9d5239c0402e0ab68718aa194c2b4f04bb.diff

LOG: [lldb/API] Expose triple for SBProcessInfo.

This is present when doing a `platform process list` and is
tracked by the underlying code. To do something like the
process list via the SB API in the future, this must be
exposed.

Differential Revision: https://reviews.llvm.org/D103375

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/lldb/bindings/interface/SBProcessInfo.i b/lldb/bindings/interface/SBProcessInfo.i
index 009842599bf84..17b2761a344e7 100644
--- a/lldb/bindings/interface/SBProcessInfo.i
+++ b/lldb/bindings/interface/SBProcessInfo.i
@@ -62,6 +62,12 @@ public:
 
     lldb::pid_t
     GetParentProcessID ();
+
+    %feature("docstring",
+    "Return the target triple (arch-vendor-os) for the described process."
+    ) GetTriple;
+    const char *
+    GetTriple ();
 };
 
 } // namespace lldb

diff  --git a/lldb/include/lldb/API/SBProcessInfo.h b/lldb/include/lldb/API/SBProcessInfo.h
index 0cc5f6a2f9f6c..36fae9e842a61 100644
--- a/lldb/include/lldb/API/SBProcessInfo.h
+++ b/lldb/include/lldb/API/SBProcessInfo.h
@@ -50,6 +50,9 @@ class LLDB_API SBProcessInfo {
 
   lldb::pid_t GetParentProcessID();
 
+  /// Return the target triple (arch-vendor-os) for the described process.
+  const char *GetTriple();
+
 private:
   friend class SBProcess;
 

diff  --git a/lldb/source/API/SBProcessInfo.cpp b/lldb/source/API/SBProcessInfo.cpp
index 29a9c7b24b5a7..cba3bdc179f30 100644
--- a/lldb/source/API/SBProcessInfo.cpp
+++ b/lldb/source/API/SBProcessInfo.cpp
@@ -179,6 +179,21 @@ lldb::pid_t SBProcessInfo::GetParentProcessID() {
   return proc_id;
 }
 
+const char *SBProcessInfo::GetTriple() {
+  LLDB_RECORD_METHOD_NO_ARGS(const char *, SBProcessInfo, GetTriple);
+
+  const char *triple = nullptr;
+  if (m_opaque_up) {
+    const auto &arch = m_opaque_up->GetArchitecture();
+    if (arch.IsValid()) {
+      // Const-ify the string so we don't need to worry about the lifetime of
+      // the string
+      triple = ConstString(arch.GetTriple().getTriple().c_str()).GetCString();
+    }
+  }
+  return triple;
+}
+
 namespace lldb_private {
 namespace repro {
 
@@ -204,6 +219,7 @@ void RegisterMethods<SBProcessInfo>(Registry &R) {
   LLDB_REGISTER_METHOD(bool, SBProcessInfo, EffectiveUserIDIsValid, ());
   LLDB_REGISTER_METHOD(bool, SBProcessInfo, EffectiveGroupIDIsValid, ());
   LLDB_REGISTER_METHOD(lldb::pid_t, SBProcessInfo, GetParentProcessID, ());
+  LLDB_REGISTER_METHOD(const char *, SBProcessInfo, GetTriple, ());
 }
 
 }

diff  --git a/lldb/test/API/python_api/process/TestProcessAPI.py b/lldb/test/API/python_api/process/TestProcessAPI.py
index 942e2616c4095..b7efc7e4affa6 100644
--- a/lldb/test/API/python_api/process/TestProcessAPI.py
+++ b/lldb/test/API/python_api/process/TestProcessAPI.py
@@ -356,6 +356,8 @@ def test_get_process_info(self):
         self.assertNotEqual(
             process_info.GetProcessID(), lldb.LLDB_INVALID_PROCESS_ID,
             "Process ID is valid")
+        triple = process_info.GetTriple()
+        self.assertIsNotNone(triple, "Process has a triple")
 
         # Additional process info varies by platform, so just check that
         # whatever info was retrieved is consistent and nothing blows up.


        


More information about the lldb-commits mailing list