diff --git a/lldb/bindings/python/python-swigsafecast.swig b/lldb/bindings/python/python-swigsafecast.swig --- a/lldb/bindings/python/python-swigsafecast.swig +++ b/lldb/bindings/python/python-swigsafecast.swig @@ -120,5 +120,15 @@ SWIGTYPE_p_lldb__SBEvent); } +PythonObject SWIGBridge::ToSWIGWrapper( + std::unique_ptr file_spec_sb) { + return ToSWIGHelper(file_spec_sb.release(), SWIGTYPE_p_lldb__SBFileSpec); +} + +PythonObject SWIGBridge::ToSWIGWrapper( + std::unique_ptr 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/SBFileSpec.h b/lldb/include/lldb/API/SBFileSpec.h --- a/lldb/include/lldb/API/SBFileSpec.h +++ b/lldb/include/lldb/API/SBFileSpec.h @@ -11,6 +11,12 @@ #include "lldb/API/SBDefines.h" +namespace lldb_private { +namespace python { +class SWIGBridge; +} // namespace python +} // namespace lldb_private + namespace lldb { class LLDB_API SBFileSpec { @@ -79,6 +85,8 @@ friend class SBThread; friend class SBTrace; + friend class lldb_private::python::SWIGBridge; + SBFileSpec(const lldb_private::FileSpec &fspec); void SetFileSpec(const lldb_private::FileSpec &fspec); diff --git a/lldb/include/lldb/API/SBModuleSpec.h b/lldb/include/lldb/API/SBModuleSpec.h --- a/lldb/include/lldb/API/SBModuleSpec.h +++ b/lldb/include/lldb/API/SBModuleSpec.h @@ -12,6 +12,12 @@ #include "lldb/API/SBDefines.h" #include "lldb/API/SBFileSpec.h" +namespace lldb_private { +namespace python { +class SWIGBridge; +} // namespace python +} // namespace lldb_private + namespace lldb { class LLDB_API SBModuleSpec { @@ -77,6 +83,14 @@ 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: @@ -84,6 +98,10 @@ friend class SBModule; friend class SBTarget; + friend class lldb_private::python::SWIGBridge; + + SBModuleSpec(const lldb_private::ModuleSpec &module_spec); + std::unique_ptr m_opaque_up; }; diff --git a/lldb/source/API/SBModuleSpec.cpp b/lldb/source/API/SBModuleSpec.cpp --- a/lldb/source/API/SBModuleSpec.cpp +++ b/lldb/source/API/SBModuleSpec.cpp @@ -29,6 +29,11 @@ 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 @@ 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 --- a/lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h +++ b/lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h @@ -30,6 +30,8 @@ class SBValue; class SBStream; class SBStructuredData; +class SBFileSpec; +class SBModuleSpec; } // namespace lldb namespace lldb_private { @@ -102,6 +104,10 @@ static PythonObject ToSWIGWrapper(std::unique_ptr stream_sb); static PythonObject ToSWIGWrapper(std::unique_ptr data_sb); + static PythonObject + ToSWIGWrapper(std::unique_ptr file_spec_sb); + static PythonObject + ToSWIGWrapper(std::unique_ptr module_spec_sb); static python::ScopedPythonObject 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 --- /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)