<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 13, 2017, at 11:44 AM, Leonard Mosescu via lldb-dev <<a href="mailto:lldb-dev@lists.llvm.org" class="">lldb-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">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.<div class=""><br class=""></div><div class="">As far as I can tell, there's a bit of inconsistency in the current state:</div><div class=""><br class=""></div><div class="">1. Some types, ex. SBThread, SBTarget, SBSection, ... offer ==, != that map directly to the corresponding operator on the opaque pointer (good!), but:</div><div class="">    .. there are no ordering operators, nor obvious ways to hash the objects</div><div class="">2. SBModule offer the == , != operators, but:</div><div class="">    ... the implementations for == and != are not exactly forwarded to the corresponding operator on the opaque pointer (1)<br class=""></div><div class="">3. Things like SBFrame offer IsEqual() in addition to ==, !=, creating a bit of confusion</div><div class="">4. Other types (ex. SBProcess, SBSymbol, SBBlock) don't offer any kind of comparison operations.</div><div class=""><br class=""></div><div class="">IMO it would be nice to have a consistent "handle type" semantics regarding identity, ordering and hashing. I can see the following options:</div><div class=""><br class=""></div><div class="">1. Expose the opaque ptr as an opaque handle() </div><div class="">     - this is an easy, quick and convenient solution for many SBxxx types but it may not work for all</div></div></div></blockquote><div><br class=""></div>That would be nice, but that won't always work with how LLDB is currently coded for SBFrame and possibly SBThread. These objects will be problems as they can come and go and the underlying object isn't always the same even through they lock onto the same logical object. SBThread and SBFrame have "lldb::ExecutionContextRefSP m_opaque_sp" members. The execution context reference is a class that contains weak pointers to the lldb_private::Thread and lldb_private::StackFrame objects, but it also contains the thread ID and frame ID so it can reconstitute the value lldb_private::Thread and lldb_private::StackFrame even if the weak pointer isn't valid. So the opaque handle will work for many objects but not all.<br class=""><blockquote type="cite" class=""><div dir="ltr" class=""></div></blockquote><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="">2. Design and implement a consistent, first class identity/ordering/hashing for all the SBxxx types</div><div class="">     - perhaps the most elegant and flexible approach, but also the most work</div></div></div></blockquote><div><br class=""></div>I would be fine with adding new members to classes we know we want to hash and order, like by adding:</div><div><br class=""></div><div>uint32_t SB*::GetHash();</div><div>bool SB*::operator==(const SB*& ohs);</div><div><div>bool SB*::operator<(const SB*& ohs);</div><div><br class=""></div><div>Would those be enough?</div><div><br class=""></div><div><blockquote type="cite" class=""><div dir="ltr" class=""></div></blockquote></div></div><div><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><br class=""></div><div class="">Any thoughts on this? Did I miss anything fundamental here?</div></div></div></blockquote><div><br class=""></div><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><br class=""></div><div class="">Thanks,</div><div class="">Lemo.</div><div class=""><br class=""></div><div class="">(1) example of operator== from SBModule:</div><div class=""><br class=""></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px" class=""><div class=""><div style="font-family: 'Droid Sans Mono', monospace, monospace, 'Droid Sans Fallback'; line-height: 18px; white-space: pre;" class=""><div style="" class=""><font size="1" class=""><span style="color:rgb(0,0,255)" class="">bool</span> SBModule::<span style="color:rgb(175,0,219)" class="">operator</span>==(<span style="color:rgb(0,0,255)" class="">const</span> SBModule &rhs) <span style="color:rgb(0,0,255)" class="">const</span> {</font></div></div></div><div class=""><div style="font-family: 'Droid Sans Mono', monospace, monospace, 'Droid Sans Fallback'; line-height: 18px; white-space: pre;" class=""><div class=""><font size="1" class="">  <span style="color:rgb(175,0,219)" class="">if</span> (m_opaque_sp)</font></div></div></div><div class=""><div style="font-family: 'Droid Sans Mono', monospace, monospace, 'Droid Sans Fallback'; line-height: 18px; white-space: pre;" class=""><div class=""><font size="1" class="">    <span style="color:rgb(175,0,219)" class="">return</span> m_opaque_sp.<span style="color:rgb(121,94,38)" class="">get</span>() == rhs.<span style="color:rgb(0,16,128)" class="">m_opaque_sp</span>.<span style="color:rgb(121,94,38)" class="">get</span>();</font></div></div></div><div class=""><div style="font-family: 'Droid Sans Mono', monospace, monospace, 'Droid Sans Fallback'; line-height: 18px; white-space: pre;" class=""><div class=""><font size="1" class="">  <span style="color:rgb(175,0,219)" class="">return</span> <span style="color:rgb(0,0,255)" class="">false</span>;</font></div></div></div><div class=""><div style="font-family: 'Droid Sans Mono', monospace, monospace, 'Droid Sans Fallback'; line-height: 18px; white-space: pre;" class=""><div class=""><font size="1" class="">}</font></div></div></div></blockquote></div></div></blockquote><br class=""></div><div>So I would leave this up to the SB classes so that we can change the implementation if needed so I would prefer to add methods to each SB object for hashing and comparison.</div><div><br class=""></div><div>Greg Clayton</div><div><br class=""></div><br class=""></body></html>