[lldb-dev] Help with C++ API

Enrico Granata egranata at apple.com
Tue Aug 27 18:53:22 PDT 2013

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

> Hello,
> I have got some questions regarding the LLDB C++ API which I haven't
> found answers to in the documentation or by investigating the source
> code so far. If there is a better place than this mailing list to
> direct this kind of questions to, please let me know!
> All the questions below are related to using the API to debug a
> program compiled from C++ source.
> 1. When trying to read data from a dynamically allocated array of
> "doubles" I fail to get all the data correctly by using
> SBValue::GetPointeeData() and then SBData::ReadRawData(), despite the
> fact that no call reports any error, and all the involved SBxxx
> objects as valid. However, if I use SBValue::GetChildAtIndex for each
> array member, each member is read correctly. What's the difference? I
> guess this has to do something with data caching (or lack thereof)?

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.

> 3. Despite reading the source code, I have not managed to grasp the
> exact meaning of the words "dynamic" and "synthetic", whenever they
> occur in the API. For example, what precisely do the
> lldb::DynamicValueType flags mean? Is this related to dynamically
> typed languages, or does it have to do something with caching of data
> exchanged between debugger and debugee? What exactly does it imply if
> I set a SBValue's "preference" to use dynamic or synthetic value?

Dynamic means “is LLDB going to be allowed to do something to figure out the runtime type of this object”?
Imagine the following C++:

class Foo { virtual int DoSomething(); … };
class Bar : public Foo { virtual int DoSomething(); … };

int TakeAFoo (Foo* f) { return f->DoSomething(); }

TakeAFoo(new Bar());

now if you stop in TakeAFoo(), the “formal” (or static) type of f is Foo*, but its actual (or dynamic) type is Bar*. Can LLDB figure it out for you, or not?
There are three options: No, Without Running Code, By Running Code When Needed.
There needs to be a ternary value because at some point in the future we might need to run some code in the inferior process in order to figure out this information. Currently, either works just fine.

Synthetic means “is LLDB going to be allowed to apply synthetic children to this object”?
Imagine an STL vector: usually it is implemented in terms of three pointers: begin, end, end of storage.
This view is not very useful when you see it in the debugger, e.g.

std::vector<int> V;
V.push_back(1); V.push_back(2);

(lldb) frame variable V
V = {
begin = 0x1234
end = 0x123D
end of storage=0x1248

you would rather much want to see
V = {
[0] = 1
[1] = 2
(unless you are the implementor of the C++ standard library, that is)

Synthetic children are the LLDB name for the feature that allows the debugger to show logically useful child information. The way it is implemented is to have a new ValueObject on top of the “real” one that vends an aptly crafted set of children.

When you set dynamic and synthetic preferences on an SBValue you are essentially telling LLDB whether you want your SBValue to be backed by a static vs. a dynamic value, and whether you want to see real children or crafted ones, when available.

Hope this helps.

> Thank you for any answers, or directions that would help me find the
> answers myself.
> Best regards,
> Jakob Leben
> _______________________________________________
> lldb-dev mailing list
> lldb-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev

Enrico Granata
📩 egranata@.com
☎️ 27683

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

More information about the lldb-dev mailing list