Skip to content

Commit

Permalink
Merge pull request #24123 from stefanv/spin-gdb-catch-breakpoint
Browse files Browse the repository at this point in the history
BUG: ``spin gdb``: launch Python directly so that breakpoint is caught
  • Loading branch information
seberg committed Jul 8, 2023
2 parents ab2178b + a7746bc commit fd23b35
Showing 1 changed file with 39 additions and 7 deletions.
46 changes: 39 additions & 7 deletions .spin/cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,48 @@ def test(ctx, pytest_args, markexpr, n_jobs, tests, verbose):


@click.command()
@click.argument('python_expr')
def gdb(python_expr):
@click.option('--code', '-c', help='Python program passed in as a string')
@click.argument('gdb_args', nargs=-1)
def gdb(code, gdb_args):
"""👾 Execute a Python snippet with GDB
spin gdb -c 'import numpy as np; print(np.__version__)'
Or pass arguments to gdb:
spin gdb -c 'import numpy as np; print(np.__version__)' -- --fullname
Or run another program, they way you normally would with gdb:
\b
spin gdb ls
spin gdb -- --args ls -al
You can also run Python programs:
\b
spin gdb my_tests.py
spin gdb -- my_tests.py --mytest-flag
"""
util.run(
['gdb', '--args', 'python', '-m', 'spin', 'run',
'python', '-P', '-c', python_expr],
replace=True
)
meson._set_pythonpath()
gdb_args = list(gdb_args)

if gdb_args and gdb_args[0].endswith('.py'):
gdb_args = ['--args', sys.executable] + gdb_args

if sys.version_info[:2] >= (3, 11):
PYTHON_FLAGS = ['-P']
code_prefix = ''
else:
PYTHON_FLAGS = []
code_prefix = 'import sys; sys.path.pop(0); '

if code:
PYTHON_ARGS = ['-c', code_prefix + code]
gdb_args += ['--args', sys.executable] + PYTHON_FLAGS + PYTHON_ARGS

gdb_cmd = ['gdb', '-ex', 'set detach-on-fork on'] + gdb_args
util.run(gdb_cmd, replace=True)


# From scipy: benchmarks/benchmarks/common.py
Expand Down

0 comments on commit fd23b35

Please sign in to comment.