繁体   English   中英

在 Mac OS Catalina 上调试 Python 分段错误

[英]Debugging Python segmentation fault on Mac OS Catalina

我正在使用 PySide2 和 scikit-learn 开发应用程序。 如果我使用单线程,应用程序可以正常工作,但是如果我将 sckikit-learn 计算移动到工作线程 QThread(以在处理过程中保持 UI 响应),我会在 Mac OS Catalina 上收到随机分段错误。 同一个程序在 Windows 上似乎运行良好(在 Mac 上,我每隔一次运行该程序时就会遇到分段错误;我在 Windows 上至少运行了 20 次该程序,但它从未崩溃过)。 我试图遵循此答案中的建议,但我无法让gdblldb在 Catalina 上正常工作。

这是我得到的lldb

% lldb python
(lldb) target create "python"
Current executable set to 'python' (x86_64).
(lldb) run test.py
error: process exited with status -1 (attach failed (Not allowed to attach to process.  Look in the console messages (Console.app), near the debugserver entries when the attached failed.  The subsystem that denied the attach permission will likely have logged an informative message about why it was denied.))

然后我尝试使用 MacPorts 安装gdb ,然后我按照GDB Wiki 中说明允许gdb调试另一个进程,但是gdb要么在run命令后挂起,要么在运行一个简单的脚本时给我一个未知信号错误(只需打印一个细绳):

% ggdb python   
GNU gdb (GDB) 9.2
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-darwin19.5.0".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://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 python...
(No debugging symbols found in python)
(gdb) run test.py
Starting program: /usr/bin/python test.py
[New Thread 0x2603 of process 92261]
[New Thread 0x1803 of process 92261]
During startup program terminated with signal ?, Unknown signal.

有没有办法在 Catalina 上调试 Python 分段错误?

macOS 上的 SIP(​​系统完整性保护)禁止调试器附加到系统应用程序,包括 Python 的交付版本。 这就是你所看到的。

您需要关闭 SIP 或构建您自己的 Python 版本。 OTOH,如果您正在调试 -O0 构建的 Python,那么在 Python 中调试您的问题会容易得多,因此从长远来看,弄清楚如何自己构建它(实际上并不难)可能是值得的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM