lldb (Xcode) custom formatting for a struct with arbitrary long char16_t buffer

Viewed 81

In LibreOffice, we have the type rtl_uString, which is (simplified a bit):

typedef struct
{
    int refCount;
    int length;
    char16_t buffer[1];
} rtl_uString;

As you might guess, the actual rtl_uString objects then have arbitrary size buffers, as indicated by the length field.

We already have a complicated Python-based summary producer for this. I.e. installed with

type summary add --skip-references --python-function LO.rtl_uString_summary rtl_uString

The Python code uses GetPointeeData(), GetUnsignedInt16() etc. But, sadly, it seems to cause hangs in the debugger in Xcode now and then. So I have had to disable it.

It is much simpler to just print the buffer by casting to a char16_t pointer, as in

command regex ps 's/(^.*$)/expression -- (char16_t*)(%1).pData->buffer/'

but having to type ps foo->mBar etc is of course a bit painful, it should be automatic, rtl_uString members and variables should be printed nicely as when using the problematic custom formatter.

So my question is: Is there some simple way to have rtl_uString values automatically be printed using such a cast of the buffer member, as in that command regex, without going all the way to a Python summary provider? I tried using type summary add --summary-string but I can't get the char16_t* cast into that.

0 Answers
Related