Skip to content

[lldb][Format] Display only the inlined Swift frame name in backtraces if available #10786

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: swift/release/6.2
Choose a base branch
from

Conversation

charles-zablit
Copy link

This PR is a port of the changes made in llvm#135343 to the Swift plugin.

We remove the prefix of [inlined] to cut on the noise but keep the [inlined] itself until we implement a way to use a formatter to display or not.

Also notice that on the screenshots below, the frame had a return type for inlined functions, but not for regular functions. Both now have the same behavior.

Before:
Screenshot 2025-06-04 at 19 06 14

After:
Screenshot 2025-06-04 at 19 06 43

@charles-zablit charles-zablit requested a review from a team as a code owner June 4, 2025 18:09
@@ -352,7 +352,7 @@ ConstString Mangled::GetDemangledNameImpl(bool force, // BEGIN SWIFT
Log *log = GetLog(LLDBLog::Demangle);
LLDB_LOGF(log, "demangle swift: %s", mangled_name);
std::string demangled(SwiftLanguageRuntime::DemangleSymbolAsString(
mangled_name, SwiftLanguageRuntime::eTypeName, sc));
mangled_name, SwiftLanguageRuntime::eSimplified, sc));
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is needed to properly return the name of the demangled name and nothing else. Otherwise, we get an output that's too verbose like main.foo instead of just foo.

Copy link

@Michael137 Michael137 Jun 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this PR is just about making the inlined frame name cleaner, should this be done in a separate PR?

Copy link
Author

@charles-zablit charles-zablit Jun 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To give some context:
The call stack for this method is:

  1. Mangled::GetDemangledNameImpl
  2. Mangled::GetDemangledName
  3. SwiftLanguage::GetDemangledFunctionNameWithoutArguments
  4. Mangled::GetName
  5. SwiftLanguage::GetFunctionDisplayName

With eTypeName this is what the output looks like:
Screenshot 2025-06-05 at 11 51 34

With eSimplified:
Screenshot 2025-06-04 at 19 06 43

This is more uniform with the rest of the backtrace.

I will bring this change in a separate PR 👍

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I take that back, sorry, notice that the frame #0 with eTypeName is test.baz(...
but with eSimplified it's simply baz(... which is the same as the current behavior of lldb.

I think this commit should stay in this patch.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we not want the return type and scope in the name though? I thought we'll make it configurable in #10710. But for now we should show as much info as we can? I'm probably still missing something

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a bit surprised the issue is all the way down in Mangled::GetDemangledNameImpl

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I replied to the wrong thread here: #10786 (comment)

To add on that, we don't remove the scope entirely, we just remove the redundant test part which is just the name of the program. If the frame is a method foo on the class Bar, we still print Bar.foo for both inlined and non inlined methods.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's some test failures here on the macOS CI:

14:35:40    lldb-api :: lang/swift/async/frame/variables_multiple_frames/TestSwiftAsyncFrameVarMultipleFrames.py
14:35:40    lldb-api :: lang/swift/async/stepping/step-in/task-switch/TestSwiftTaskSwitch.py
14:35:40    lldb-api :: lang/swift/async/tasks/TestSwiftTaskSelect.py
14:35:40    lldb-api :: lang/swift/async/unwind/short_unwind/TestSwiftShortAsyncUnwind.py
14:35:40    lldb-api :: lang/swift/async/unwind/unwind_in_all_instructions/TestSwiftAsyncUnwindAllInstructions.py
14:35:40    lldb-api :: lang/swift/bt_printing/TestSwiftBacktracePrinting.py
14:35:40    lldb-api :: lang/swift/generic_function_name/TestSwiftGenericFunctionName.py
14:35:40    lldb-api :: lang/swift/macro/TestSwiftMacro.py
14:35:40    lldb-api :: lang/swift/protocols/class_protocol/TestSwiftClassConstrainedProtocolArgument.py
14:35:40    lldb-api :: lang/swift/protocols/stepping_through_witness/TestSwiftSteppingThroughWitness.py
14:35:40    lldb-api :: lang/swift/step_into_override/TestStepIntoOverride.py
14:35:40    lldb-api :: lang/swift/swift_callback/TestSwiftCallback.py
14:35:40    lldb-api :: lang/swift/variables/func/TestSwiftFunctionVariables.py
14:35:40    lldb-shell :: SwiftREPL/NSObjectSubclass.test

I suspect they might be related to this part here. But haven't looked closely

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They seem to all be related. There are 2 failures:

  1. Tests that fail because main.foo becomes foo, which is what we want.
  2. Tests that fail because async functions were printed with their return types, so foo() async -> Int becomes foo() which is not a desirable change.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After more testing, it seems that too many methods depend on Mangled::GetDemangledNameImpl to change its behavior.

c6b8ffa introduces a better approach, keeping the same results as the screenshots above, but without breaking the API and tests that depend on Mangled::GetDemangledNameImpl.

@Michael137
Copy link

@swift-ci test

@charles-zablit
Copy link
Author

@swift-ci test

@charles-zablit
Copy link
Author

charles-zablit commented Jun 6, 2025

The tests are failing because on macOS, the frame is represented as:
main [inlined] test.foo(a=Swift.Int @ scalar, b=Swift.Int @ scalar) -> Swift.Int at test.swift:8:17 [opt]

But on other systems, it's:
main [inlined] test.foo(a=1, b=1) -> Swift.Int at test.swift:8:17 [opt]

I marked the tests as XFAIL on non Darwin systems, but I'm not sure if it's the right call, we might want to fix this.

This is not a regression in this patch.

s << display_name;
s.PutCString(" [inlined] ");
display_name = inline_info->GetName().GetString();
s.PutCString("[inlined] ");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the back and forth, but now that we merged #10789 into 6.2, we can remove this

@Michael137
Copy link

The tests are failing because on macOS, the frame is represented as: main [inlined] test.foo(a=Swift.Int @ scalar, b=Swift.Int @ scalar) -> Swift.Int at test.swift:8:17 [opt]

But on other systems, it's: main [inlined] test.foo(a=1, b=1) -> Swift.Int at test.swift:8:17 [opt]

I marked the tests as XFAIL on non Darwin systems, but I'm not sure if it's the right call, we might want to fix this.

This is not a regression in this patch.

If it's not a regression then marking them as XFAIL is the right call. Actually the way it's formatted on Darwin is worse UX in my opinion, since we don't see the value.

Something to do with the way we're formatting the builtin Int. @kastiglione @adrian-prantl will know better. But we don't need to address it in this patch

@Michael137
Copy link

@swift-ci test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants