@@ -326,7 +326,7 @@ def test(ctx, pytest_args, n_jobs, tests, verbose, coverage=False):
326326@click .argument ("gdb_args" , nargs = - 1 )
327327@click .pass_context
328328def gdb (ctx , code , gdb_args ):
329- """👾 Execute a Python snippet with GDB
329+ """👾 Execute code through GDB
330330
331331 spin gdb -c 'import numpy as np; print(np.__version__)'
332332
@@ -601,3 +601,69 @@ def docs(ctx, sphinx_target, clean, first_build, jobs, sphinx_gallery_plot):
601601 f"$ export PYTHONPATH={ os .environ ['PYTHONPATH' ]} " , bold = True , fg = "bright_blue"
602602 )
603603 _run (["make" , "-C" , "doc" , sphinx_target ], replace = True )
604+
605+
606+ @click .command ()
607+ @click .option ("--code" , "-c" , help = "Python program passed in as a string" )
608+ @click .argument ("lldb_args" , nargs = - 1 )
609+ @click .pass_context
610+ def lldb (ctx , code , lldb_args ):
611+ """👾 Execute code through LLDB
612+
613+ spin lldb -c 'import numpy as np; print(np.__version__)'
614+
615+ Or run another program, they way you normally would with LLDB:
616+
617+ \b
618+ spin lldb -- ls -al
619+
620+ You can also run Python programs:
621+
622+ \b
623+ spin lldb -- my_tests.py
624+ spin lldb -- my_tests.py --mytest-flag
625+
626+ And specify LLDB-specific flags:
627+
628+ \b
629+ spin lldb -- --arch x86_64 -- ls -al
630+ spin lldb -- --arch x86_64 -- my_tests.py
631+ spin lldb -c 'import numpy as np; print(np.__version__)' -- --arch x86_64
632+ """
633+ build_cmd = _get_configured_command ("build" )
634+ if build_cmd :
635+ click .secho (
636+ "Invoking `build` prior to invoking lldb:" , bold = True , fg = "bright_green"
637+ )
638+ ctx .invoke (build_cmd )
639+
640+ _set_pythonpath ()
641+ lldb_args = list (lldb_args )
642+
643+ if code :
644+ if sys .version_info [:2 ] >= (3 , 11 ):
645+ PYTHON_FLAGS = ["-P" ]
646+ code_prefix = ""
647+ else :
648+ PYTHON_FLAGS = []
649+ code_prefix = "import sys; sys.path.pop(0); "
650+
651+ PYTHON_ARGS = ["-c" , code_prefix + code ]
652+ program = [sys .executable ] + PYTHON_FLAGS + PYTHON_ARGS
653+ else :
654+ if "--" in lldb_args :
655+ ix = lldb_args .index ("--" )
656+ lldb_args , program = lldb_args [:ix ], lldb_args [ix + 1 :]
657+ else :
658+ program , lldb_args = lldb_args , []
659+
660+ if program and program [0 ].endswith (".py" ):
661+ program = [sys .executable ] + program
662+
663+ lldb_cmd = (
664+ ["lldb" , "-O" , "settings set target.process.follow-fork-mode child" ]
665+ + lldb_args
666+ + ["--" ]
667+ + program
668+ )
669+ _run (lldb_cmd , replace = True )
0 commit comments