macOS 内核调试环境搭建中的两个error解决

这两个error都出现在执行command script import ...时。


报错1 :

error描述:

在lldb中执行命令

command script import "/Library/Developer/KDKs/KDK_10.11.3_15D21.kdk/System/Library/Kernels/kernel.dSYM/Contents/Resources/DWARF/../Python/lldbmacros/xnu.py"

报错如下:

error: module importing failed: dlopen(/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_ctypes.so, 2): Symbol not found: __PySlice_AdjustIndices

解决方法:

问题就出在这个_ctypes.so上。在terminal中执行sudo find / -name _ctypes.so

输出如下:

find: /dev/fd/3: Not a directory
find: /dev/fd/4: Not a directory
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_ctypes.so
/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_ctypes.so

其中第四行是这个报错的文件,第三行是系统自带文件。将第四行的文件备份后,用第三行文件的文件覆盖它。

cp /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_ctypes.so  /usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_ctypes.so

报错2 :

error描述 :

依然是执行 command script import时报错:

error: module importing failed: No module named logging
  File "temp.py", line 1, in 
  File "/Library/Developer/KDKs/KDK_10.11.3_15D21.kdk/System/Library/Kernels/kernel.dSYM/Contents/Resources/DWARF/../Python/lldbmacros/xnu.py", line 757, in 
    from usertaskgdbserver import *
  File "/Library/Developer/KDKs/KDK_10.11.3_15D21.kdk/System/Library/Kernels/kernel.dSYM/Contents/Resources/DWARF/../Python/lldbmacros/usertaskgdbserver.py", line 2, in 
    import logging

解决方法:

参考这个链接里的回答:

...but because this question appears high in search results for the error, I wanted to say that I had this error on OSX because my default system Python was 2.7, and I brew installed "python@2" while installing another package.
If you're on OSX and are using homebrew, check your packages installed with brew by running brew list, and if "python@2" appears in that list, and Python 2.7 is your system Python, you can remove the brew installed package with brew remove python@2 --ignore-dependencies

先通过brew list查看是否通过homebrew安装了"python@2",如果有,执行brew remove python@2 --ignore-dependencies

然后就可以开始愉快滴调试啦

你可能感兴趣的:(macOS 内核调试环境搭建中的两个error解决)