the*_*sti 8 c c++ python gdb pyenv
我正在 pyenv 管理的 virtualenv 中工作
$ which python
/Users/me/.pyenv/shims/python
Run Code Online (Sandbox Code Playgroud)
/Users/me/.pyenv/shims/python是一个 shell 脚本,gdb 不起作用
"0x7ffeeb614570s": not in executable format: file format not recognized
Run Code Online (Sandbox Code Playgroud)
如何在/sf/answers/186496271/的 python 脚本上使用 gdb 来调试我的 C 扩展的段错误?
/sf/answers/3710511241/建议gdb -ex r --args bash python crash.py,但它不起作用,同样的错误
"0x7ffee0aa4530s": not in executable format: file format not recognized
Run Code Online (Sandbox Code Playgroud)
我的感觉是,你的问题是你正在调用pyenvshim 文件,而python不是gdb. gdb必须提供python可执行文件路径,而不是 shim 脚本文件。它需要python可执行文件来加载符号等。
> pyenv virtualenv 3.10 66824320
> pyenv local 66824320
> which python
> /Users/$USER/.pyenv/shims/python
>
> cat `which python` #!/usr/bin/env bash
set -e
[ -n "$PYENV_DEBUG" ] && set -x
program="${0##*/}"
export PYENV_ROOT="/Users/$USER/.pyenv"
exec "/usr/local/opt/pyenv/bin/pyenv" exec "$program" "$@"
Run Code Online (Sandbox Code Playgroud)
你需要打开的是:
> pyenv which python
/Users/$USER/.pyenv/versions/66824320/bin/python
Run Code Online (Sandbox Code Playgroud)
要使用真正的 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...
Run Code Online (Sandbox Code Playgroud)
因此:
> gdb -ex r --args `pyenv which python` crash.py
Run Code Online (Sandbox Code Playgroud)