mirror of
https://github.com/intel/llvm.git
synced 2026-01-16 13:35:38 +08:00
[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
This commit is contained in:
@@ -150,6 +150,8 @@ public:
|
||||
|
||||
uint64_t GetByteSize();
|
||||
|
||||
uint64_t GetByteAlign();
|
||||
|
||||
bool IsPointerType();
|
||||
|
||||
bool IsReferenceType();
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "lldb/Utility/Stream.h"
|
||||
|
||||
#include "llvm/ADT/APSInt.h"
|
||||
#include "llvm/Support/MathExtras.h"
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
@@ -132,6 +133,18 @@ uint64_t SBType::GetByteSize() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint64_t SBType::GetByteAlign() {
|
||||
LLDB_INSTRUMENT_VA(this);
|
||||
|
||||
if (!IsValid())
|
||||
return 0;
|
||||
|
||||
std::optional<uint64_t> bit_align =
|
||||
m_opaque_sp->GetCompilerType(/*prefer_dynamic=*/false)
|
||||
.GetTypeBitAlign(nullptr);
|
||||
return llvm::divideCeil(bit_align.value_or(0), 8);
|
||||
}
|
||||
|
||||
bool SBType::IsPointerType() {
|
||||
LLDB_INSTRUMENT_VA(this);
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user