<div dir="ltr"><div><div><div>Hi Greg,<br><br></div>Thanks for your reply. I did try the method you mention above but variable.GetLocation() only provide me the memory address of the variable. What exactly I am looking for was  the register offset that stores variable i here. Example, I am looking for method able to output the one highlighted in yellow:<br><br>Variable: id = {0x000000a2}, name = "i", type= "int", <span style="background-color:rgb(255,255,0)">location = DW_OP_fbreg(-564</span>), decl = ivm_demo.c:6<br><br><br></div><div>Basically, I am working on  a binary instrumentation research tool, that will inject code to check changes on selected variable. Therefore, using register offset, I am able to inject check for instruction using this register with this offset.<br></div><div>Please let me know if you have any better method to grab register offset for particular variable.<br></div><div><br></div>Thanks,<br></div>Kamenee<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jun 20, 2016 at 7:15 PM, Greg Clayton <span dir="ltr"><<a href="mailto:gclayton@apple.com" target="_blank">gclayton@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The variables are available through the frame in your symbol context. You have a line of code commented out in your script:<br>
<br>
                    #variable = frame.GetVariables(target,True,True,True)<br>
<br>
Change it to:<br>
<br>
get_arguments = True # Get argument variables<br>
get_locals = True # Get local variables<br>
get_statics = True # Get globals and static variables<br>
get_in_scope_only = True # only get variables that are in scope<br>
use_dynamic = lldb.eDynamicDontRunTarget # Get dynamic types for variables<br>
variables = frame.GetVariables (get_arguments, get_locals, get_statics, get_in_scope_only, use_dynamic)<br>
print variables<br>
<br>
This output will look different from the output in "image lookup --address 0x... --verbose" because we have an actual frame here so we can dump the variable value itself because we have a stack frame that allows us to have variable values. If you want the location of the variable you can also print that in a for loop using "variables" from above:<br>
<br>
for variable in variables:<br>
    print str(variable)<br>
    print "Location = %s" % (variable.GetLocation())<br>
<br>
<br>
Each "variable" object is a lldb.SBValue type. There are many API calls on these that you can call manually depending on what you want. Let me know if you have any questions.<br>
<br>
Greg Clayton<br>
<div><div class="h5"><br>
<br>
<br>
<br>
> On Jun 17, 2016, at 11:34 AM, Kamenee Arumugam via lldb-dev <<a href="mailto:lldb-dev@lists.llvm.org">lldb-dev@lists.llvm.org</a>> wrote:<br>
><br>
> Hi,<br>
><br>
> I am trying program using Lldb Python API to get an output exactly same when I run this command "image lookup --address 0x0000000405a6 --verbose". But when I print return value of GetSymbolContext(lldb.eSymbolContextEverything), it doesnt contain the decoding of local variables which the above commands can print out local variables.<br>
><br>
> I have attached a simple script.py that I have developed. It is not possible to print out local variables using the APIs or I am missing something out?<br>
><br>
> I am looking forward to hear from you soon.<br>
><br>
> Thanks,<br>
> kmn<br>
</div></div>> <script.txt>_______________________________________________<br>
> lldb-dev mailing list<br>
> <a href="mailto:lldb-dev@lists.llvm.org">lldb-dev@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev</a><br>
<br>
</blockquote></div><br></div>