Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lldb/bindings/interface/SBFrame.i
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@ public:
lldb::SBStructuredData
GetLanguageSpecificData ();

bool
IsSwiftThunk ();

STRING_EXTENSION(SBFrame)

#ifdef SWIGPYTHON
Expand Down
28 changes: 28 additions & 0 deletions lldb/bindings/python/static-binding/LLDBWrapPython.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32459,6 +32459,33 @@ SWIGINTERN PyObject *_wrap_SBFrame_GetLanguageSpecificData(PyObject *SWIGUNUSEDP
}


SWIGINTERN PyObject *_wrap_SBFrame_IsSwiftThunk(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
lldb::SBFrame *arg1 = (lldb::SBFrame *) 0 ;
void *argp1 = 0 ;
int res1 = 0 ;
PyObject *swig_obj[1] ;
bool result;

if (!args) SWIG_fail;
swig_obj[0] = args;
res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_lldb__SBFrame, 0 | 0 );
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "SBFrame_IsSwiftThunk" "', argument " "1"" of type '" "lldb::SBFrame *""'");
}
arg1 = reinterpret_cast< lldb::SBFrame * >(argp1);
{
SWIG_PYTHON_THREAD_BEGIN_ALLOW;
result = (bool)(arg1)->IsSwiftThunk();
SWIG_PYTHON_THREAD_END_ALLOW;
}
resultobj = SWIG_From_bool(static_cast< bool >(result));
return resultobj;
fail:
return NULL;
}


SWIGINTERN PyObject *_wrap_SBFrame___str__(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
lldb::SBFrame *arg1 = (lldb::SBFrame *) 0 ;
Expand Down Expand Up @@ -82565,6 +82592,7 @@ static PyMethodDef SwigMethods[] = {
""},
{ "SBFrame_GetDescription", _wrap_SBFrame_GetDescription, METH_VARARGS, "SBFrame_GetDescription(SBFrame self, SBStream description) -> bool"},
{ "SBFrame_GetLanguageSpecificData", _wrap_SBFrame_GetLanguageSpecificData, METH_O, "SBFrame_GetLanguageSpecificData(SBFrame self) -> SBStructuredData"},
{ "SBFrame_IsSwiftThunk", _wrap_SBFrame_IsSwiftThunk, METH_O, "SBFrame_IsSwiftThunk(SBFrame self) -> bool"},
{ "SBFrame___str__", _wrap_SBFrame___str__, METH_O, "SBFrame___str__(SBFrame self) -> std::string"},
{ "SBFrame_swigregister", SBFrame_swigregister, METH_O, NULL},
{ "SBFrame_swiginit", SBFrame_swiginit, METH_VARARGS, NULL},
Expand Down
4 changes: 4 additions & 0 deletions lldb/bindings/python/static-binding/lldb.py
Original file line number Diff line number Diff line change
Expand Up @@ -6013,6 +6013,10 @@ def GetLanguageSpecificData(self):
r"""GetLanguageSpecificData(SBFrame self) -> SBStructuredData"""
return _lldb.SBFrame_GetLanguageSpecificData(self)

def IsSwiftThunk(self):
r"""IsSwiftThunk(SBFrame self) -> bool"""
return _lldb.SBFrame_IsSwiftThunk(self)

def __str__(self):
r"""__str__(SBFrame self) -> std::string"""
return _lldb.SBFrame___str__(self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ class SwiftLanguageRuntime : public LanguageRuntime {

void ModulesDidLoad(const ModuleList &module_list) override;

bool IsSymbolARuntimeThunk(const Symbol &symbol) override;

/// Mangling support.
/// \{
/// Use these passthrough functions rather than calling into Swift directly,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,15 @@ static lldb::ThreadPlanSP GetStepThroughTrampolinePlan(Thread &thread,
return new_thread_plan_sp;
}

bool SwiftLanguageRuntime::IsSymbolARuntimeThunk(const Symbol &symbol) {
llvm::StringRef symbol_name =
symbol.GetMangled().GetMangledName().GetStringRef();
if (symbol_name.empty())
return false;
swift::Demangle::Context demangle_ctx;
return demangle_ctx.isThunkSymbol(symbol_name);
}

bool SwiftLanguageRuntime::IsSwiftMangledName(llvm::StringRef name) {
return swift::Demangle::isSwiftSymbol(name);
}
Expand Down
2 changes: 2 additions & 0 deletions lldb/test/API/lang/swift/swift_thunk/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SWIFT_SOURCES := main.swift
include Makefile.rules
26 changes: 26 additions & 0 deletions lldb/test/API/lang/swift/swift_thunk/TestIsSwiftThunk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import lldb
from lldbsuite.test.decorators import *
import lldbsuite.test.lldbtest as lldbtest
import lldbsuite.test.lldbutil as lldbutil

class TestCase(lldbtest.TestBase):

mydir = lldbtest.TestBase.compute_mydir(__file__)

@swiftTest
@skipIf(oslist=['windows', 'linux'])
def test(self):
"""Test SBFrame.IsSwiftThunk()"""
self.build()

# `breaker` is called on a protocol, which causes execution to run
# through a protocol witness thunk. The first stop is that thunk.
_, process, thread, _ = lldbutil.run_to_name_breakpoint(self, "breaker")
frame = thread.frames[0]
self.assertTrue(frame.IsSwiftThunk())

# Proceed to the real implementation.
process.Continue()
frame = thread.frames[0]
self.assertEqual(frame.function.GetDisplayName(), "S.breaker()")
self.assertFalse(frame.IsSwiftThunk())
10 changes: 10 additions & 0 deletions lldb/test/API/lang/swift/swift_thunk/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
protocol P {
func breaker() -> Int
}

struct S: P {
func breaker() -> Int { 41 }
}

let p: P = S()
print(p.breaker())