Skip to content

Commit dce0d46

Browse files
committed
add test via exposed IsSwiftThunk in python bindings
1 parent 47d7569 commit dce0d46

File tree

6 files changed

+73
-0
lines changed

6 files changed

+73
-0
lines changed

lldb/bindings/interface/SBFrame.i

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,9 @@ public:
288288
lldb::SBStructuredData
289289
GetLanguageSpecificData ();
290290

291+
bool
292+
IsSwiftThunk ();
293+
291294
STRING_EXTENSION(SBFrame)
292295

293296
#ifdef SWIGPYTHON

lldb/bindings/python/static-binding/LLDBWrapPython.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32459,6 +32459,33 @@ SWIGINTERN PyObject *_wrap_SBFrame_GetLanguageSpecificData(PyObject *SWIGUNUSEDP
3245932459
}
3246032460

3246132461

32462+
SWIGINTERN PyObject *_wrap_SBFrame_IsSwiftThunk(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
32463+
PyObject *resultobj = 0;
32464+
lldb::SBFrame *arg1 = (lldb::SBFrame *) 0 ;
32465+
void *argp1 = 0 ;
32466+
int res1 = 0 ;
32467+
PyObject *swig_obj[1] ;
32468+
bool result;
32469+
32470+
if (!args) SWIG_fail;
32471+
swig_obj[0] = args;
32472+
res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_lldb__SBFrame, 0 | 0 );
32473+
if (!SWIG_IsOK(res1)) {
32474+
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "SBFrame_IsSwiftThunk" "', argument " "1"" of type '" "lldb::SBFrame *""'");
32475+
}
32476+
arg1 = reinterpret_cast< lldb::SBFrame * >(argp1);
32477+
{
32478+
SWIG_PYTHON_THREAD_BEGIN_ALLOW;
32479+
result = (bool)(arg1)->IsSwiftThunk();
32480+
SWIG_PYTHON_THREAD_END_ALLOW;
32481+
}
32482+
resultobj = SWIG_From_bool(static_cast< bool >(result));
32483+
return resultobj;
32484+
fail:
32485+
return NULL;
32486+
}
32487+
32488+
3246232489
SWIGINTERN PyObject *_wrap_SBFrame___str__(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
3246332490
PyObject *resultobj = 0;
3246432491
lldb::SBFrame *arg1 = (lldb::SBFrame *) 0 ;
@@ -82565,6 +82592,7 @@ static PyMethodDef SwigMethods[] = {
8256582592
""},
8256682593
{ "SBFrame_GetDescription", _wrap_SBFrame_GetDescription, METH_VARARGS, "SBFrame_GetDescription(SBFrame self, SBStream description) -> bool"},
8256782594
{ "SBFrame_GetLanguageSpecificData", _wrap_SBFrame_GetLanguageSpecificData, METH_O, "SBFrame_GetLanguageSpecificData(SBFrame self) -> SBStructuredData"},
82595+
{ "SBFrame_IsSwiftThunk", _wrap_SBFrame_IsSwiftThunk, METH_O, "SBFrame_IsSwiftThunk(SBFrame self) -> bool"},
8256882596
{ "SBFrame___str__", _wrap_SBFrame___str__, METH_O, "SBFrame___str__(SBFrame self) -> std::string"},
8256982597
{ "SBFrame_swigregister", SBFrame_swigregister, METH_O, NULL},
8257082598
{ "SBFrame_swiginit", SBFrame_swiginit, METH_VARARGS, NULL},

lldb/bindings/python/static-binding/lldb.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6013,6 +6013,10 @@ def GetLanguageSpecificData(self):
60136013
r"""GetLanguageSpecificData(SBFrame self) -> SBStructuredData"""
60146014
return _lldb.SBFrame_GetLanguageSpecificData(self)
60156015

6016+
def IsSwiftThunk(self):
6017+
r"""IsSwiftThunk(SBFrame self) -> bool"""
6018+
return _lldb.SBFrame_IsSwiftThunk(self)
6019+
60166020
def __str__(self):
60176021
r"""__str__(SBFrame self) -> std::string"""
60186022
return _lldb.SBFrame___str__(self)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
SWIFT_SOURCES := main.swift
2+
include Makefile.rules
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import lldb
2+
from lldbsuite.test.decorators import *
3+
import lldbsuite.test.lldbtest as lldbtest
4+
import lldbsuite.test.lldbutil as lldbutil
5+
6+
class TestCase(lldbtest.TestBase):
7+
8+
mydir = lldbtest.TestBase.compute_mydir(__file__)
9+
10+
@swiftTest
11+
@skipIf(oslist=['windows', 'linux'])
12+
def test(self):
13+
"""Test SBFrame.IsSwiftThunk()"""
14+
self.build()
15+
16+
# `breaker` is called on a protocol, which causes execution to run
17+
# through a protocol witness thunk. The first stop is that thunk.
18+
_, process, thread, _ = lldbutil.run_to_name_breakpoint(self, "breaker")
19+
frame = thread.frames[0]
20+
self.assertTrue(frame.IsSwiftThunk())
21+
22+
# Proceed to the real implementation.
23+
process.Continue()
24+
frame = thread.frames[0]
25+
self.assertEqual(frame.function.GetDisplayName(), "S.breaker()")
26+
self.assertFalse(frame.IsSwiftThunk())
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
protocol P {
2+
func breaker() -> Int
3+
}
4+
5+
struct S: P {
6+
func breaker() -> Int { 41 }
7+
}
8+
9+
let p: P = S()
10+
print(p.breaker())

0 commit comments

Comments
 (0)