Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: spin gdb: launch Python directly so that breakpoint is caught #24123

Merged
merged 6 commits into from
Jul 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 39 additions & 7 deletions .spin/cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,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
Loading