Skip to content
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

[lldb] Add APIs enabling OperatingSystem plugins to update ThreadPlanStack #122966

Conversation

felipepiovezan
Copy link
Contributor

@felipepiovezan felipepiovezan commented Jan 14, 2025

At the end of Process::UpdateThreadListIfNeeded, we see this comment:

      // Now update the plan stack map.
      // If we do have an OS plugin, any absent real threads in the
      // m_thread_list have already been removed from the ThreadPlanStackMap.
      // So any remaining threads are OS Plugin threads, and those we want to
      // preserve in case they show up again.
      m_thread_plans.Update(m_thread_list, clear_unused_threads);

In other words, if a OS plugin maps a real thread to a plugin thread, the plugin is expected to remove the thread plan of the real thread from m_thread_plans.
However, it is impossible to do so today: the APIs are simply not there. In fact, plugins don't even have access to m_thread_plans. This is not a problem for plugins who "report all threads", since LLDB will then clean up plans for any threads that are not present in the new list of threads (mapped real threads won't be in the new list). For plugins that do not report all threads, this is a problem.

There are two pieces missing here:
A) The OperatingSystem::UpdateThreadList function needs access to m_thread_plans.
B) ThreadPlanStack needs to expose the TIDs it currently knows about, since its methods (like Find, Erase) are all TID-based.

This commit provides these pieces so that future commits (and plugins) may make use of them.

Point A is currently addressed by passing m_thread_plans as a function argument to OperatingSystem::UpdateThreadList, however it would have been possible to make it public through an accessor method in Process.

…Stack

At the end of Process::UpdateThreadListIfNeeded, we see this comment:
```
      // Now update the plan stack map.
      // If we do have an OS plugin, any absent real threads in the
      // m_thread_list have already been removed from the ThreadPlanStackMap.
      // So any remaining threads are OS Plugin threads, and those we want to
      // preserve in case they show up again.
      m_thread_plans.Update(m_thread_list, clear_unused_threads);
```

In other words, if a OS plugin maps a real thread to a plugin thread,
the plugin is expected to remove the thread plan of the real thread from
`m_thread_plans`.
However, it is impossible to do so today: the APIs are simply not there.
In fact, plugins don't even have access to `m_thread_plans`. This is not
a problem for plugins who "report all threads", since LLDB will then
clean up plans for any threads that are not present in the new list of
threads (mapped real threads won't be in the new list). For plugins that
do _not_ report all threads, this is a problem.

There are two pieces missing here:
A) The `OperatingSystem::UpdateThreadList` function needs access to
m_thread_plans.
B) ThreadPlanStack needs to expose the TIDs it currently knows about,
since its methods (like Find, Erase) are all TID-based.

This commit provides these pieces so that future commits (and plugins)
may make use of them.

Point A is currently addressed by passing m_thread_plans as a function
argument to OperatingSystem::UpdateThreadList, however it would have
been possible to make it public through an accessor method in Process.
@felipepiovezan felipepiovezan force-pushed the felipe/operating-system-stack-api branch from 8dc10cc to c8e7e22 Compare January 14, 2025 21:04
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.

1 participant