This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Remove the global platform list
ClosedPublic

Authored by labath on Mar 2 2022, 6:23 AM.

Details

Summary

This patch moves the platform creation and selection logic into the
per-debugger platform lists. I've tried to keep functional changes to a
minimum -- the main (only) observable difference in this change is that
APIs, which select a platform by name (e.g.,
Debugger::SetCurrentPlatform) will not automatically pick up a platform
associated with another debugger (or no debugger at all).

I've also added several tests for this functionality -- one of the
pleasant consequences of the debugger isolation is that it is now
possible to test the platform selection and creation logic.

This is a product of the discussion at
https://discourse.llvm.org/t/multiple-platforms-with-the-same-name/59594.

Diff Detail

Event Timeline

labath created this revision.Mar 2 2022, 6:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 2 2022, 6:23 AM
Herald added subscribers: mgorny, emaste. · View Herald Transcript
labath requested review of this revision.Mar 2 2022, 6:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 2 2022, 6:23 AM
JDevlieghere accepted this revision.Mar 2 2022, 10:28 AM

It's always great to see changes that enable more testing. I left one inline comment/nit but besides that this LGTM.

lldb/source/Target/Platform.cpp
1957

[Nit/pedantic] We have a few calls to IsCompatibleArchitecture in this function. Based on the existing comments you can infer that that's what the second argument is for. Normally I'd suggest an inline comment, but given the that there's a bunch of calls, could we have either have two constants:

enum ArchMatch : bool {
  ExactArchMatch = true,
  CompatibleArchMatch = false,
};

Or maybe even better, can we change the signature of that function to take an enum with those values?

This revision is now accepted and ready to land.Mar 2 2022, 10:28 AM
labath added inline comments.Mar 9 2022, 7:10 AM
lldb/source/Target/Platform.cpp
1957

I've created a separate patch for that (https://reviews.llvm.org/D121290)

This revision was automatically updated to reflect the committed changes.
thakis added a subscriber: thakis.Mar 9 2022, 8:41 AM
thakis added inline comments.
lldb/source/Plugins/Platform/gdb-server/CMakeLists.txt
10

It doesn't seem like lldb cares about this kind of thing, but this adds a dependency cycle: lldbPluginPlatformGDB->lldbPluginProcessGDBRemote->lldbPluginPlatformMacOSX->lldbPluginPlatformPOSIX->lldbPluginPlatformGDB

labath added inline comments.Mar 9 2022, 9:16 AM
lldb/source/Plugins/Platform/gdb-server/CMakeLists.txt
10

Actually, this is something I wanted to address before landing this patch (but then forgot). I think that the dependencies introduced (I would actually say "made explicit") here are reasonable, and the weird one is lldbPluginProcessGDBRemote->lldbPluginPlatformMacOSX). Lemme back this out until I figure out what to do with that.

(I'm not going to land this immediately, since I've also learned that this breaks running the test suite against the qemu platform -- which works right now, but it seems that is mostly accidental. I will switch gears and make the qemu platform more test-suite compatible first.)

labath reopened this revision.Apr 5 2022, 7:35 AM
This revision is now accepted and ready to land.Apr 5 2022, 7:35 AM
labath updated this revision to Diff 420507.Apr 5 2022, 7:35 AM

Reopening, since the last attempt was quite some time ago, and the rebase was
non-trivial.

Functionally, there are no real changes. The one-liner in dotest.py is somewhat
interesting, as it was necessary for (emu|simu)lator platform tests (which don't
have a connection url) to work. Previously, these worked even without setting
lldb.selected_platform, as they would get picked up from the global platform
list, but with this patch, they would become completely orphaned, and uneligible
for automatic selection.

labath requested review of this revision.Apr 5 2022, 7:35 AM

Still LGTM. Apologies for the new rebase conflict introduced by e90d8f024b2b.

JDevlieghere accepted this revision.Apr 5 2022, 12:26 PM
This revision is now accepted and ready to land.Apr 5 2022, 12:26 PM
This revision was automatically updated to reflect the committed changes.