gdb 8.2 can't recognized executable file on macOS Mojave 10.14

后端 未结 8 687
感情败类
感情败类 2020-11-30 19:05

I get gdb by brew install gdb.

The source file content is:

#include 
int main(){
    int a = 10;
    for(int i = 0; i<          


        
8条回答
  •  再見小時候
    2020-11-30 20:02

    The problem is that clang-1000.11.45.2 distributed with Apple LLVM version 10.0.0 add a new load command to o-mach executables named LC_BUILD_VERSION.

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

    From the apple source:

    /*
     * The build_version_command contains the min OS version on which this
     * binary was built to run for its platform.  The list of known platforms and
     * tool values following it.
     */
    

    So currently bfd (program used by gdb to manipulate executables) is not able to interpret this command, and returns the error.

    The temporary solution I found is directly edit bfd sources provide with gdb. I've only test with gdb-8.0.1.

    First, download gdb-8.0.1 sources from mirrors. Then add to gdb-8.0.1/bfd/mach-o.c the following code at line 4649 :

    case BFD_MACH_O_LC_BUILD_VERSION:
    break;
    

    And finally add int gdb-8.0.1/include/mach-o/loader.h :

      BFD_MACH_O_LC_BUILD_VERSION = 0x32
    

    at line 189 (don't forget to add a , at the end of the line 188 after BFD_MACH_O_LC_VERSION_MIN_WATCHOS = 0x30).

    After these instructions you can follow a classic gdb compilation as indicate inside the README :

    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
    

    Don't forget to sign gdb as explain here. If you still get the (os/kern) failure (0x5) error, just run sudo gdb.

    This is a temporary solution waiting for the GNU team fix the problem directly on the repo.

    EDIT

    Binutils-gdb has been updated, these changes are now implemented in commit fc7b364.

    Hope It will be helpfull.

提交回复
热议问题