Skip to content Skip to sidebar Skip to footer

Writing A Python Script To Print Out An Array Of Recs In Lldb

I need help with the SBValue class used in the lldb Python module which is used for creating scripts for lldb debugging sessions. I am in the process of porting my kext test and de

Solution 1:

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>typedefstruct
{
    int datum;
} TraceRec;

typedefstruct
{
        uint32_t fMaxNumberEntries;
        uint32_t fNextEntryNumber;
        TraceRec *fTraceRecArray;
} com_softraid_TraceLog;

com_softraid_TraceLog *com_softraid_gTraceLogPtr;

intmain(){
    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");

    return0;
}

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.

Post a Comment for "Writing A Python Script To Print Out An Array Of Recs In Lldb"