Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
gdb 8.2 can';无法识别macOS Mojave 10.14上的可执行文件_Macos_Gdb - Fatal编程技术网

gdb 8.2 can';无法识别macOS Mojave 10.14上的可执行文件

gdb 8.2 can';无法识别macOS Mojave 10.14上的可执行文件,macos,gdb,Macos,Gdb,我通过brew安装gdb获得gdb 源文件内容为: #include <cstdio> int main(){ int a = 10; for(int i = 0; i< 10; i++){ a += i; } printf("%d\n",a); return 0; } 并运行gdb gdb ./demo 但是,它不能工作。它无法识别可执行文件 GNU gdb (GDB) 8.2 Copyright (C) 2018

我通过
brew安装gdb
获得gdb

源文件内容为:

#include <cstdio>
int main(){
    int a = 10;
    for(int i = 0; i< 10; i++){
        a += i;
    }
    printf("%d\n",a);
    return 0;
}
并运行gdb

gdb ./demo
但是,它不能工作。它无法识别可执行文件

GNU gdb (GDB) 8.2
Copyright (C) 2018 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-darwin18.0.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"...
BFD: /Users/xxx/Codes/demo: unknown load command 0x32
BFD: /Users/xxx/Codes/demo: unknown load command 0x32
"/Users/xxx/Codes/demo": not in executable format: file format not recognized
运行
/demo
,其输出为
55
在gdb中键入
show configuration
,它显示:

 This GDB was configured as follows:
 configure --host=x86_64-apple-darwin18.0.0 --target=x86_64-apple-darwin18.0.0
         --with-auto-load-dir=:${prefix}/share/auto-load
         --with-auto-load-safe-path=:${prefix}/share/auto-load
         --with-expat
         --with-gdb-datadir=/usr/local/Cellar/gdb/8.2/share/gdb (relocatable)
         --with-jit-reader-dir=/usr/local/Cellar/gdb/8.2/lib/gdb (relocatable)
         --without-libunwind-ia64
         --without-lzma
         --without-babeltrace
         --without-intel-pt
         --disable-libmcheck
         --without-mpfr
         --with-python=/System/Library/Frameworks/Python.framework/Versions/2.7
         --without-guile
         --with-separate-debug-dir=/usr/local/Cellar/gdb/8.2/lib/debug (relocatable)

谁能帮我?非常感谢

我通过细化应用程序解决了莫哈韦的这个问题。GDB不理解通用二进制文件。因此,如果
文件myapp
告诉您myapp是通用二进制文件,请尝试以下操作:

lipo -thin x86_64 -output myapp-x86_64 myapp
然后

gdb myapp-x86_64

问题在于随
Apple LLVM 10.0.0版
发布的
clang-1000.11.45.2
向名为
LC\u BUILD\u version
的o-mach可执行文件添加了一个新的加载命令

$ otool -l test.o
...
Load command 1
       cmd LC_BUILD_VERSION
   cmdsize 24
  platform macos
       sdk n/a
     minos 10.14
    ntools 0
...
来自苹果:

因此,当前
bfd
(gdb用来操作可执行文件的程序)无法解释此命令并返回错误

作为临时解决方案,您可以编辑
bfd
源代码随
gdb
提供的源代码

首先,从中下载
gdb-8.0.1
sources。然后将第4649行的以下代码添加到
gdb-8.0.1/bfd/mach-o.c

case BFD_MACH_O_LC_BUILD_VERSION:
break;
最后在第189行的gdb-8.0.1/include/mach-o/loader.h中

  BFD_MACH_O_LC_BUILD_VERSION = 0x32
不要忘记在
BFD\u MACH\u O\u LC\u VERSION\u MIN\u WATCHOS=0x30之后的第188行末尾添加一个

然后按照自述文件中的说明处理经典的
gdb
编译:

run the ``configure'' script here, e.g.:

    ./configure 
    make

To install them (by default in /usr/local/bin, /usr/local/lib, etc),
then do:
    make install
别忘了按说明在gdb上签名。 如果仍然出现(os/kern)故障(0x5)错误,只需运行
sudogdb

为了等待GNU团队的修复,这是一个临时解决方案

编辑

Binutils gdb
已更新,这些更改现在在提交中实现


希望对您有所帮助。

我发布了一个临时brew公式,它似乎有效,同时等待官方brew公式更新:


brew安装升级到GDB 8.3版。另请参见Binutils bug tracker中的

从:

我找到了问题的根源。binutils不处理负载 命令0x32 LC\U构建版本(实际上也不是0x31 LC\U注释)。他们是 在最近的LLVM版本中定义:请参阅

查看objdump-private头文件的输出,有一点很清楚 区别:

