[lldb-dev] lldbinit, cast and accessing array

Jean-Yves Avenard jyavenard at gmail.com
Sat Jul 5 01:26:20 PDT 2014


Hi

I have an object that contains an array of (void*). That (void*) is
actually a pointer to a type.

What I'd like to do, is get the address, cast that to a type I know so
I can display its content for a summary format.

the object is something like:

class MyArray<T> {
  int num;
  void *array[]
  ....
}

MyArray::array contains list of pointers to objects of type T.

In my lldbinit I would hope to do something like:

    strings = dprivate.GetChildMemberWithName("array")
    target = lldb.debugger.GetSelectedTarget()
    val = '{ '
    for i in range(length):
        child = strings.GetPointeeData(i)
        error = lldb.SBError()
        val += "[%s]:%s" % (i, child.GetUnsignedInt64(error, 0))

    val += ' }'

right now this display the value of the void*.

Now I may take the wrong way about it, and it may be much simpler for
me to implement the pretty-printing of my object.

I think I have to perform a cast but maybe I don't

the class provides an operator[], and a size() member

if I could within python use those methods like I do at the lldb console:
print myobject[0]

Just want to iterate through all the objects in my array
in pseudo code that would be:
result = "{ "
for i in range(object.size()):
   result += T_summary(object[i]) + " "
result += " }"

thanks in advance



More information about the lldb-dev mailing list