From 768adbb55b590cc9ef7980482b6d9a9c1b3f6a99 Mon Sep 17 00:00:00 2001 From: Charles Zablit Date: Wed, 4 Jun 2025 19:04:38 +0100 Subject: [PATCH 1/2] [lldb][Format] Display only the inlined Swift frame name in backtraces if available --- .../Plugins/Language/Swift/SwiftLanguage.cpp | 5 ++- .../inlined-function-name-backtrace.test | 33 +++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 lldb/test/Shell/Swift/inlined-function-name-backtrace.test diff --git a/lldb/source/Plugins/Language/Swift/SwiftLanguage.cpp b/lldb/source/Plugins/Language/Swift/SwiftLanguage.cpp index a4e34603f474c..daec35f32f3f4 100644 --- a/lldb/source/Plugins/Language/Swift/SwiftLanguage.cpp +++ b/lldb/source/Plugins/Language/Swift/SwiftLanguage.cpp @@ -1761,7 +1761,7 @@ std::string SwiftLanguage::GetFunctionName(const SymbolContext &sc, if (sc.function->GetLanguage() != eLanguageTypeSwift) return {}; std::string name = SwiftLanguageRuntime::DemangleSymbolAsString( - sc.function->GetMangled().GetMangledName().GetStringRef(), + sc.GetPossiblyInlinedFunctionName().GetMangledName(), SwiftLanguageRuntime::eSimplified, &sc, exe_ctx); if (name.empty()) return {}; @@ -1879,8 +1879,7 @@ SwiftLanguage::GetDemangledFunctionNameWithoutArguments(Mangled mangled) const { ConstString mangled_name = mangled.GetMangledName(); ConstString demangled_name = mangled.GetDemangledName(); if (demangled_name && mangled_name) { - if (SwiftLanguageRuntime::IsSwiftMangledName( - demangled_name.GetStringRef())) { + if (SwiftLanguageRuntime::IsSwiftMangledName(mangled_name.GetStringRef())) { lldb_private::ConstString basename; bool is_method = false; if (SwiftLanguageRuntime::MethodName::ExtractFunctionBasenameFromMangled( diff --git a/lldb/test/Shell/Swift/inlined-function-name-backtrace.test b/lldb/test/Shell/Swift/inlined-function-name-backtrace.test new file mode 100644 index 0000000000000..8b264d27935b4 --- /dev/null +++ b/lldb/test/Shell/Swift/inlined-function-name-backtrace.test @@ -0,0 +1,33 @@ +# Test Swift function name printing in backtraces. + +# RUN: split-file %s %t +# RUN: %target-swiftc -g -O %t/main.swift -o %t.out +# RUN: %lldb -x -b -s %t/commands.input %t.out -o exit 2>&1 \ +# RUN: | FileCheck %s + +#--- main.swift +@inline(never) +func baz(_ a: Int) -> Int { + return a * 2 +} + +@inline(__always) +func foo(_ a: Int, _ b: Int) -> Int { + return a * b * baz(a) +} + +func bar() { + let baz = foo(4, 5) +} + +bar() + +#--- commands.input +b baz + +run +bt + +# CHECK: `baz(a={{.*}}) at main.swift:3:14 [opt] +# CHECK: `foo(a={{.*}}, b={{.*}}) at main.swift:8:17 [opt] [inlined] +# CHECK: `bar() at main.swift:12:15 [opt] [inlined] From 5ffc6cf28b3fe433ee9e0f2f33068ae8fec41009 Mon Sep 17 00:00:00 2001 From: Charles Zablit Date: Mon, 16 Jun 2025 12:16:24 +0100 Subject: [PATCH 2/2] mark the test as failing on windows --- lldb/test/Shell/Swift/inlined-function-name-backtrace.test | 1 + 1 file changed, 1 insertion(+) diff --git a/lldb/test/Shell/Swift/inlined-function-name-backtrace.test b/lldb/test/Shell/Swift/inlined-function-name-backtrace.test index 8b264d27935b4..cdbb76d9aa751 100644 --- a/lldb/test/Shell/Swift/inlined-function-name-backtrace.test +++ b/lldb/test/Shell/Swift/inlined-function-name-backtrace.test @@ -1,5 +1,6 @@ # Test Swift function name printing in backtraces. +# XFAIL: system-windows # RUN: split-file %s %t # RUN: %target-swiftc -g -O %t/main.swift -o %t.out # RUN: %lldb -x -b -s %t/commands.input %t.out -o exit 2>&1 \