This is an archive of the discontinued LLVM Phabricator instance.

[lldb/Process] Populate queues in Scripted Process
ClosedPublic

Authored by mib on Dec 12 2022, 9:19 AM.

Details

Summary

This patch enhances queue support in Scripted Processes.

Scripted Threads could already report their queue name if they had one,
but this information was only surfaced when getting the process and
thread status.

However, no queue was create and added to the scripted process queue
list. This patch improves that by creating a queue from the scripted
thread queue name. For now, it uses an invalid queue id, since the
scripted thread doesn't expose this capability yet, but this could
easily be supported if the queue id information is available.

rdar://98844004

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>

Diff Detail

Event Timeline

mib created this revision.Dec 12 2022, 9:19 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 12 2022, 9:19 AM
mib requested review of this revision.Dec 12 2022, 9:19 AM
JDevlieghere added inline comments.Dec 12 2022, 9:55 AM
lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp
757 ↗(On Diff #482163)

Comparing the plugin name defeats the abstraction a plugin is meant to provide. While we have other instances of LLDB breaking these abstractions, I don't recall other places where we compare the plugin name. The way we normally deal with this is extend the plugins capability (by adding a method) and implementing it accordingly for all the plugins (or have a sane default).

Based on the description of the patch it's not clear to me why this is special for scripted processes. If we need to special case this I'd like to see a comment explaining why.

mib added inline comments.Dec 12 2022, 11:26 AM
lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp
757 ↗(On Diff #482163)

I agree, but in this case, Process::UpdateQueueListIfNeeded calls the System Runtime plugin PopulateQueueList method and since queues are only supported on macOS, it does make sense in my opinion.

I think we definitely shouldn't add another system runtime for scripted processes just to support that case, so adding a special case for scripted processes seems to be the less intrusive way to implement it.

labath added a subscriber: labath.Dec 13 2022, 7:24 AM
labath added inline comments.
lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp
757 ↗(On Diff #482163)

I'm with Jonas here. Even though these Queue concepts are a big mystery do me, I would like to understand why the scripted processes do can not go through the same code path as "regular" ones.

mib added inline comments.Dec 13 2022, 7:33 AM
lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp
757 ↗(On Diff #482163)

The reason here why this is not implemented at the Scripted Process plugin level, is because UpdateQueueListIfNeeded is a base method of the Process base class that's not expected to be redefined in the process plugin.

I guess we could either make UpdateQueueListIfNeeded virtual and keep the base class implementation the default and override it in the Scripted Process plugin class or we can have a virtual void Process::DoUpdateQueueList() {} method that would be called in Process::UpdateQueueListIfNeeded.

mib updated this revision to Diff 482486.Dec 13 2022, 7:51 AM
mib marked an inline comment as done.

Make use of the process plugin model to avoid adding a special case on the system runtime plugin.

That definitely looks much better. As I understand it, the scripted thread interface is more high-level that our internal thread interface, and that means it is computing its queue by itself, instead of delegating the work to a separate plugin. That makes sense to me.

mib added a comment.Dec 13 2022, 7:56 AM

That definitely looks much better. As I understand it, the scripted thread interface is more high-level that our internal thread interface, and that means it is computing its queue by itself, instead of delegating the work to a separate plugin. That makes sense to me.

Correct, Scripted Thread will report "pre-computed" queues to lldb, so it won't need to rely on the system runtime to resolve them in lldb.

mib updated this revision to Diff 482495.Dec 13 2022, 8:15 AM
JDevlieghere accepted this revision.Dec 13 2022, 1:17 PM

This looks like what I had in mind. LGTM.

This revision is now accepted and ready to land.Dec 13 2022, 1:17 PM
This revision was landed with ongoing or failed builds.Jan 12 2023, 7:21 PM
This revision was automatically updated to reflect the committed changes.