title: Using LLDB API to get the address of an expression in an elf file compiled with ARM-GCC
body: <p>Given an ARM .elf file with a nested structure in a .cpp file, I can use LLDB to evaluate an expression to get an address of a global structure/array element.</p>
  <pre><code>lldb my_arm.elf
  (lldb) ex &amp;user_data.sub_type[2].i[3]
  </code></pre>
  <p>This gives the expected result,</p>
  <pre><code>(int *) $1 = 0x200001f0
  </code></pre>
  <p>...similar to gdb, with a type, an index, and an address in RAM, for the C/C++ structure element specified. LLDB can also evaluate expressions like '&amp;main', '1+1' etc.</p>
  <p>Attempting to do the same thing in python using EvaluateExpression() in the lldb API, always results in  !IsValid().</p>
  <pre><code>import lldb  # this works in python in linux.
  dbg = lldb.SBDebugger().Create()
  dbg.SetAsync(False)
  modspec = lldb.SBModuleSpec()
  modspec.SetFileSpec(lldb.SBFileSpec(&quot;my_arm.elf&quot;))
  modspec.SetSymbolFileSpec(lldb.SBFileSpec(&quot;my_arm.elf&quot;))
  target.AddModule(modspec)  # target.IsValid() is True.
  val=target.EvaluateExpression('&amp;user_data.sub_type[2].i[3]')
  </code></pre>
  <p>This is python <em>outside</em> of lldb. <code>val.IsValid()</code> is always False and I can't seem to get values from the expressions. More trivial expressions like '&amp;main' and '1+1' give similar results.</p>
  <p>How can I use the lldb API to evaluate expressions for a .elf file?</p>