This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Add matching based on Python callbacks for data formatters.
ClosedPublic

Authored by jgorbe on Oct 11 2022, 1:05 AM.

Details

Summary

This patch adds a new matching method for data formatters, in addition
to the existing exact typename and regex-based matching. The new method
allows users to specify the name of a Python callback function that
takes a SBType object and decides whether the type is a match or not.

Here is an overview of the changes performed:

  • Add a new eFormatterMatchCallback matching type, and logic to handle it in TypeMatcher and SBTypeNameSpecifier.
  • Extend FormattersMatchCandidate instances with a pointer to the current ScriptInterpreter and the TypeImpl corresponding to the candidate type, so we can run registered callbacks and pass the type to them. All matcher search functions now receive a FormattersMatchCandidate instead of a type name.
  • Add some glue code to ScriptInterpreterPython and the SWIG bindings to allow calling a formatter matching callback. Most of this code is modeled after the equivalent code for watchpoint callback functions.
  • Add an API test for the new callback-based matching feature.

For more context, please check the RFC thread where this feature was
originally discussed:
https://discourse.llvm.org/t/rfc-python-callback-for-data-formatters-type-matching/64204/11

Diff Detail

Event Timeline

jgorbe created this revision.Oct 11 2022, 1:05 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 11 2022, 1:05 AM
jgorbe requested review of this revision.Oct 11 2022, 1:05 AM
labath added inline comments.Oct 14 2022, 4:11 AM
lldb/source/Commands/CommandObjectType.cpp
2306–2312

Is that even possible? Like, this command can be run before any binaries/debug info is loaded, right? Maybe we should just call that WAI?

lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
2159–2167

I think we already had code like this somewhere, but these two versions are completely equivalent.

jgorbe updated this revision to Diff 467987.Oct 14 2022, 5:58 PM

Address review comments.

jgorbe marked 2 inline comments as done.Oct 14 2022, 6:00 PM
jgorbe added inline comments.
lldb/source/Commands/CommandObjectType.cpp
2306–2312

You're right. I hadn't though of the case where we have no target yet. Changed the comments in this file and a similar one in lldb/include/lldb/DataFormatters/FormattersContainer.h to remove the TODO and indicate this is WAI. Thanks!

lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
2159–2167

Done!

labath accepted this revision.Oct 17 2022, 11:40 PM

Seems fine to me. Jim, Med, do you want to add anything?

This revision is now accepted and ready to land.Oct 17 2022, 11:40 PM
This revision was automatically updated to reflect the committed changes.
jgorbe marked 2 inline comments as done.