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 3 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
36 changes: 29 additions & 7 deletions .spin/cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,38 @@ 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 pogram passed in as a string')
stefanv marked this conversation as resolved.
Show resolved Hide resolved
@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:

spin gdb ls
spin gdb -- --args ls -al
"""
util.run(
['gdb', '--args', 'python', '-m', 'spin', 'run',
'python', '-P', '-c', python_expr],
replace=True
)
meson._set_pythonpath()
gdb_args = list(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 follow-fork-mode child'] + gdb_args
stefanv marked this conversation as resolved.
Show resolved Hide resolved
util.run(gdb_cmd, replace=True)


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