简体   繁体   English

gdb无法在Mac Sierra中正确安装

[英]gdb can't be properly installed in Mac Sierra

I tried everything I can find about installing gdb, but still could not make it work. 我尝试了所有有关安装gdb的信息,但仍然无法使它正常工作。

Here is how I install and run gdb: 这是我安装和运行gdb的方法:

  1. install gdb with brew install gdb brew install gdb

  2. then it tells me to do the following 然后它告诉我执行以下操作

    (experiment3.5) ->brew install gdb Updating Homebrew... ==> Downloading https://homebrew.bintray.com/bottles/gdb- 8.0.1.sierra.bottle.tar Already downloaded: /Users/Natsume/Library/Caches/Homebrew/gdb- 8.0.1.sierra.bottle.tar.gz ==> Pouring gdb-8.0.1.sierra.bottle.tar.gz ==> Caveats gdb requires special privileges to access Mach ports. (experiment3.5)-> brew install gdb正在更新Homebrew ... ==>正在下载https://homebrew.bintray.com/bottles/gdb- 8.0.1.sierra.bottle.tar已下载:/ Users / Natsume /库/缓存/自制程序/ gdb- 8.0.1.sierra.bottle.tar.gz ==>倒gdb-8.0.1.sierra.bottle.tar.gz ==>注意gdb需要特殊特权才能访问Mach端口。 You will need to codesign the binary. 您将需要对二进制文件进行代码签名。 For instructions, see: 有关说明,请参阅:
    https://sourceware.org/gdb/wiki/BuildingOnDarwin https://sourceware.org/gdb/wiki/BuildingOnDarwin

    On 10.12 (Sierra) or later with SIP, you need to run this: 在具有SIP的10.12(Sierra)或更高版本上,您需要运行以下命令:

    echo "set startup-with-shell off" >> ~/.gdbinit

  3. I did finish these two steps. 我确实完成了这两个步骤。 I did the codesign task by following exact instruction here 我通过以下详细的指令做了协同设计任务, 在这里

  4. everything goes smoothly. 一切顺利。 however, when I ran the following code, I still get the same error message 但是,当我运行以下代码时,我仍然收到相同的错误消息

I ran gdb python test.py and received following message 我运行了gdb python test.py并收到以下消息

(experiment3.5)  ->gdb python signal_test.py
GNU gdb (GDB) 8.0.1
Copyright (C) 2017 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-darwin16.7.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...
warning: `/Users/travis/miniconda3/conda-bld/python_1494603145199/work/Python-3.5.3/Programs/python.o': can't open to read symbols: No such file or directory.
(no debugging symbols found)...done.
Python Exception <type 'exceptions.ImportError'> No module named libpython:
"/Users/Natsume/Documents/shendusuipian/pytorch/raw_pytorch/60min_intro/signal_test.py" is not a core dump: File format not recognized
  1. then I did download libpython.py , but I don't know what to do with it. 然后我确实下载了libpython.py ,但是我不知道该怎么做。
  2. I don't have such folder /Users/travis/miniconda3/conda-bld/python_1494603145199/work/Python-3.5.3/Programs/python.o' as stated in the warning message above 我没有上述警告消息中所述的文件夹/Users/travis/miniconda3/conda-bld/python_1494603145199/work/Python-3.5.3/Programs/python.o'

Update I have tried to follow the steps here , I directly used the gdb8.01.tar.gz downloaded through brew install gdb , but I got error message below. 更新我尝试按照此处的步骤操作 ,我直接使用了通过brew install gdb下载的gdb8.01.tar.gz ,但是下面出现了错误消息。

Focus on one: /Users/Natsume/Desktop/src/gdb/8.0.1
 ->./configure --prefix=$HOME/opt/usr/local
-bash: ./configure: No such file or directory
Focus on one: /Users/Natsume/Desktop/src/gdb/8.0.1
 ->ls
COPYING         README          share
ChangeLog       bin
INSTALL_RECEIPT.json    include
Focus on one: /Users/Natsume/Desktop/src/gdb/8.0.1
 ->

update I ran the code from the link above, and installed, configured gdb8.0, however, I don't have a folder as $HOME/opt/usr/local , but only /opt/usr/local . 更新我从上面的链接运行了代码,并安装并配置了gdb8.0,但是,我没有$HOME/opt/usr/local文件夹,而只有/opt/usr/local文件夹。 Therefore, although ./configure --prefix=$HOME/opt/usr/local ran through, but I still can't run codesign -f -s "gdb-cert" <gnat_install_prefix>/bin/gdb , as there is no $HOME/opt/usr/local . 因此,尽管./configure --prefix=$HOME/opt/usr/local通过,但我仍然无法运行codesign -f -s "gdb-cert" <gnat_install_prefix>/bin/gdb ,因为没有$HOME/opt/usr/local

update 更新

exactly forllowing the link above, I can install gdb 8.0 , but I can't run gfortran , 完全缺少上面的链接,我可以安装gdb 8.0 ,但不能运行gfortran

(experiment3.5)  ->gfortran
-bash: gfortran: command not found

nor can I run gdb python test.py with success: 我也无法成功运行gdb python test.py

(experiment3.5)  ->gdb --args python signal_test.py
GNU gdb (GDB) 8.0
Copyright (C) 2017 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-darwin16.7.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...
warning: `/Users/travis/miniconda3/conda-bld/python_1494603145199/work/Python-3.5.3/Programs/python.o': can't open to read symbols: No such file or directory.
(no debugging symbols found)...done.
Python Exception <type 'exceptions.ImportError'> No module named libpython:

