Writing a Python script to print out an array of recs in lldb

梦想与她 提交于 2019-12-01 12:40:43

You're looking for SBValue::GetChildAtIndex() but you need to use the long form of that API. For instance, with a standalone user process C file,

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
typedef struct
{
    int datum;
} TraceRec;

typedef struct
{
        uint32_t fMaxNumberEntries;
        uint32_t fNextEntryNumber;
        TraceRec *fTraceRecArray;
} com_softraid_TraceLog;

com_softraid_TraceLog *com_softraid_gTraceLogPtr;

int main ()
{
    com_softraid_TraceLog log;
    com_softraid_gTraceLogPtr = &log;
    log.fTraceRecArray = (TraceRec *) malloc (sizeof (TraceRec) * 100);
    log.fMaxNumberEntries = 100;
    log.fNextEntryNumber = 4;
    log.fTraceRecArray[0].datum = 0;
    log.fTraceRecArray[1].datum = 1;
    log.fTraceRecArray[2].datum = 2;
    log.fTraceRecArray[3].datum = 3;

    puts ("break here");

    return 0;
}

we can experiment a little in the interactive script mode:

(lldb) br s -p break
(lldb) r
(lldb) scri
>>> debugger = lldb.debugger
>>> target = debugger.GetSelectedTarget()
>>> traceLog = target.FindFirstGlobalVariable("com_softraid_gTraceLogPtr")
>>> traceRecordArray = traceLog.GetChildMemberWithName("fTraceRecArray")
>>> print traceRecordArray.GetChildAtIndex(1, lldb.eNoDynamicValues, 1)
(TraceRec) [1] = {
  datum = 1
}
>>> print traceRecordArray.GetChildAtIndex(2, lldb.eNoDynamicValues, 1)
(TraceRec) [2] = {
  datum = 2
}
>>> 

There's also SBValue::GetPointeeData() which would give you the raw bytes of each member of the array in an SBData object but then you'd need to coerce those bytes back into your structure so I wouldn't go that way.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!