[Lldb-commits] [PATCH] D117237: [lldb] Use __lldb_init_module instead of "if lldb.debugger" idiom

Dave Lee via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu Jan 13 10:46:02 PST 2022


kastiglione added inline comments.


================
Comment at: lldb/docs/use/python-reference.rst:586
 the module is loaded allowing you to add whatever commands you want into the
-current debugger. Note that this function will only be run when using the LLDB
-command command script import, it will not get run if anyone imports your
-module from another module. If you want to always run code when your module is
-loaded from LLDB or when loaded via an import statement in python code you can
-test the lldb.debugger object, since you imported the module at the top of the
-python ls.py module. This test must be in code that isn't contained inside of
-any function or class, just like the standard test for __main__ like all python
-modules usually do. Sample code would look like:
-
-::
-
-  if __name__ == '__main__':
-      # Create a new debugger instance in your module if your module
-      # can be run from the command line. When we run a script from
-      # the command line, we won't have any debugger object in
-      # lldb.debugger, so we can just create it if it will be needed
-      lldb.debugger = lldb.SBDebugger.Create()
-  elif lldb.debugger:
-      # Module is being run inside the LLDB interpreter
-      lldb.debugger.HandleCommand('command script add -f ls.ls ls')
-      print 'The "ls" python command has been installed and is ready for use.'
+current debugger.
 
----------------
jingham wrote:
> I think it's okay to show the "if __name__  == '__main__': part of this example, but it should be:
> 
> 
> ```
> if __name__ == '__main__':
>       # Create a new debugger instance in your module if your module
>       # can be run from the command line. When we run a script from
>       # the command line, we won't have any debugger object in
>       # lldb.debugger, so we can just create it if it will be needed
>       lldb.debugger = lldb.SBDebugger.Create()
>       # Now do whatever work this module would do when run as a command
>       # Now dispose of the debugger you just made.
>       lldb.SBDebugger.Destroy(debugger)
> 
> 
> ```That seems useful trick.
good point


================
Comment at: lldb/examples/darwin/heap_find/heap.py:1518
+        __name__)
+    # debugger.HandleCommand('command script add -f %s.heap heap' % package_name)
+    # debugger.HandleCommand('command script add -f %s.section_ptr_refs section_ptr_refs' % package_name)
----------------
jingham wrote:
> Do you know what these commented-out lines are for?
I don't, no. Of the three, only the `section_ptr_refs` exists in this file. The other two, `heap` and `stack_ptr_refs` do not exist. I can remove the latter two, and leave the commented out line for the existing `section_ptr_refs` function.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D117237/new/

https://reviews.llvm.org/D117237



More information about the lldb-commits mailing list