[lldb-dev] Multiple platforms with the same name

Greg Clayton via lldb-dev lldb-dev at lists.llvm.org
Tue Jan 18 15:38:12 PST 2022


Platforms can contain connection specific setting and data. You might want to create two different "remote-linux" platforms and connect each one to a different remote linux machine. Each target which uses this platform would each be able to fetch files, resolve symbol files, get OS version/build string/kernel info, get set working directory from the remote server they are attached. Since each platform tends to belong to a target and since you might want to create two different targets and have each one connected to a different remote machine, I believe it is fine to have multiple instances.

I would vote to almost always create a new instance unless it is the host platform. Though it should be possible to create to targets and possibly set the platform on one target using the platform from another that might already be connected. 

I am open to suggestions if anyone has any objections.

Greg

> On Jan 17, 2022, at 8:18 AM, Pavel Labath <pavel at labath.sk> wrote:
> 
> Hello all,
> 
> currently our code treats platform name more-or-less as a unique identifier  (e.g. Platform::Find returns at most one platform instance --the first one it finds).
> 
> This is why I was surprised that the "platform select" CLI command always creates a new instance of the given platform, even if the platform of a given name already exists. This is because Platform::Create does not search the existing platform list before creating a new one. This might sound reasonable at first, but for example the Platform::Create overload which takes an ArchSpec first tries to look for a compatible platforms among the existing ones before creating a new one.
> 
> For this reason, I am tempted to call this a bug and fix the name-taking Create overload. This change passes the test suite, except for a single test, which now gets confused because some information gets leaked from one test to another. (although our coverage of the Platform class in the tests is fairly weak)
> 
> However, this test got me thinking. It happens to use the the SB way of manipulating platforms, and "creates" a new instance as lldb.SBPlatform("remote-linux"). For this kind of a command, it would be reasonable/expected to create a new instance, were it not for the fact that this platform would be very tricky to access from the command line, and even through some APIs -- SBDebugger::CreateTarget takes a platform _name_.
> 
> So, which one is it? Should we always have at most one instance of each platform, or are multiple instances ok?

> cheers,
> pl
> 
> PS: In case you're wondering about how I run into this, I was trying to create a pre-configured platform instance in (e.g.) an lldbinit file, without making it the default. That way it would get automatically selected when the user opens an executable of the appropriate type. This actually works, *except* for the case when the user selects the platform manually. That's because in that case, we would create an empty/unpopulated platform, and it would be the one being selected because it was the /current/ platform.



More information about the lldb-dev mailing list