This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Refactor Platform::ResolveExecutable
ClosedPublic

Authored by labath on Nov 9 2021, 7:56 AM.

Details

Summary

Module resolution is probably the most complex piece of lldb [citation
needed], with numerous levels of abstraction, each one implementing
various retry and fallback strategies.

It is also a very repetitive, with only small differences between
"host", "remote-and-connected" and "remote-but-not-(yet)-connected"
scenarios.

The goal of this patch (first in series) is to reduce the number of
abstractions, and deduplicate the code.

One of the reasons for this complexity is the tension between the desire
to offload the process of module resolution to the remote platform
instance (that's how most other platform methods work), and the desire
to keep it local to the outer platform class (its easier to subclass the
outer class, and it generally makes more sense).

This patch resolves that conflict in favour of doing everything in the
outer class. The gdb-remote (our only remote platform) implementation of
ResolveExecutable was not doing anything gdb-specific, and was rather
similar to the other implementations of that method (any divergence is
most likely the result of fixes not being applied everywhere rather than
intentional).

It does this by excising the remote platform out of the resolution
codepath. The gdb-remote implementation of ResolveExecutable is moved to
Platform::ResolveRemoteExecutable, and the (only) call site is
redirected to that. On its own, this does not achieve (much), but it
creates new opportunities for layer peeling and code sharing, since all
of the code now lives closer together.

Diff Detail

Event Timeline

labath requested review of this revision.Nov 9 2021, 7:56 AM
labath created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptNov 9 2021, 7:56 AM
labath added inline comments.Nov 9 2021, 7:59 AM
lldb/source/Target/Platform.cpp
865

Next step is to merge this with the if (!m_remote_platform_sp) path in RemoteAwarePlatform::ResolveExecutable

LGTM. I will ok soon if no one else chimes in!

Thanks, Greg.

clayborg accepted this revision.Nov 10 2021, 3:06 PM
This revision is now accepted and ready to land.Nov 10 2021, 3:06 PM
This revision was automatically updated to reflect the committed changes.