Skip to content

Commit

Permalink
Merge pull request swiftlang#9294 from augusto2112/test-clang-importe…
Browse files Browse the repository at this point in the history
…r-align

[lldb] Add test with custom alignment on a clang type
  • Loading branch information
augusto2112 authored Sep 19, 2024
2 parents 534793f + 0d4b6a9 commit 8c2a65f
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SWIFT_SOURCES := main.swift
SWIFTFLAGS_EXTRAS = -I$(SRCDIR)

include Makefile.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# TestSwiftClangImporterCustomAlignment.py
#
# This source file is part of the Swift.org open source project
#
# Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
# Licensed under Apache License v2.0 with Runtime Library Exception
#
# See https://swift.org/LICENSE.txt for license information
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
#
# ------------------------------------------------------------------------------
import lldb
from lldbsuite.test.decorators import *
import lldbsuite.test.lldbtest as lldbtest
import lldbsuite.test.lldbutil as lldbutil
import os


class TestSwiftClangImporterCustomAlignment(lldbtest.TestBase):

mydir = lldbtest.TestBase.compute_mydir(__file__)

@swiftTest
@skipIf(setting=('symbols.use-swift-clangimporter', 'false'))
def test(self):
self.build()
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
self, "break here", lldb.SBFileSpec("main.swift")
)
frame = thread.frames[0]
v = frame.FindVariable("v")
s = v.GetChildMemberWithName("s")

field_1 = s.GetChildMemberWithName("field_64_1")
lldbutil.check_variable(self, field_1, False, value="100")

field_2 = s.GetChildMemberWithName("field_32_1")
lldbutil.check_variable(self, field_2, False, value="200")

field_3 = s.GetChildMemberWithName("field_32_2")
lldbutil.check_variable(self, field_3, False, value="300")

field_4 = s.GetChildMemberWithName("field_64_2")
lldbutil.check_variable(self, field_4, False, value="400")

x = v.GetChildMemberWithName("x")
lldbutil.check_variable(self, x, False, value="1")
14 changes: 14 additions & 0 deletions lldb/test/API/lang/swift/clangimporter/custom_alignment/header.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "stdlib.h"
#include <stdint.h>

#pragma pack(push, 4)

struct Struct {
int64_t field_64_1;
int32_t field_32_1;
uint32_t field_32_2;
int64_t field_64_2;
};

#pragma pack(pop)

17 changes: 17 additions & 0 deletions lldb/test/API/lang/swift/clangimporter/custom_alignment/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import Module

struct Value {
var x: Int32 = 1
var s = Struct()
}

func f() {
var v = Value()
v.s.field_64_1 = 100;
v.s.field_32_1 = 200;
v.s.field_32_2 = 300;
v.s.field_64_2 = 400;
print(v) // break here
}

f()
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Module {
header "header.h"
export *
}

0 comments on commit 8c2a65f

Please sign in to comment.