[lldb-dev] Help with C++ API

Enrico Granata egranata at apple.com
Wed Aug 28 11:25:34 PDT 2013

On Aug 27, 2013, at 8:48 PM, Jakob Leben <jakob.leben at gmail.com> wrote:

> Hi Enrico,
> On Tue, Aug 27, 2013 at 6:53 PM, Enrico Granata <egranata at apple.com> wrote:
>> Do you have a test case for your issue? I would like to take a look.
>> The fact that GetChildAtIndex() works is not unexpected. I would like to
>> figure out why GetPointeeData() & ReadRawData() are failing.
> Erm, sorry, that was my mistake! While cooking up a simple test case,
> I realized I was passing size to ReadRawData as element count instead
> of count * sizeof(type).
> Thanks for other answers, that makes things much clearer!
> Further observations that I would like to clarify:
> 1. Reading elements of std::list works just great using
> GetNumChildren() and GetChildAtIndex() on the container, when the
> container is set to use synthetic value. However the
> "can_create_synthetic" argument of GetChildAtIndex() does not seem to
> have any effect, contrary to what documentation suggests. Am I
> misreading something or is documentation wrong? Perhaps the argument
> only controls the preference of children with regard to grandchildren,
> and not how children are obtained.

That is because historically LLDB called “synthetic” something entirely different from “synthetic children”.
Assume you have 

Foo* aFoo = new Foo[3];

The previous notion of synthetic was “LLDB, can you make me aFoo[2] as if aFoo was a large enough array of Foo”?

That is was can_create_synthetic controls in GetChildAtIndex().
It is an unfortunate legacy naming that I am aware of and just have never had time to fix.

> 2. For std::vector, GetNumChildren() returns -1 (with preference for
> synthetic)! However, reading children using GetChildAtIndex() etc.
> still succeeds.

Interesting. Test case?

> 3. For both std::vector or std::list, I would then expect
> container.GetData().GetSignedXxx(error, index) to work as well. It
> fails in either case, and regardless of preference of container with
> regard to synthetic values.

That is probably because you are trying to access the synthetic children by reading into raw memory?
That won’t work. When you try getting data you are reading the raw object, not the synthetic data.
The synthetic data is only accessible by poking at the children

> 4. For std::string, GetNumChildren() always returns 1 regardless of
> preference for synthetic values, and I haven't found any way to read
> elements succesfully.

That makes sense. An std::string only has one child, which is a struct that then contains the pointer
std::string has no synthetic children, also.
It only has a summary.
To figure out what types have what formatters the “type xxxxxx list” commands (where xxxx can be format, summary, synthetic or filter[1]) is your friend

[1] filters are a lightweight type of synthetic children which you can use to only show a subset of the real member variables

Enrico Granata
📩 egranata@.com
☎️ 27683

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-dev/attachments/20130828/47e69501/attachment.html>

More information about the lldb-dev mailing list