I've been playing around with lldb and customization in python recently, and the interface seems unclear and/or broken around continuing from a breakpoint when using a one-line python script ("breakpoint command add -s python -o <one-liner>"). The documentation isn't clear about whether this works with a one liner (It says both "Your Python code, however organized, can optionally return a value. If the returned value is False, that tells LLDB not to stop at the breakpoint to which the code is associated." and "Single line breakpoint commands will be interpreted 'as is' when the breakpoint is hit. Multiple lines of Python will be wrapped in a generated function, and a call to the function will be attached to the breakpoint.") and my experiments have suggested that it can't (neither an expression that returns False nor an explicit "return <False>" seem to work).
Is this expected to work? Should the documentation be cleared up? (In case anyone wants to help with the background problem I'm trying to solve: I'm trying to write some generic logging code that can be attached to a breakpoint, so that I can log variable values at particular locations without repeatedly recompiling the program. So I'm trying to have a command that creates a breakpoint at a location that prints different variables and then continues. I couldn't find a way to have the python code enter multiple lines of commands attached to a breakpoint (hence the one-liner). From the doc it looked like I could set a python callback to be called when the breakpoint was hit and do everything in python, but I couldn't find any documentation on how to use SBBreakpoint::BreakpointHitCallback. I can't just attach a python function directly to the breakpoint (--python-function) because the function has to vary depending on what variables you want to trace. I've attached my python module to make this clear. The "experiments" I refer to above are whether the text on line 58 is "return logging.log(frame, bp_loc, (" + or "logging.log(frame, bp_loc, (" + ). Thanks much in advance ... -- Randy
import argparse import lldb import shlex def log(frame, bp_loc, variables): result = "" result += "Logging: " result += bp_loc.GetAddress().GetFunction().GetName() result += "(" result += bp_loc.GetAddress().GetLineEntry().GetFileSpec().GetFilename() result += ":" result += str(bp_loc.GetAddress().GetLineEntry().GetLine()) result += "): " for v in variables: result += '"%s"' % v result += ":" result += frame.EvaluateExpression(v).GetValue() result += " " result += "\n" print result return False # TODO: Define a python function that takes the following args when aliased # from the command line: # -f <fnname> # -l <l#> # -v <variable to log> # may be specified multiple times. # # and sets a breakpoint that outputs: # "Logging <functionname> (fnname:l#): <variable>: <value>" # and continues whenever that location is hit. def log_line(debugger, command, result, internal_dict): "Set a breakpoint for logging; prints information and continues." args=shlex.split(command) parser = argparse.ArgumentParser( prog='<embedded interpretter>', description='Parse args to log_line function.') parser.add_argument('-f', dest='filename', required=True, help="File containing line to log.") parser.add_argument('-l', dest='lineno', type=int, required=True, help="Line to log.") parser.add_argument('-v', dest='variables', action='append', help="Variable value to log.") args_ns = parser.parse_args(args=args) ## TODO: Shift over to using python arguments instead of going through ## command line. Requires understanding how callbacks are used in python. bp = debugger.GetSelectedTarget().BreakpointCreateByLocation( args_ns.filename, args_ns.lineno) debugger.HandleCommand( "breakpoint set -f %s -l %d" % (args_ns.filename, args_ns.lineno)) debugger.HandleCommand("breakpoint command add -s python -o '" + "return logging.log(frame, bp_loc, (" + ",".join(['"%s"' % i for i in args_ns.variables]) + "))'") lldb.debugger.HandleCommand('command script add -f logging.log_line trace')
_______________________________________________ lldb-dev mailing list lldb-dev@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev