title: Dereferencing a SBValue which is of type void * in lldb Python script
body: <p>This is a follow on question from my post a day ago:
  <a href="https://stackoverflow.com/questions/21693730/writing-a-python-script-to-print-out-an-array-of-recs-in-lldb">Writing a Python script to print out an array of recs in lldb</a></p>
  
  <p>I am trying to write a Python script for use with lldb which will allow me to print out records of a given type which are pointed to by an array of <code>void *</code>'s.  Using the Python which Jason provided yesterday (thanks for great advice), I am able to get an <code>SBValue</code> object which contains the <code>void *</code> for each member in the array.</p>
  
  <p>Now I can't figure out how to create a new <code>SBValue</code> object which represents the record starting with the <code>SBValue</code> object which contains the void *.  In the code below, I create an array of <code>void *</code>'s which each point to a TraceRec record.</p>
  
  <p>In the Python below, I am trying to create a <code>SBValue</code> object which contains a <code>TraceRec</code> given a <code>SBValue</code> object which contains one of the elements (of type <code>void *</code>) in the array.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;stdint.h&gt;
  
  typedef struct
  {
      int datum;
  } TraceRec;
  
  typedef struct
  {
      uint32_t fMaxNumberEntries;
      uint32_t fNextEntryNumber;
      void ** fPointerArray;
  } com_softraid_TraceLog;
  
  com_softraid_TraceLog *com_softraid_gTraceLogPtr;
  
  int main ()
  {
      com_softraid_TraceLog log;
      TraceRec * traceRecArray;
  
      traceRecArray = (TraceRec *) malloc (sizeof (TraceRec) * 100);
  
      traceRecArray[0].datum = 0;
      traceRecArray[1].datum = 1;
      traceRecArray[2].datum = 2;
      traceRecArray[3].datum = 3;
  
      com_softraid_gTraceLogPtr = &amp;log;
      log.fMaxNumberEntries = 100;
      log.fNextEntryNumber = 4;
  
      log.fPointerArray = malloc (sizeof(void *) * 100);
  
      for (uint32_t index = 0; index &lt; 100; index++)
      {
          log.fPointerArray[index] = &amp;traceRecArray[index];
      }
  
      puts ("break here");
  
      return 0;
  }
  </code></pre>
  
  <p>The Python code to print the second elements in fPointerArray is:</p>
  
  <pre><code>(lldb) br s -p break
  (lldb) r
  (lldb) scri
  &gt;&gt;&gt; debugger = lldb.debugger
  &gt;&gt;&gt; target = debugger.GetSelectedTarget()
  &gt;&gt;&gt; traceLog = target.FindFirstGlobalVariable("com_softraid_gTraceLogPtr")
  &gt;&gt;&gt; pointerArray = traceLog.GetChildMemberWithName("fPointerArray")
  &gt;&gt;&gt; voidPointer = pointerArray.GetChildAtIndex(1, lldb.eNoDynamicValues, 1)
  &gt;&gt;&gt; print voidPointer
  (void *) [1] = 0xffffff807b602e10
  </code></pre>
  
  <p>But how do I access the contents of the <code>TraceRec</code> which is pointed to by <code>voidPointer</code>?</p>
  
  <p>A note for anyone setting up lldb for 2 Mac debugging: You need to configure some settings in order to get lldb to load symbols correctly.  I use the following file to initialize lldb (filename = <code>.lldb_init</code> in the home directory):</p>
  
  <pre><code>settings set target.load-script-from-symbol-file true
  
  #   Load the symbols for all the kexts
  settings set plugin.dynamic-loader.darwin-kernel.load-kexts true
  
  #   Load the symbols from the kext being developed (from /R2D2/syms)
  settings set platform.plugin.darwin-kernel.kext-directories /R2D2/syms
  
  #   Import the Python scripts
  command script import ./sr_debug_macros.py
  
  #   Import lldb command aliases
  command source ./sr_debug_macros
  
  //  Wait for connection to the remote Mac
  kdp-remote 10.0.1.15
  </code></pre>
  
  <p>I start my lldb session using the following command in Terminal:</p>
  
  <pre><code>xcrun lldb -s lldb_init
  </code></pre>