Skip to content

[lldb] Add parent address to Task synthetic provider #10936

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 4 commits into
base: swift/release/6.2
Choose a base branch
from

Conversation

kastiglione
Copy link

@kastiglione kastiglione commented Jul 1, 2025

Display the address of a Task's parent (or 0x0000000 for root tasks).

Exposing a Task's parent will allow:

  • inspection of parent task (task info <addr>)
  • viewing the parent Task's backtrace (task backtrace <addr>)
  • selecting the parent Task's as a thread (task select <addr>)

rdar://147851193

@kastiglione
Copy link
Author

@swift-ci test

parent_addr = process_sp->ReadPointerFromMemory(
m_task_ptr + ChildFragmentOffset, status);
if (status.Fail() || parent_addr == LLDB_INVALID_ADDRESS)
parent_addr = 0;

Choose a reason for hiding this comment

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

is this really what we want to do here? When the task has no parent, does the runtime write a 0 to its slot, or do we expect an error?

If the runtime is explicitly writing a 0 and we don't expect the memory read to fail, I think we can just return nullptr here.

Choose a reason for hiding this comment

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

For the case of a parent-less task, should we try to customize the formatter output to say something "root task" or "no parent", instead of 0s?

I think 0s could give users the impression that the debugger failed to get the value

Copy link
Author

Choose a reason for hiding this comment

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

When the task has no parent, does the runtime write a 0 to its slot

A swift Task can have tail allocated "fragments", including a ChildFragment. Child tasks have a ChildFragment, while root tasks do not.

One way to model that is to make the existence of a parent conditional. In other words, for a root task, no parent member will be shown at all. The reason I didn't do that is:

  1. Users might find it confusing (why is there a parent some times, but not other times)
  2. It makes the synthetic child provider more complex (which is fine if we have good reason)

For the case of a parent-less task, should we try to customize the formatter output to say something "root task" or "no parent", instead of 0s?

The parent member needs a data type, which currently is UnsafeRawPointer. To show a task-specific string like "root task", we'd need to use some other data type, one we invent ourselves. This adds complexity, and will be exposed to users who might wonder "what's a LLDBParentTaskPointer?".

We could put a string like "root task" into Task's summary formatter. In which case the parent = 0x0000... would be accompanied with "root task" in the summary string, which should explain the parent address.

On this subject, one of the questions I have for reviewers is the name of this member. I used parent, but felt like make it should be parent_addr. The main reason I didn't do that is the provider has an address field, and I didn't like the inconsistency of using address and addr, and I didn't like the verbose choice of parent_address. Maybe we can rename address to addr, and then use parent_addr. Thoughts? I think including addr in the name might make it more clear that a bunch of zeros means root task/no parent.

Copy link
Author

Choose a reason for hiding this comment

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

A swift Task can have tail allocated "fragments", including a ChildFragment. Child tasks have a ChildFragment, while root tasks do not.

I misspoke. A root task will of course have a ChildFragment if it has children.

Copy link
Author

Choose a reason for hiding this comment

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

Adrian's suggestion is to have the parent's type be UnsafeRawPointer?, and will show nil when there's no parent. Works for me, what do you think Felipe?

Choose a reason for hiding this comment

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

yup that sounds good to me!

@kastiglione
Copy link
Author

@swift-ci test

@kastiglione kastiglione marked this pull request as ready for review July 2, 2025 17:06
@kastiglione kastiglione requested a review from a team as a code owner July 2, 2025 17:06
@kastiglione
Copy link
Author

@swift-ci test

@kastiglione
Copy link
Author

#10947

@swift-ci test

Copy link

@felipepiovezan felipepiovezan left a comment

Choose a reason for hiding this comment

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

lgtm! excited to see this merged!

@kastiglione
Copy link
Author

@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