[lldb-dev] Object identities in the LLDB's C++ API

Leonard Mosescu via lldb-dev lldb-dev at lists.llvm.org
Wed Dec 13 11:44:11 PST 2017


LLDB's C++ API deals with SBxxx objects, most of which are PIMPL-style
wrappers around an opaque pointer to the internal implementation. These
SBxxx objects act as handles and are passed/returned by value, which is
generally convenient, except for the situations where one would need to
keep track of object identities, ex. using them as keys in associative
containers.

As far as I can tell, there's a bit of inconsistency in the current state:

1. Some types, ex. SBThread, SBTarget, SBSection, ... offer ==, != that map
directly to the corresponding operator on the opaque pointer (good!), but:
    .. there are no ordering operators, nor obvious ways to hash the objects
2. SBModule offer the == , != operators, but:
    ... the implementations for == and != are not exactly forwarded to the
corresponding operator on the opaque pointer (1)
3. Things like SBFrame offer IsEqual() in addition to ==, !=, creating a
bit of confusion
4. Other types (ex. SBProcess, SBSymbol, SBBlock) don't offer any kind of
comparison operations.

IMO it would be nice to have a consistent "handle type" semantics regarding
identity, ordering and hashing. I can see the following options:

1. Expose the opaque ptr as an opaque handle()
     - this is an easy, quick and convenient solution for many SBxxx types
but it may not work for all
2. Design and implement a consistent, first class identity/ordering/hashing
for all the SBxxx types
     - perhaps the most elegant and flexible approach, but also the most
work

Any thoughts on this? Did I miss anything fundamental here?

Thanks,
Lemo.

(1) example of operator== from SBModule:

bool SBModule::operator==(const SBModule &rhs) const {
if (m_opaque_sp)
return m_opaque_sp.get() == rhs.m_opaque_sp.get();
return false;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-dev/attachments/20171213/64bf64eb/attachment.html>


More information about the lldb-dev mailing list