适用于macOS上Python的gdb [英] gdb for Python on macOS
问题描述
我想使用gdb调试我编写的C扩展名.
I want to use gdb to debug a C extension I wrote.
我按照此处的所有步骤对我的 brew install gdb
版本的gdb进行了代码签名:
I followed all the steps here to codesign my brew install gdb
version of gdb: https://sourceware.org/gdb/wiki/PermissionsDarwin
但是,显示 security dump-trust-settings -d
SecTrustSettingsCopyCertificates: No Trust Settings were found.
即使我选择了始终信任"在Keychain Access中进行代码签名.无论如何,我继续按照说明进行操作.
Even though I selected "Always Trust" for code signing in Keychain Access. Anyway I continued with the instructions.
gdb仍然具有与我第一次尝试时相同的错误:
gdb still has the same error as when I first tried it:
% gdb -ex r --args zsh python crash.py
GNU gdb (GDB) 10.1
Copyright (C) 2020 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-darwin20.2.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"...
"0x7ffee8d454b0s": not in executable format: file format not recognized
Starting program: python crash.py
No executable file specified.
Use the "file" or "exec-file" command.
(gdb)
推荐答案
gdb对Mac OS上的所谓胖"二进制文件的支持X 断断续续地存在了近十年(目前破损两年以上).您需要使用Apple的Xcode命令行工具,仅提取您感兴趣的架构,例如
gdb support for so-called "fat" binaries on Mac OS X has been on-again, off-again for almost a decade now (currently broken for two+ years). You need to use the lipo
utility, from Apple's Xcode command line tools, to extract only the architecture you are interested in, e.g.
lipo -thin x86_64 -output ls-x86_64 /bin/ls
此后,您应该能够 gdb
它,例如
Afterwards you should¹ be able to gdb
it, e.g.
▶ gdb ./ls-x86_64
GNU gdb (GDB) 10.1
Copyright (C) 2020 Free Software Foundation, Inc.
[...]
Reading symbols from ./ls-x86_64...
(No debugging symbols found in ./ls-x86_64)
(gdb) set startup-with-shell off
(gdb) run
gdb-entitlement.xml
[Inferior 1 (process 7566) exited normally]
(gdb)
¹在撰写本文时,您需要构建和使用修补版本.
这篇关于适用于macOS上Python的gdb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!