Author: Kazuki Sakamoto Date: 2023-07-12T11:11:18-07:00 New Revision: c4fa6fafc43ad5374a29d542737c0238b85516e4
URL: https://github.com/llvm/llvm-project/commit/c4fa6fafc43ad5374a29d542737c0238b85516e4 DIFF: https://github.com/llvm/llvm-project/commit/c4fa6fafc43ad5374a29d542737c0238b85516e4.diff LOG: [lldb][LocateModuleCallback] Update SBFileSpec/SBModuleSpec RFC https://discourse.llvm.org/t/rfc-python-callback-for-target-get-module/71580 SBFileSpec and SBModuleSpec will be used for locate module callback as Python function arguments. This diff allows these things. - Can be instantiated from SBPlatform. - Can be passed to/from Python. - Can be accessed for object offset and size. Differential Revision: https://reviews.llvm.org/D153733 Added: lldb/test/API/python_api/module_spec/TestModuleSpec.py Modified: lldb/bindings/python/python-swigsafecast.swig lldb/include/lldb/API/SBModuleSpec.h lldb/source/API/SBModuleSpec.cpp lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h Removed: ################################################################################ diff --git a/lldb/bindings/python/python-swigsafecast.swig b/lldb/bindings/python/python-swigsafecast.swig index bd6166f2232f16..d5ea5148727134 100644 --- a/lldb/bindings/python/python-swigsafecast.swig +++ b/lldb/bindings/python/python-swigsafecast.swig @@ -120,5 +120,15 @@ ScopedPythonObject<lldb::SBEvent> SWIGBridge::ToSWIGWrapper(Event *event) { SWIGTYPE_p_lldb__SBEvent); } +PythonObject SWIGBridge::ToSWIGWrapper( + std::unique_ptr<lldb::SBFileSpec> file_spec_sb) { + return ToSWIGHelper(file_spec_sb.release(), SWIGTYPE_p_lldb__SBFileSpec); +} + +PythonObject SWIGBridge::ToSWIGWrapper( + std::unique_ptr<lldb::SBModuleSpec> module_spec_sb) { + return ToSWIGHelper(module_spec_sb.release(), SWIGTYPE_p_lldb__SBModuleSpec); +} + } // namespace python } // namespace lldb_private diff --git a/lldb/include/lldb/API/SBModuleSpec.h b/lldb/include/lldb/API/SBModuleSpec.h index 7529879b78b580..8d1ecfe6e6f8b1 100644 --- a/lldb/include/lldb/API/SBModuleSpec.h +++ b/lldb/include/lldb/API/SBModuleSpec.h @@ -77,13 +77,24 @@ class LLDB_API SBModuleSpec { bool SetUUIDBytes(const uint8_t *uuid, size_t uuid_len); + uint64_t GetObjectOffset(); + + void SetObjectOffset(uint64_t object_offset); + + uint64_t GetObjectSize(); + + void SetObjectSize(uint64_t object_size); + bool GetDescription(lldb::SBStream &description); private: friend class SBModuleSpecList; friend class SBModule; + friend class SBPlatform; friend class SBTarget; + SBModuleSpec(const lldb_private::ModuleSpec &module_spec); + std::unique_ptr<lldb_private::ModuleSpec> m_opaque_up; }; diff --git a/lldb/source/API/SBModuleSpec.cpp b/lldb/source/API/SBModuleSpec.cpp index 83b1b6b7494163..fbbcfeac201783 100644 --- a/lldb/source/API/SBModuleSpec.cpp +++ b/lldb/source/API/SBModuleSpec.cpp @@ -29,6 +29,11 @@ SBModuleSpec::SBModuleSpec(const SBModuleSpec &rhs) { m_opaque_up = clone(rhs.m_opaque_up); } +SBModuleSpec::SBModuleSpec(const lldb_private::ModuleSpec &module_spec) + : m_opaque_up(new lldb_private::ModuleSpec(module_spec)) { + LLDB_INSTRUMENT_VA(this, module_spec); +} + const SBModuleSpec &SBModuleSpec::operator=(const SBModuleSpec &rhs) { LLDB_INSTRUMENT_VA(this, rhs); @@ -145,6 +150,30 @@ bool SBModuleSpec::GetDescription(lldb::SBStream &description) { return true; } +uint64_t SBModuleSpec::GetObjectOffset() { + LLDB_INSTRUMENT_VA(this); + + return m_opaque_up->GetObjectOffset(); +} + +void SBModuleSpec::SetObjectOffset(uint64_t object_offset) { + LLDB_INSTRUMENT_VA(this, object_offset); + + m_opaque_up->SetObjectOffset(object_offset); +} + +uint64_t SBModuleSpec::GetObjectSize() { + LLDB_INSTRUMENT_VA(this); + + return m_opaque_up->GetObjectSize(); +} + +void SBModuleSpec::SetObjectSize(uint64_t object_size) { + LLDB_INSTRUMENT_VA(this, object_size); + + m_opaque_up->SetObjectSize(object_size); +} + SBModuleSpecList::SBModuleSpecList() : m_opaque_up(new ModuleSpecList()) { LLDB_INSTRUMENT_VA(this); } diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h b/lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h index 1d8ed8737b70fb..630ab293cf939e 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h +++ b/lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h @@ -30,6 +30,8 @@ class SBCommandReturnObject; class SBValue; class SBStream; class SBStructuredData; +class SBFileSpec; +class SBModuleSpec; } // namespace lldb namespace lldb_private { @@ -102,6 +104,10 @@ class SWIGBridge { static PythonObject ToSWIGWrapper(std::unique_ptr<lldb::SBStream> stream_sb); static PythonObject ToSWIGWrapper(std::unique_ptr<lldb::SBStructuredData> data_sb); + static PythonObject + ToSWIGWrapper(std::unique_ptr<lldb::SBFileSpec> file_spec_sb); + static PythonObject + ToSWIGWrapper(std::unique_ptr<lldb::SBModuleSpec> module_spec_sb); static python::ScopedPythonObject<lldb::SBCommandReturnObject> ToSWIGWrapper(CommandReturnObject &cmd_retobj); diff --git a/lldb/test/API/python_api/module_spec/TestModuleSpec.py b/lldb/test/API/python_api/module_spec/TestModuleSpec.py new file mode 100644 index 00000000000000..eee7acb9993b1f --- /dev/null +++ b/lldb/test/API/python_api/module_spec/TestModuleSpec.py @@ -0,0 +1,24 @@ +""" +Test some SBModuleSpec APIs. +""" + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * + + +class ModuleSpecAPIsTestCase(TestBase): + def test_object_offset_and_size(self): + module_spec = lldb.SBModuleSpec() + self.assertEqual(module_spec.GetObjectOffset(), 0) + self.assertEqual(module_spec.GetObjectSize(), 0) + + module_spec.SetObjectOffset(4096) + self.assertEqual(module_spec.GetObjectOffset(), 4096) + + module_spec.SetObjectSize(3600) + self.assertEqual(module_spec.GetObjectSize(), 3600) + + module_spec.Clear() + self.assertEqual(module_spec.GetObjectOffset(), 0) + self.assertEqual(module_spec.GetObjectSize(), 0) _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits