From 30367cb5982dfdab2655401f020711311e7d78b9 Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Mon, 6 May 2024 10:06:51 +0200 Subject: [lldb] Add SBType::GetByteAlign (#90960) lldb already mostly(*) tracks this information. This just makes it available to the SB users. (*) It does not do that for typedefs right now see llvm.org/pr90958 --- lldb/test/API/python_api/type/TestTypeList.py | 21 +++++++++++++++++++++ lldb/test/API/python_api/type/main.cpp | 3 +++ 2 files changed, 24 insertions(+) (limited to 'lldb/test/API/python_api') diff --git a/lldb/test/API/python_api/type/TestTypeList.py b/lldb/test/API/python_api/type/TestTypeList.py index 17e27b6..0498396 100644 --- a/lldb/test/API/python_api/type/TestTypeList.py +++ b/lldb/test/API/python_api/type/TestTypeList.py @@ -272,3 +272,24 @@ class TypeAndTypeListTestCase(TestBase): self.assertTrue(int_enum_uchar) self.DebugSBType(int_enum_uchar) self.assertEqual(int_enum_uchar.GetName(), "unsigned char") + + def test_GetByteAlign(self): + """Exercise SBType::GetByteAlign""" + self.build() + spec = lldb.SBModuleSpec() + spec.SetFileSpec(lldb.SBFileSpec(self.getBuildArtifact())) + module = lldb.SBModule(spec) + self.assertTrue(module) + + # Invalid types should not crash. + self.assertEqual(lldb.SBType().GetByteAlign(), 0) + + # Try a type with natural alignment. + void_ptr = module.GetBasicType(lldb.eBasicTypeVoid).GetPointerType() + self.assertTrue(void_ptr) + # Not exactly guaranteed by the spec, but should be true everywhere we + # care about. + self.assertEqual(void_ptr.GetByteSize(), void_ptr.GetByteAlign()) + + # And an over-aligned type. + self.assertEqual(module.FindFirstType("OverAlignedStruct").GetByteAlign(), 128) diff --git a/lldb/test/API/python_api/type/main.cpp b/lldb/test/API/python_api/type/main.cpp index 7384a3d..986ed30 100644 --- a/lldb/test/API/python_api/type/main.cpp +++ b/lldb/test/API/python_api/type/main.cpp @@ -50,6 +50,9 @@ enum EnumType {}; enum class ScopedEnumType {}; enum class EnumUChar : unsigned char {}; +struct alignas(128) OverAlignedStruct {}; +OverAlignedStruct over_aligned_struct; + int main (int argc, char const *argv[]) { Task *task_head = new Task(-1, NULL); -- cgit v1.1