20
$ file app
app: Mach-O universal binary with 2 architectures
app (for architecture i386):    Mach-O executable i386
app (for architecture x86_64):  Mach-O 64-bit executable x86_64

$ gdb app
GNU gdb (GDB) 7.6
Copyright (C) 2013 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-darwin13.0.0".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
"app": not in executable format: File format not recognized


$ file test
test: Mach-O 64-bit executable x86_64

$ gdb test
GNU gdb (GDB) 7.6
Copyright (C) 2013 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-darwin13.0.0".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /Users/dmulder/test...Reading symbols from /Users/dmulder/test.dSYM/Contents/Resources/DWARF/test...done.
done.

Why would the 64bit binary succeed, but the 64+32 binary fail?

5
  • Am I missing something obvious here? Commented Dec 12, 2013 at 20:42
  • 1
    I built gdb from source, by the way (yesterday). Commented Dec 12, 2013 at 21:04
  • is your "app" in an application package? i.e. are you trying to do "gdb app" when you should be doing "gdb app.app/Contents/MacOS/app"? (i.e. the true binary is buried in the application package) Commented Jan 6, 2014 at 14:05
  • @David Good point, I installed gdb via Xcode, do you have xcode? can you send me the permalink to the file so I can test it here? put it on dropbox or something... (i delete the answer until come up w/ something concrete) Commented Jan 6, 2014 at 17:43
  • You can't install gdb via xcode on Mac 10.9. Of course I have xcode installed. Commented Jan 7, 2014 at 20:07

2 Answers 2

20
+50

Unfortunately, the non-Apple version of GNU gdb is currently unable to debug universal (or 'fat') binaries (ones that contain both 32-bit and 64-bit executables).

One option is to use lipo to extract a single architecture and run gdb on that:

lipo -thin x86_64 -output app-x86_64 ./app

or

lipo -thin i386 -output app-i386 ./app

If you'd prefer to debug the combined executable, you could try using LLDB, or an Apple version of gdb.

Sign up to request clarification or add additional context in comments.

1 Comment

I ended up downloading and compiling Apple's version of gdb here opensource.apple.com/release/developer-tools-46 and that worked. Thanks.
5

As OP commented, using Apple's gdb will fix the problem.

Here are instructions to build Apple gdb 6.3.50.20050815-cvs from source on OS 10.9:

NOTE: You will need to install Xcode and set up a build environment. If you have Homebrew installed, run brew doctor to see if "Your system is ready to brew."

  1. Download the gdb-1822 source tarball from: http://opensource.apple.com/tarballs/gdb/gdb-1822.tar.gz

  2. Extract this into a temporary directory. Open a terminal and cd into gdb-1822/src.

  3. Run the configure script:

    ./configure --prefix="$HOME/.local/stow/gdb-1822" --disable-debug --disable-dependency-tracking --with-system-readline
    

    (The last three configure arguments are from the homebrew-dupes formula: https://github.com/Homebrew/homebrew-dupes/blob/master/gdb.rb )

  4. Run make:

    make
    make install
    
  5. Follow the instructions at https://sourceware.org/gdb/wiki/BuildingOnDarwin#Creating_a_certificate to create a gdb-cert code signing certificate.

  6. cd into $HOME/.local/stow/gdb-1822/bin and sign the gdb executable:

    codesign -s gdb-cert gdb
    
  7. cd into $HOME/.local/stow and stow the gdb-1822 folder:

    stow gdb-1822
    
  8. Add $HOME/.local/bin to your PATH and either restart the terminal or clear Bash's cache to the location of gdb:

    hash -d gdb
    

1 Comment

Why would brew install gdb produce this exact same problem ... NOW?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.