<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; ">
Hi Enrico & Daniel,
<div>Thanks all, I'm browsing through the formatters page. I managed to throw together a skeleton, but it doesn't seem to work too well. Maybe I failed to grasp something:</div>
<div><br>
</div>
<div>
<div>import lldb</div>
<div>def UniString_SummaryProvider(valobj, dict):</div>
<div> e = lldb.SBError()</div>
<div> s = u'"'</div>
<div> if valobj.GetValue() != 0:</div>
<div> content = valobj.GetChildMemberWithName('content')</div>
<div> length = content.GetPointeeData(0,1).GetChildMemberWithName('length')</div>
<div> string = content.GetPointeeData(0,1).GetChildMemberWithName('string')</div>
<div> i = 0</div>
<div> newchar = -1</div>
<div> while newchar != 0 and i < length:</div>
<div> # read next wchar character out of memory</div>
<div> data_val = string.GetPointeeData(i, 1)</div>
<div> newchar = data_val.GetUnsignedInt16(e, 0) # utf-16</div>
<div> if e.fail:</div>
<div> return '<error>'</div>
<div> i = i + 1</div>
<div> # add the character to our string 's'</div>
<div> if newchar != 0:</div>
<div> s = s + unichr(newchar)</div>
<div> s = s + u'"'</div>
<div> return s.encode('utf-8')</div>
<div><br>
</div>
<div>def __lldb_init_module(debugger,dict):</div>
<div> debugger.HandleCommand("type summary add -F UniString.UniString_SummaryProvider GS::UniString")</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div>Yes, I'd like to show the string member (it's in UTF-16) in the summary. I was looking at the CFString.py formatter, but that seems to be an overkill in our case.</div>
<div>The string[1] member is an 'old' C trick, here's the allocation routine. It preallocates a separate buffer of the right size, then uses placement new to put the SharedBuffer member there.</div>
<div><br>
</div>
<div>
<div>inline GS::UniString::SharedBuffer::SharedBuffer (USize initialLength, USize initialCapacity, Int32 initialRefCounter):</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>length (initialLength),</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>capacity (initialCapacity),</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>refCounter (initialRefCounter)</div>
<div>{</div>
<div>}</div>
<div><br>
</div>
<div>inline USize<span class="Apple-tab-span" style="white-space:pre"> </span>GS::UniString::CapacityToBufferSize (USize capacity)</div>
<div>{</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>return (sizeof (SharedBuffer) + (capacity - 1) * sizeof (unichar));</div>
<div>}</div>
<div><br>
</div>
<div>inline USize<span class="Apple-tab-span" style="white-space:pre"> </span>GS::UniString::BufferSizeToCapacity (USize bufferSize)</div>
<div>{</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>return ((bufferSize - sizeof (SharedBuffer)) / sizeof (unichar) + 1);</div>
<div>}</div>
<div><br>
</div>
</div>
<div>
<div>GS::UniString::SharedBuffer* GS::UniString::AllocateBuffer (USize capacity)</div>
<div>{</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>if (capacity == 0)</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>return ShareEmptyBuffer ();</div>
<div><br>
</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>capacity++;<span class="Apple-tab-span" style="white-space:pre">
</span>// to ensure capacity for the closing 0 (used in conversion)</div>
<div><br>
</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>USize bufferSize = CapacityToBufferSize (capacity);</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>if (bufferSize < MinBufferSize4) {</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>if (bufferSize < MinBufferSize1)</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>bufferSize = MinBufferSize1;</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>else if (bufferSize < MinBufferSize2)</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>bufferSize = MinBufferSize2;</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>else if (bufferSize < MinBufferSize3)</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>bufferSize = MinBufferSize3;</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>else</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>bufferSize = MinBufferSize4;</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>}</div>
<div><br>
</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>void* buffer = cachedAllocator.Allocate (bufferSize, &bufferSize);</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>capacity = BufferSizeToCapacity (bufferSize);</div>
<div><br>
</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>return new (buffer) SharedBuffer (0, capacity, 1);</div>
<div>}</div>
<div><br>
</div>
<div>Best, Akos</div>
<div><br>
</div>
<div>
<div>On Dec 10, 2012, at 11:32 PM, Enrico Granata <<a href="mailto:egranata@apple.com">egranata@apple.com</a>></div>
<div> wrote:</div>
<br class="Apple-interchange-newline">
<blockquote type="cite">
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">
Hi.
<div>It looks like your task should be relatively easy since you have the full definition of the UniString and the SharedBuffer.</div>
<div>I am assuming you will want to show the string content as your summary (as it happens for std::string and NSString).</div>
<div>If so, how are you going to use the string buffer? Is it going to contain a pointer to the real data?</div>
<div>I am probably slightly confused by your comment next to it.</div>
<div>Could you explain the logic for storing the string data or provide an example of code that handles e.g. the string allocation, or access to it?</div>
<div>Given that understanding, it should be relatively straightforward to accomplish your task.</div>
<div><br>
<div>
<div>
<div style="border-collapse: separate; border-spacing: 0px; "><i>Enrico Granata</i></div>
<div style="border-collapse: separate; border-spacing: 0px; ">✉ egranata@<font class="Apple-style-span" color="#ff230e"></font>.com</div>
<div>✆ (408) 972-7683</div>
</div>
</div>
<br>
<div>
<div>On Dec 10, 2012, at 7:35 AM, "Somorjai, Akos" <<a href="mailto:ASomorjai@graphisoft.com">ASomorjai@graphisoft.com</a>> wrote:</div>
<br class="Apple-interchange-newline">
<blockquote type="cite">Hello everyone,<br>
<br>
I need a little help with a custom formatter for the class below; I'd appreciate if someone could throw together a skeleton I can start from.<br>
<br>
Thanks,<br>
<br>
Akos<br>
<br>
<br>
Here's the class layout:<br>
<br>
class UniString {<br>
<br>
private:<br>
<span class="Apple-tab-span" style="white-space:pre"></span>struct SharedBuffer;<br>
<br>
<span class="Apple-tab-span" style="white-space:pre"></span>SharedBuffer*<span class="Apple-tab-span" style="white-space:pre">
</span>content;<span class="Apple-tab-span" style="white-space:pre"> </span>// shared buffer storing content of the string<br>
<br>
<span class="Apple-tab-span" style="white-space:pre"></span><span class="Apple-tab-span" style="white-space:pre"></span>// Implementation classes and structures<br>
<br>
<span class="Apple-tab-span" style="white-space:pre"></span>struct SharedBuffer {<br>
<span class="Apple-tab-span" style="white-space:pre"></span><span class="Apple-tab-span" style="white-space:pre"></span>USize<span class="Apple-tab-span" style="white-space:pre">
</span><span class="Apple-tab-span" style="white-space:pre"></span><span class="Apple-tab-span" style="white-space:pre"></span>length;<span class="Apple-tab-span" style="white-space:pre">
</span><span class="Apple-tab-span" style="white-space:pre"></span><span class="Apple-tab-span" style="white-space:pre"></span>// length of the string in UniChar::Layout units<br>
<span class="Apple-tab-span" style="white-space:pre"></span><span class="Apple-tab-span" style="white-space:pre"></span>USize<span class="Apple-tab-span" style="white-space:pre">
</span><span class="Apple-tab-span" style="white-space:pre"></span><span class="Apple-tab-span" style="white-space:pre"></span>capacity;<span class="Apple-tab-span" style="white-space:pre">
</span><span class="Apple-tab-span" style="white-space:pre"></span>// capacity of the allocated buffer in UniChar::Layout units<br>
<span class="Apple-tab-span" style="white-space:pre"></span><span class="Apple-tab-span" style="white-space:pre"></span>SInt32<span class="Apple-tab-span" style="white-space:pre">
</span><span class="Apple-tab-span" style="white-space:pre"></span><span class="Apple-tab-span" style="white-space:pre"></span>refCounter;<span class="Apple-tab-span" style="white-space:pre">
</span><span class="Apple-tab-span" style="white-space:pre"></span>// stores number of references to this shared buffer<br>
<span class="Apple-tab-span" style="white-space:pre"></span><span class="Apple-tab-span" style="white-space:pre"></span>char<span class="Apple-tab-span" style="white-space:pre">
</span><span class="Apple-tab-span" style="white-space:pre"></span><span class="Apple-tab-span" style="white-space:pre"></span>reserved[2];<span class="Apple-tab-span" style="white-space:pre">
</span><span class="Apple-tab-span" style="white-space:pre"></span>// padding reserved for the future use<br>
<span class="Apple-tab-span" style="white-space:pre"></span><span class="Apple-tab-span" style="white-space:pre"></span>unichar<span class="Apple-tab-span" style="white-space:pre">
</span><span class="Apple-tab-span" style="white-space:pre"></span><span class="Apple-tab-span" style="white-space:pre"></span>string[1];<span class="Apple-tab-span" style="white-space:pre">
</span><span class="Apple-tab-span" style="white-space:pre"></span><span class="Apple-tab-span" style="white-space:pre"></span>// buffer storing content of the string (extends beyond of the SharedBuffer)<br>
<br>
<span class="Apple-tab-span" style="white-space:pre"></span><span class="Apple-tab-span" style="white-space:pre"></span>inline SharedBuffer ();<br>
<span class="Apple-tab-span" style="white-space:pre"></span><span class="Apple-tab-span" style="white-space:pre"></span>inline SharedBuffer (USize initialLength, USize initialCapacity, Int32 initialRefCounter);<br>
<span class="Apple-tab-span" style="white-space:pre"></span>};<br>
…<br>
};<br>
<br>
<br>
_______________________________________________<br>
lldb-dev mailing list<br>
<a href="mailto:lldb-dev@cs.uiuc.edu">lldb-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev">http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev</a><br>
</blockquote>
</div>
<br>
</div>
</div>
</blockquote>
</div>
<br>
</div>
</div>
</body>
</html>