[lldb-dev] executing a c++ function from lldb python script
Niels Bogaards
niels at elephantcandy.com
Tue Jan 7 05:22:59 PST 2014
Hi,
I made a script for lldb last year that allowed me to plot a custom object as a curve from Xcode’s lldb prompt. Worked very well for a year, but no more. Has anything changed in the EvaluateExpression syntax? Are there linker options I need to activate in my target c++ program?
Thanks for any help,
Niels
Here's the script, it outputs:
- DEBUG - res is No value
- DEBUG - fname is No value
- DEBUG - error is error: <NULL>
import lldb
import commands
import optparse
import shlex
import logging
def plot(debugger, command, result, dict):
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
command_args = shlex.split(command)
usage = "usage: %prog objectName "
description=‘''plot'''
parser = optparse.OptionParser(description=description, prog='plot',usage=usage)
try:
(options, args) = parser.parse_args(command_args)
except:
print '"plot" exception'
return
la = len(args)
print 'len args = %d' % la
if len(args) == 1:
ecom = “MyNamespace::MyClass::MyStaticPlotFunction(%s)" % args[0]
res = lldb.frame.EvaluateExpression(ecom, 1)
fname = lldb.frame.EvaluateExpression("MyNamespace::MyClass::GetStaticPlotFileName()")
error = lldb.SBError()
logging.debug("res is %s", res);
logging.debug("fname is %s", fname);
logging.debug("error is %s", error);
if __name__ == '__main__':
# This script is being run from the command line, create a debugger in case we are
# going to use any debugger functions in our function.
lldb.debugger = lldb.SBDebugger.Create()
plot (sys.argv)
def __lldb_init_module (debugger, dict):
# This initializer is being run from LLDB in the embedded command interpreter
# Add any commands contained in this module to LLDB
debugger.HandleCommand('command script add -f plot.plot plot')
print '"plot" command installed, type "plot --help" for detailed help'
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-dev/attachments/20140107/b8832890/attachment.html>
More information about the lldb-dev
mailing list