From 47d75699e4fc6316eb0ec53b289c4e031d3ada06 Mon Sep 17 00:00:00 2001 From: Dave Lee Date: Wed, 5 May 2021 15:57:48 -0700 Subject: [PATCH 1/3] [lldb] Restore Swift IsSymbolARuntimeThunk override --- .../Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.h | 2 ++ .../LanguageRuntime/Swift/SwiftLanguageRuntimeNames.cpp | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.h b/lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.h index 109d74993d0f2..ff97dd7b1c091 100644 --- a/lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.h +++ b/lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.h @@ -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, diff --git a/lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntimeNames.cpp b/lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntimeNames.cpp index 9cee22c496687..179879009c90b 100644 --- a/lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntimeNames.cpp +++ b/lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntimeNames.cpp @@ -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); } From dce0d46220e29c6144cbb4c6413b9471fd8bf54c Mon Sep 17 00:00:00 2001 From: Dave Lee Date: Wed, 5 May 2021 17:06:08 -0700 Subject: [PATCH 2/3] add test via exposed IsSwiftThunk in python bindings --- lldb/bindings/interface/SBFrame.i | 3 ++ .../python/static-binding/LLDBWrapPython.cpp | 28 +++++++++++++++++++ lldb/bindings/python/static-binding/lldb.py | 4 +++ lldb/test/API/lang/swift/swift_thunk/Makefile | 2 ++ .../swift/swift_thunk/TestIsSwiftThunk.py | 26 +++++++++++++++++ .../API/lang/swift/swift_thunk/main.swift | 10 +++++++ 6 files changed, 73 insertions(+) create mode 100644 lldb/test/API/lang/swift/swift_thunk/Makefile create mode 100644 lldb/test/API/lang/swift/swift_thunk/TestIsSwiftThunk.py create mode 100644 lldb/test/API/lang/swift/swift_thunk/main.swift diff --git a/lldb/bindings/interface/SBFrame.i b/lldb/bindings/interface/SBFrame.i index fa30ae91cc4b7..807bee1b436a4 100644 --- a/lldb/bindings/interface/SBFrame.i +++ b/lldb/bindings/interface/SBFrame.i @@ -288,6 +288,9 @@ public: lldb::SBStructuredData GetLanguageSpecificData (); + bool + IsSwiftThunk (); + STRING_EXTENSION(SBFrame) #ifdef SWIGPYTHON diff --git a/lldb/bindings/python/static-binding/LLDBWrapPython.cpp b/lldb/bindings/python/static-binding/LLDBWrapPython.cpp index 42a555dc00968..ca5c137fe45c4 100644 --- a/lldb/bindings/python/static-binding/LLDBWrapPython.cpp +++ b/lldb/bindings/python/static-binding/LLDBWrapPython.cpp @@ -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 ; @@ -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}, diff --git a/lldb/bindings/python/static-binding/lldb.py b/lldb/bindings/python/static-binding/lldb.py index e3a79ed4df7d1..1d081fffad1cb 100644 --- a/lldb/bindings/python/static-binding/lldb.py +++ b/lldb/bindings/python/static-binding/lldb.py @@ -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) diff --git a/lldb/test/API/lang/swift/swift_thunk/Makefile b/lldb/test/API/lang/swift/swift_thunk/Makefile new file mode 100644 index 0000000000000..cb73d9276d0ed --- /dev/null +++ b/lldb/test/API/lang/swift/swift_thunk/Makefile @@ -0,0 +1,2 @@ +SWIFT_SOURCES := main.swift +include Makefile.rules diff --git a/lldb/test/API/lang/swift/swift_thunk/TestIsSwiftThunk.py b/lldb/test/API/lang/swift/swift_thunk/TestIsSwiftThunk.py new file mode 100644 index 0000000000000..6bdfac1ab24d8 --- /dev/null +++ b/lldb/test/API/lang/swift/swift_thunk/TestIsSwiftThunk.py @@ -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()) diff --git a/lldb/test/API/lang/swift/swift_thunk/main.swift b/lldb/test/API/lang/swift/swift_thunk/main.swift new file mode 100644 index 0000000000000..2d19627c34e83 --- /dev/null +++ b/lldb/test/API/lang/swift/swift_thunk/main.swift @@ -0,0 +1,10 @@ +protocol P { + func breaker() -> Int +} + +struct S: P { + func breaker() -> Int { 41 } +} + +let p: P = S() +print(p.breaker()) From 97082e1510001c361fc97fe9da57e843ce26b307 Mon Sep 17 00:00:00 2001 From: Dave Lee Date: Thu, 6 May 2021 09:24:38 -0700 Subject: [PATCH 3/3] Revert "add test via exposed IsSwiftThunk in python bindings" This reverts commit dce0d46220e29c6144cbb4c6413b9471fd8bf54c. --- lldb/bindings/interface/SBFrame.i | 3 -- .../python/static-binding/LLDBWrapPython.cpp | 28 ------------------- lldb/bindings/python/static-binding/lldb.py | 4 --- lldb/test/API/lang/swift/swift_thunk/Makefile | 2 -- .../swift/swift_thunk/TestIsSwiftThunk.py | 26 ----------------- .../API/lang/swift/swift_thunk/main.swift | 10 ------- 6 files changed, 73 deletions(-) delete mode 100644 lldb/test/API/lang/swift/swift_thunk/Makefile delete mode 100644 lldb/test/API/lang/swift/swift_thunk/TestIsSwiftThunk.py delete mode 100644 lldb/test/API/lang/swift/swift_thunk/main.swift diff --git a/lldb/bindings/interface/SBFrame.i b/lldb/bindings/interface/SBFrame.i index 807bee1b436a4..fa30ae91cc4b7 100644 --- a/lldb/bindings/interface/SBFrame.i +++ b/lldb/bindings/interface/SBFrame.i @@ -288,9 +288,6 @@ public: lldb::SBStructuredData GetLanguageSpecificData (); - bool - IsSwiftThunk (); - STRING_EXTENSION(SBFrame) #ifdef SWIGPYTHON diff --git a/lldb/bindings/python/static-binding/LLDBWrapPython.cpp b/lldb/bindings/python/static-binding/LLDBWrapPython.cpp index ca5c137fe45c4..42a555dc00968 100644 --- a/lldb/bindings/python/static-binding/LLDBWrapPython.cpp +++ b/lldb/bindings/python/static-binding/LLDBWrapPython.cpp @@ -32459,33 +32459,6 @@ 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 ; @@ -82592,7 +82565,6 @@ 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}, diff --git a/lldb/bindings/python/static-binding/lldb.py b/lldb/bindings/python/static-binding/lldb.py index 1d081fffad1cb..e3a79ed4df7d1 100644 --- a/lldb/bindings/python/static-binding/lldb.py +++ b/lldb/bindings/python/static-binding/lldb.py @@ -6013,10 +6013,6 @@ 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) diff --git a/lldb/test/API/lang/swift/swift_thunk/Makefile b/lldb/test/API/lang/swift/swift_thunk/Makefile deleted file mode 100644 index cb73d9276d0ed..0000000000000 --- a/lldb/test/API/lang/swift/swift_thunk/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -SWIFT_SOURCES := main.swift -include Makefile.rules diff --git a/lldb/test/API/lang/swift/swift_thunk/TestIsSwiftThunk.py b/lldb/test/API/lang/swift/swift_thunk/TestIsSwiftThunk.py deleted file mode 100644 index 6bdfac1ab24d8..0000000000000 --- a/lldb/test/API/lang/swift/swift_thunk/TestIsSwiftThunk.py +++ /dev/null @@ -1,26 +0,0 @@ -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()) diff --git a/lldb/test/API/lang/swift/swift_thunk/main.swift b/lldb/test/API/lang/swift/swift_thunk/main.swift deleted file mode 100644 index 2d19627c34e83..0000000000000 --- a/lldb/test/API/lang/swift/swift_thunk/main.swift +++ /dev/null @@ -1,10 +0,0 @@ -protocol P { - func breaker() -> Int -} - -struct S: P { - func breaker() -> Int { 41 } -} - -let p: P = S() -print(p.breaker())