[lldb/API] Expose triple for SBProcessInfo.
authorBruce Mitchener <bruce.mitchener@gmail.com>
Sun, 30 May 2021 10:28:09 +0000 (17:28 +0700)
committerBruce Mitchener <bruce.mitchener@gmail.com>
Wed, 2 Jun 2021 04:35:11 +0000 (11:35 +0700)
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

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

index 0098425..17b2761 100644 (file)
@@ -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
index 0cc5f6a..36fae9e 100644 (file)
@@ -50,6 +50,9 @@ public:
 
   lldb::pid_t GetParentProcessID();
 
+  /// Return the target triple (arch-vendor-os) for the described process.
+  const char *GetTriple();
+
 private:
   friend class SBProcess;
 
index 29a9c7b..cba3bdc 100644 (file)
@@ -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, ());
 }
 
 }
index 942e261..b7efc7e 100644 (file)
@@ -356,6 +356,8 @@ class ProcessAPITestCase(TestBase):
         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.