[PATCH] D36347: New lldb python module for adding diagnostic breakpoints
Jim Ingham via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 25 15:04:50 PDT 2017
jingham added a comment.
Note, BTW, Enrico also added a form of the command add that allows you to use a Python class to wrap the callable. That was in early 2015 so it's probably safe to use as well by now. That's even more convenient, and obviates the need for globals at all. One instance of the class is made per debugger as the command gets loaded, so it's ivars live for the life of the command - spanning execution.
There's an example of it here:
and it is mentioned in the Python Ref.
You don't by any means have to use this form, but if you are having fun playing around with this stuff, it makes it much more pleasant to write commands.
Comment at: utils/clangdiag.py:100
+ # Use the Shell Lexer to properly parse up command options just like a
+ # shell would
+ command_args = shlex.split(command)
> Great idea. Forgot about the execution context variant. The "exe_ctx" is a lldb.SBExecutionContext object. You get your target using:
> target = exe_ctx.GetTarget()
Yeah, if I could think of a friendly way to do it, I would outlaw the older form. That was an oversight, and makes commands that aren't guaranteed to behave correctly in breakpoint callbacks.
I'll go make the docs a little stronger now that the exe_ctx form has been there long enough that it's generally safe to use.
More information about the cfe-commits