<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div>On Aug 28, 2013, at 7:15 PM, Jakob Leben <<a href="mailto:jakob.leben@gmail.com">jakob.leben@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">On Wed, Aug 28, 2013 at 5:08 PM, <<a href="mailto:jingham@apple.com">jingham@apple.com</a>> wrote:<br><blockquote type="cite"><br>So it would be narrowing to view the "synthetic children" as only a framework for viewing container types.<br></blockquote><br>Perhaps what I've missed is that there can be several different<br>synthetic child providers for any parent data type. Even in that case,<br>it seems there is one such provider that's installed on an SBValue<br>provided via C++ API by default. So then my proposal applies to these<br>default providers.<br><br></blockquote><div><br></div><div>There can only be one synthetic provider per type that is active.</div><div>If you end up installing multiple, through regexp or whatnot, the order of categories determines which one wins.</div><div>Technically, a category can only ever contain one provider per type. With regular expressions it is fairly easy to violate this requirement. What happens then is undefined (i.e. it depends on the order in which they were added or in which the iterators we use provide them to us for inspection, …) long story short: don’t rely on any such tricks.</div><br><blockquote type="cite">Besides, it's not that SBValue for std::string provides synthetic<br>children in a different way than I would like. The issue is that it<br>doesn't provide synthetic children at all! And so far I simply haven't<br>heard any good reason why it shouldn't by default provide characters<br>as children.<br></blockquote><div><br></div><div>It is a largely uninteresting view for most people. The majority of people using LLDB have never expressed the desire to twist their strings open and see an array of characters. Actually, there has been an opposite drive: even a char[] should be displayed as a string.</div><div>This is really the only reason why that was not implemented.</div><div><br></div><div><div>On Aug 28, 2013, at 7:56 PM, Jakob Leben <<a href="mailto:jakob.leben@gmail.com">jakob.leben@gmail.com</a>> wrote:</div><div><br></div><blockquote type="cite">Enrico, I'd be grateful if you could help me with this!<br></blockquote></div><div><br></div><div>Assuming you work with libstdc++, your string data is located at <strVariable>._M_dataplus._M_p</div><div><br></div><div>You are going to have to implement a Python class, as described at: <a href="http://lldb.llvm.org/varformats.html">http://lldb.llvm.org/varformats.html</a></div><div><br></div><div><font color="blue" style="font-family: monospace; font-size: medium;">class</font><span style="font-family: monospace; font-size: medium;"> SyntheticChildrenProvider:</span><br style="font-family: monospace; font-size: medium;"><span style="font-family: monospace; font-size: medium;"> </span><font color="blue" style="font-family: monospace; font-size: medium;">def</font><span style="font-family: monospace; font-size: medium;"> __init__(self, valobj, internal_dict):</span><br style="font-family: monospace; font-size: medium;"><span style="font-family: monospace; font-size: medium;"> </span><i style="font-family: monospace; font-size: medium;">this call should initialize the Python object using valobj as the variable to provide synthetic children for</i><span style="font-family: monospace; font-size: medium;"> </span><br style="font-family: monospace; font-size: medium;"><span style="font-family: monospace; font-size: medium;"> </span><font color="blue" style="font-family: monospace; font-size: medium;">def</font><span style="font-family: monospace; font-size: medium;"> num_children(self): </span><br style="font-family: monospace; font-size: medium;"><span style="font-family: monospace; font-size: medium;"> </span><i style="font-family: monospace; font-size: medium;">this call should return the number of children that you want your object to have</i><span style="font-family: monospace; font-size: medium;"> </span><br style="font-family: monospace; font-size: medium;"><span style="font-family: monospace; font-size: medium;"> </span><font color="blue" style="font-family: monospace; font-size: medium;">def</font><span style="font-family: monospace; font-size: medium;"> get_child_index(self,name): </span><br style="font-family: monospace; font-size: medium;"><span style="font-family: monospace; font-size: medium;"> </span><i style="font-family: monospace; font-size: medium;">this call should return the index of the synthetic child whose name is given as argument</i><span style="font-family: monospace; font-size: medium;"> </span><br style="font-family: monospace; font-size: medium;"><span style="font-family: monospace; font-size: medium;"> </span><font color="blue" style="font-family: monospace; font-size: medium;">def</font><span style="font-family: monospace; font-size: medium;"> get_child_at_index(self,index): </span><br style="font-family: monospace; font-size: medium;"><span style="font-family: monospace; font-size: medium;"> </span><i style="font-family: monospace; font-size: medium;">this call should return a new LLDB SBValue object representing the child at the index given as argument</i><span style="font-family: monospace; font-size: medium;"> </span><br style="font-family: monospace; font-size: medium;"><span style="font-family: monospace; font-size: medium;"> </span><font color="blue" style="font-family: monospace; font-size: medium;">def</font><span style="font-family: monospace; font-size: medium;"> update(self): </span><br style="font-family: monospace; font-size: medium;"><span style="font-family: monospace; font-size: medium;"> </span><i style="font-family: monospace; font-size: medium;">this call should be used to update the internal state of this Python object whenever the state of the variables in LLDB changes.</i><sup style="font-family: monospace;">[1]</sup><br style="font-family: monospace; font-size: medium;"><span style="font-family: monospace; font-size: medium;"> </span><font color="blue" style="font-family: monospace; font-size: medium;">def</font><span style="font-family: monospace; font-size: medium;"> has_children(self): </span><br style="font-family: monospace; font-size: medium;"><span style="font-family: monospace; font-size: medium;"> </span><i style="font-family: monospace; font-size: medium;">this call should return True if this object might have children, and False if this object can be guaranteed not to have children.</i><sup style="font-family: monospace;">[2]</sup><br style="font-family: monospace; font-size: medium;"></div><div><br></div><div>What you are probably going to do is:</div><div>- save the valobj as an ivar of the children provider in __init__</div><div>- in update, you should grab the value of _M_p (a pointer) and save it somewhere. That is going to be your real data source. Return None from update. Really. It’s much safer :)</div><div><br></div><div><span style="font-family: monospace; font-size: medium;"> </span><font color="blue" style="font-family: monospace; font-size: medium;">def</font><span style="font-family: monospace; font-size: medium;"> __init__(self, valobj, internal_dict):</span></div><div><span style="font-family: monospace; font-size: medium;"><span class="Apple-tab-span" style="white-space:pre"> </span>self.value = valobj</span></div><div><span style="font-family: monospace; font-size: medium;"> </span><font color="blue" style="font-family: monospace; font-size: medium;">def</font><span style="font-family: monospace; font-size: medium;"> update(self): </span><br style="font-family: monospace; font-size: medium;"></div><div><span class="Apple-tab-span" style="font-family: monospace; font-size: medium; white-space: pre;"> </span><font face="monospace" size="3">self.ptr_value = self.value.GetChildMemberWithName(“_M_dataplus”).GetChildMemberWithName(“_M_p”).GetValueAsUnsigned(0)</font></div><div><br></div><div>To actually compute your number of children (len of string), you can do one of two things:</div><div> - call strlen() as an expression; it is unsafe</div><div> - read chunks of data until a \0 is encountered, or you realize you are reading way too much and you should bail; this latter case can be fairly common with uninitialized data, and anything that deals with potentially bogus data needs to be hardened against such events, or suffer great pain down the road</div><div>What you technically want is a strlen-with-bounds, that will fail if the length is waaaaay beyond reasonable. We can work details here.</div><div><br></div><div>As for get_child_index, I am assuming you will want to call your children [0], [1], …</div><div>It is a simple matter of rejecting any name other than those formed as [<i>number</i>], and for those that are well formed, return the <i>number</i> token</div><div>Internally, LLDB likes to deal with children by index. But for us humans, it is highly convenient to name children, since we are better at memorizing names than indexes. This call allows LLDB to answer the question “when I am asked for child foo, where do I find it?”. Natural ordering of the DWARF debug information would answer this in the “raw data” case.</div><div><br></div><div>Now, the real deal. In get_child_at_index you are going to extract the individual byte.</div><div>You can fairly simply go to the process, read a byte at ptr_value+index, and use an expression to make that into a char.</div><div>There are more interesting/efficient ways to get the same result, which would involve retrieving the pointee type for _M_p and using that to build an SBValue. Feel free to ask if you want to delve more</div><div><br></div><div>has_children is fairly easy: return True and be done with it.</div><div><br></div><div>Hope these pointers help you get started!</div><div><br></div><div>
<div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div style=" orphans: 2; widows: 2; border-collapse: separate; border-spacing: 0px;"><span style="font-size: 12px; orphans: auto; widows: auto;">Enrico Granata</span><br style="font-size: 12px; orphans: auto; widows: auto;"><span style="font-size: 12px; orphans: auto; widows: auto;">📩 egranata@</span><font color="#ff2600" style="font-size: 12px; orphans: auto; widows: auto;"></font><span style="font-size: 12px; orphans: auto; widows: auto;">.com</span><br style="font-size: 12px; orphans: auto; widows: auto;"><span style="font-size: 12px; orphans: auto; widows: auto;">☎️ 27683</span></div></div></div>
</div>
<br><div><div><br></div></div></body></html>