[lldb-dev] GetSymbolContext(lldb.eSymbolContextEverything)
Hi, I am trying program using Lldb Python API to get an output exactly same when I run this command "image lookup --address 0x000405a6 --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. 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? I am looking forward to hear from you soon. Thanks, kmn import lldb import os triple = "x86_64" def disassemble_instructions(insts): for i in insts: print i # Set the path to the executable to debug exe = "buffer" # Create a new debugger instance debugger = lldb.SBDebugger.Create() # When we step or continue, don't return from the function until the process # stops. Otherwise we would have to handle the process events ourselves which, while doable is #a little tricky. We do this by setting the async mode to false. debugger.SetAsync (False) # Create a target from a file and arch print "Creating a target for '%s'" % exe target = debugger.CreateTargetWithFileAndArch (exe, lldb.LLDB_ARCH_DEFAULT) if target: # If the target is valid set a breakpoint at main main_bp = target.BreakpointCreateByName ("main",target.GetExecutable().GetFilename()); #print main_bp # Launch the process. Since we specified synchronous mode, we won't return # from this function until we hit the breakpoint at main process = target.LaunchSimple (None, None, os.getcwd()) # Make sure the launch went ok if process: # Print some simple process info state = process.GetState () #print process if state == lldb.eStateStopped: # Get the first thread thread = process.GetThreadAtIndex (0) if thread: # Print some simple thread info #print thread # Get the first frame frame = thread.GetFrameAtIndex (0) #if frame: # Print some simple frame info # Print some simple frame info #print frame #function = frame.GetFunction() #variable = frame.GetVariables(target,True,True,True) module = target.GetModuleAtIndex(0) target.SetSectionLoadAddress(module.FindSection("__TEXT"), 0x1) module = target.AddModule ("/usr/lib/system/libsystem_c.dylib", triple, None, "/build/server/a/libsystem_c.dylib.dSYM") target.SetSectionLoadAddress(module.FindSection("__TEXT"), 0x7fff83f32000) module = target.AddModule ("/usr/lib/system/libsystem_dnssd.dylib", triple, None, "/build/server/b/libsystem_dnssd.dylib.dSYM") target.SetSectionLoadAddress(module.FindSection("__TEXT"), 0x7fff883db000) module = target.AddModule ("/usr/lib/system/libsystem_kernel.dylib", triple, None, "/build/server/c/libsystem_kernel.dylib.dSYM") target.SetSectionLoadAddress(module.FindSection("__TEXT"), 0x7fff8c0dc000) load_addr = 0x04005a6 so_addr = target.ResolveLoadAddress(load_addr) sym_ctx = so_addr.GetSymbolContext(lldb.eSymbolContextEverything) print sym_ctx ___ lldb-dev mailing list lldb-dev@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev
Re: [lldb-dev] GetSymbolContext(lldb.eSymbolContextEverything)
Hi Greg, 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: Variable: id = {0x00a2}, name = "i", type= "int", location = DW_OP_fbreg(-564), decl = ivm_demo.c:6 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. Please let me know if you have any better method to grab register offset for particular variable. Thanks, Kamenee On Mon, Jun 20, 2016 at 7:15 PM, Greg Clayton wrote: > The variables are available through the frame in your symbol context. You > have a line of code commented out in your script: > > #variable = frame.GetVariables(target,True,True,True) > > Change it to: > > get_arguments = True # Get argument variables > get_locals = True # Get local variables > get_statics = True # Get globals and static variables > get_in_scope_only = True # only get variables that are in scope > use_dynamic = lldb.eDynamicDontRunTarget # Get dynamic types for variables > variables = frame.GetVariables (get_arguments, get_locals, get_statics, > get_in_scope_only, use_dynamic) > print variables > > 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: > > for variable in variables: > print str(variable) > print "Location = %s" % (variable.GetLocation()) > > > 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. > > Greg Clayton > > > > > > On Jun 17, 2016, at 11:34 AM, Kamenee Arumugam via lldb-dev < > lldb-dev@lists.llvm.org> wrote: > > > > Hi, > > > > I am trying program using Lldb Python API to get an output exactly same > when I run this command "image lookup --address 0x000405a6 --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. > > > > 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? > > > > I am looking forward to hear from you soon. > > > > Thanks, > > kmn > > ___ > > lldb-dev mailing list > > lldb-dev@lists.llvm.org > > http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev > > ___ lldb-dev mailing list lldb-dev@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev
Re: [lldb-dev] GetSymbolContext(lldb.eSymbolContextEverything)
Thanks a lot Greg for your input. I have tried the 2nd option to parse the out of image lookup command and it works perfectly fine for me. Regards, Kamenee On Tue, Jun 21, 2016 at 2:21 PM, Greg Clayton wrote: > We currently don't expose this information through the API, though we > could. You could add a new method to SBValue: > > namespace lldb > { > class SBValue > { > SBData GetDWARFLocation(); > } > }; > > This could return the DWARF location as a SBData object. Then you could > consume the data by parsing the DWARF DW_OP enumerations. Otherwise you can > parse the textual output of the "image lookup -va 0x123" command: > > result = lldb.SBCommandReturnObject() > ci = debugger.GetCommandInterpreter() > ci.HandleCommand("image lookup -va %#x" % (frame.GetPC()), result, False) > > # Now all output from the above command is in "result" > output = result.GetOutput() > > # Parse "output" for variable locations > > > > > > On Jun 21, 2016, at 9:07 AM, Kamenee Arumugam > wrote: > > > > Hi Greg, > > > > 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: > > > > Variable: id = {0x00a2}, name = "i", type= "int", location = > DW_OP_fbreg(-564), decl = ivm_demo.c:6 > > > > > > 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. > > Please let me know if you have any better method to grab register offset > for particular variable. > > > > Thanks, > > Kamenee > > > > On Mon, Jun 20, 2016 at 7:15 PM, Greg Clayton > wrote: > > The variables are available through the frame in your symbol context. > You have a line of code commented out in your script: > > > > #variable = frame.GetVariables(target,True,True,True) > > > > Change it to: > > > > get_arguments = True # Get argument variables > > get_locals = True # Get local variables > > get_statics = True # Get globals and static variables > > get_in_scope_only = True # only get variables that are in scope > > use_dynamic = lldb.eDynamicDontRunTarget # Get dynamic types for > variables > > variables = frame.GetVariables (get_arguments, get_locals, get_statics, > get_in_scope_only, use_dynamic) > > print variables > > > > 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: > > > > for variable in variables: > > print str(variable) > > print "Location = %s" % (variable.GetLocation()) > > > > > > 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. > > > > Greg Clayton > > > > > > > > > > > On Jun 17, 2016, at 11:34 AM, Kamenee Arumugam via lldb-dev < > lldb-dev@lists.llvm.org> wrote: > > > > > > Hi, > > > > > > I am trying program using Lldb Python API to get an output exactly > same when I run this command "image lookup --address 0x000405a6 > --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. > > > > > > 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? > > > > > > I am looking forward to hear from you soon. > > > > > > Thanks, > > > kmn > > > ___ > > > lldb-dev mailing list > > > lldb-dev@lists.llvm.org > > > http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev > > > > > > ___ lldb-dev mailing list lldb-dev@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev