我正在 pyenv 管理的 virtualenv 中工作
$ which python
/Users/theonlygusti/.pyenv/shims/python
/Users/theonlygusti/.pyenv/shims/python
是一个shell脚本,gdb不起作用
"0x7ffeeb614570s": not in executable format: file format not recognized
如何在像这里这样的Python脚本上使用gdb https://stackoverflow.com/a/2664232/3310334来调试我的C扩展的段错误?
https://stackoverflow.com/a/53007303/3310334建议
gdb -ex r --args bash python crash.py
,但它不起作用,同样的错误
"0x7ffee0aa4530s": not in executable format: file format not recognized
我的感觉是你的问题是你正在调用 pyenv shim 文件,而不是使用 gdb 调用 python 可执行文件。 gdb 需要可执行文件而不是 shim 文件来加载符号等。
> pyenv virtualenv 3.10 66824320
> pyenv local 66824320
> which python
> /Users/pkjar/.pyenv/shims/python
>
> cat `which python` #!/usr/bin/env bash
set -e
[ -n "$PYENV_DEBUG" ] && set -x
program="${0##*/}"
export PYENV_ROOT="/Users/pkjar/.pyenv"
exec "/usr/local/opt/pyenv/bin/pyenv" exec "$program" "$@"
您需要打开的是:
> pyenv which python
/Users/$USER/.pyenv/versions/66824320/bin/python
要使用真正的 python 二进制文件运行 gdb,您需要将 python 可执行文件传递给 gdb:
> gdb `pyenv which python`
GNU gdb (GDB) 13.2
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin22.4.0".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /Users/$USER/.pyenv/versions/66824320/bin/python...
我希望以上内容能帮助您指明正确的方向。