@@ -56,16 +56,18 @@ attributes NO_TOC STRIP_STATIC_SYMS LIVE
  reserved1 0
  reserved2 0
 Load command 1
-      cmd LC_VERSION_MIN_MACOSX
-  cmdsize 16
-  version 10.13
-      sdk n/a
+       cmd LC_BUILD_VERSION
+   cmdsize 24
+  platform macos
+       sdk n/a
+     minos 10.14
+    ntools 0
 Load command 2
      cmd LC_SYMTAB
  cmdsize 24
LC_VERSION_MIN_MACOSX在binutils中实现,而 LC_构建_版本不可用。这在莫哈韦显然是新的


我从堆栈溢出中得到了一个很好的解决方案,但我不知道为什么它会起作用。 这是你的电话号码

我是macOS的新手,我做以下工作:

  • high Sierra中的协同设计gdb 8.0.1
  • 莫哈韦最新情况
  • gdb 8.0.1死于
    BFD:/Users/xxx/code/demo:unknown load命令0x32
  • 更改为gdb 8.2.1并遇到钥匙链错误
    未知错误-2147414007
    。 通过在
    登录
    中获取证书来解决此问题,然后将其导出并导入
    系统
    (如果无法导入,请将其从登录中删除)

  • 最后,由于某种错误,它仍然无法工作,并且出现了
    错误:无法开始调试。来自命令“-exec run”的意外GDB输出。找不到进程id 1510:(os/kern)故障(0x5)的Mach任务端口。
    (请检查gdb是否已代码化-请参阅taskgated(8))
    ,根据,仍然存在一些错误,答案告诉我如何
    brew重新安装gdb
    ,但它仍然不起作用,我昨天打电话给它
  • 最后我遇到了,我很开心,现在我可以调试了
    希望我的解决方案能有所帮助。

    我通过以下方式让gdb在莫哈韦工作:

    a) 获取最新的gdb源文件(在撰写本文时),除其他外,它增加了识别Mac上可执行文件的处理

    b) 构建gdb。我在darwin nat.c中得到了变量阴影的错误,所以我编辑了文件并重建了它

    c) 遵循中的步骤


    (来源:)

    从自制安装的gdb 8.2与Mac mojave不兼容。
    我已升级到8.2.1。这个问题应该得到解决。

    上面蒂莫西科的回答确实对我有用:

    brew安装

    然后我必须生成一个自签名证书,如中所示

    您使用的是什么
    gdb
    ?你是怎么得到的?您是否从下载并编译了它的源代码?如果是,您是如何配置的?如果否,则在
    gdb
    中显示
    show configuration
    的输出。同样地,对于您的
    c++
    (是否是…)?显示
    c++-v
    的输出。您能否在同一终端上运行
    /demo
    文件的输出是什么。/demo
    ?显示
    demo.cpp
    的源代码(或者将其设置为一个小文件)。首先用一个hello world这样的例子试试这个听起来很像,只是在8.2中被修复了。还需要注意的是,有一些macOS修复程序只在git master上使用——至少从High Sierra开始需要。此外,我认为在gdb上工作的人还没有尝试过Mojave。提交一个gdb bug会很好。更好的方法是在失败的地方附加一个“hello world”类型的可执行文件。尝试了gdb 8.0和8.2,同样的问题是如何在编辑的地方使用提交?我已经下载了gdb-8.2源文件,并尝试按照提交的方式进行修改。但是有一些文件我找不到。问题来自
    bfd
    而不是直接
    gdb
    bfd
    存在于
    binutils
    包中。您可以通过git
    git clone获得
    binutils
    git://sourceware.org/git/binutils-gdb.git
    。按照自述文件编译和安装
    binutils
    ,我使用gdb 8.0.1来避免兼容性问题。有人通知过
    brew
    此更新吗?更新:是的,我们可能想在GitHub上提出一个问题:我也是。更具体
      BFD_MACH_O_LC_BUILD_VERSION = 0x32
    
    run the ``configure'' script here, e.g.:
    
        ./configure 
        make
    
    To install them (by default in /usr/local/bin, /usr/local/lib, etc),
    then do:
        make install
    
    @@ -56,16 +56,18 @@ attributes NO_TOC STRIP_STATIC_SYMS LIVE
      reserved1 0
      reserved2 0
     Load command 1
    -      cmd LC_VERSION_MIN_MACOSX
    -  cmdsize 16
    -  version 10.13
    -      sdk n/a
    +       cmd LC_BUILD_VERSION
    +   cmdsize 24
    +  platform macos
    +       sdk n/a
    +     minos 10.14
    +    ntools 0
     Load command 2
          cmd LC_SYMTAB
      cmdsize 24