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:

http://llvm.org/svn/llvm-project/lldb/trunk/examples/python/disassembly_mode.py

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)
----------------
clayborg wrote:
> 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.


https://reviews.llvm.org/D36347



_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to