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 @@ -62,6 +62,12 @@ 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 --- a/lldb/include/lldb/API/SBProcessInfo.h +++ b/lldb/include/lldb/API/SBProcessInfo.h @@ -50,6 +50,9 @@ 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 --- a/lldb/source/API/SBProcessInfo.cpp +++ b/lldb/source/API/SBProcessInfo.cpp @@ -179,6 +179,21 @@ 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 @@ 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 --- a/lldb/test/API/python_api/process/TestProcessAPI.py +++ b/lldb/test/API/python_api/process/TestProcessAPI.py @@ -356,6 +356,8 @@ 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.