[lldb-dev] Custom formatter request

Enrico Granata egranata at apple.com
Tue Dec 11 11:18:42 PST 2012


Hi Akos,
what do you mean by "it doesn't work too well"? Do you get any diagnostics?
A good debugging technique is to use the LLDB interactive script interpreter to repeat the steps in your script and check where you get issues such as empty or invalid objects (all our SB API objects have an IsValid() call on them).
To bootstrap yourself, you can use:
valobj = lldb.frame.FindVariable("name of the variable to format here")

At a glance I can see two issues here:

>   if valobj.GetValue() != 0:

If your valobj is not a pointer, but a plain record, its value is going to be None (only scalars have values).
You might want to rephrase your check along the lines of:

if (valobj.TypeIsPointerType() == False or valobj.GetValue() != 0):

Also, I am pretty sure you do not need the GetPointeeData() calls here:

>     content = valobj.GetChildMemberWithName('content')
>     length = content.GetPointeeData(0,1).GetChildMemberWithName('length')
>     string = content.GetPointeeData(0,1).GetChildMemberWithName('string')


 You should be able to dereference the children of content by name even if content is a pointer.
GetPointeeData() is used when you have a pointer/array and you want to retrieve the byte values it points to/refers.
In your case, you want to retrieve a child of a variable and maintain the value-ness of whatever you get back - hence the SBValue returning calls are what you want/need.

As an aside,

>       data_val = string.GetPointeeData(i, 1)
>       newchar = data_val.GetUnsignedInt16(e, 0)   # utf-16

You should be able to get away with something along the lines of:

data_val = string.GetPointeeData(0,length) outside the while, and then access the individual uint16's as data_val.uint16[index]

This way you avoid generating a bunch of one-off SBData objects and keep the entire buffer around (of course, if your buffers are huge, the former solution might still be preferable).

Let me know if I can help you more with the script!

Enrico Granata
✉ egranata@.com
✆ (408) 972-7683

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-dev/attachments/20121211/6d05d4b6/attachment.html>


More information about the lldb-dev mailing list