Update through this link to build ~/.gdbinit can get rid of the error of No module named libpython is solved; 通过此链接进行更新 ,以构建~/.gdbinit可以消除错误: No module named libpython解决No module named libpython however, the warning or bigger problem is still present 但是,警告或更大的问题仍然存在

warning: /Users/travis/miniconda3/conda-bld/python_1494603145199/work/Python-3.5.3/Programs/python.o': can't open to read symbols: No such file or directory. (no debugging symbols found)...done. 警告: /Users/travis/miniconda3/conda-bld/python_1494603145199/work/Python-3.5.3/Programs/python.o': can't open to read symbols: No such file or directory. (no debugging symbols found)...done. /Users/travis/miniconda3/conda-bld/python_1494603145199/work/Python-3.5.3/Programs/python.o': can't open to read symbols: No such file or directory. (no debugging symbols found)...done.

I have spent quite some time on this one. 我花了很多时间在这上面。 You need to compile it from sources. 您需要从源代码编译它。

Take a look here: 在这里看看:

Running GDB in macOS sierra 在macOS Sierra中运行GDB

It worked for me ;) 它为我工作;)

Just one note, make sure to code sign it! 请注意,请确保对其进行代码签名! Notes can be found here: Codesigning the Debugger 可以在这里找到注释: 协同设计调试器

Update: 更新:

for python stuff, take a look here 对于python的东西,请看这里

http://unconj.ca/blog/setting-up-gdb-for-debugging-python-on-os-x.html http://unconj.ca/blog/setting-up-gdb-for-debugging-python-on-os-x.html

as for gdb itself 至于gdb本身

it should be enough to test it following way 它应该足以按照以下方式对其进行测试

// simple.c
#include <stdio.h>

int main() {
  printf("Hello\n");
  return 0;
}

and then 接着

# assuming that gdb is signed
cc -g -o simple simple.c
gdb ./simple

Update - System Integrity Protection 更新-系统完整性保护

When it comes to some areas (eg /usr/bin) you won't have access there due to the fact that System Integrity Protection is on. 当涉及到某些区域(例如/ usr / bin)时,由于系统完整性保护已打开,您将无法访问该区域。 You need to turn it off: 您需要将其关闭:

# You need to boot to Recovery OS in a first place (before you call csrutil)
> csrutil disable

# you can also use another location as output
> lipo /usr/bin/python -thin x86_64 -output ~/python64

Take a look here when it comes to details of System Integrity Protection . 系统完整性保护方面,请看这里。

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

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