Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing GDB with All Targets on Mac with Homebrew

I'm unable to install gdb with all targets enabled on Mac OSX Mojave (10.14) using Homebrew (2.0.0).

I've tried: brew install gdb --enable-targets=all and brew install gdb --with-all-targets and receive Error: invalid option: --enable-targets=all and Error: invalid option: --with-all-targets

brew info gdb returns:

gdb: stable 8.2.1 (bottled), HEAD
GNU debugger
https://www.gnu.org/software/gdb/
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/gdb.rb
==> Dependencies
Build: pkg-config ✔
==> Options
--HEAD
    Install HEAD version
==> Caveats
gdb requires special privileges to access Mach ports.
You will need to codesign the binary. For instructions, see:

  https://sourceware.org/gdb/wiki/BuildingOnDarwin

On 10.12 (Sierra) or later with SIP, you need to run this:

  echo "set startup-with-shell off" >> ~/.gdbinit
==> Analytics
install: 13,521 (30 days), 42,502 (90 days), 153,991 (365 days)
install_on_request: 12,161 (30 days), 37,200 (90 days), 132,057 (365 days)
build_error: 0 (30 days)

Please note that none of the options are listed in the info that show in the gdb.rb link. What am I missing here?

Other options, like --disable-debug do not work either. If I remove all options, the install works fine.

like image 512
ChipsAndBits Avatar asked Feb 05 '19 19:02

ChipsAndBits


People also ask

Where is GDB path Mac?

If you have installed gdb as explained before (using Homebrew), the path should be: /usr/local/Cellar/gdb/version/bin/gdb (replace version with the actual version of your gdb installation, e.g. /usr/local/Cellar/gdb/8.3/bin/gdb).


1 Answers

Just figured it out. I created a modified version of the formula .rb file in my /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/gdbCustom.rb and added the missing build options. I based it on this formula: https://raw.githubusercontent.com/Homebrew/homebrew-core/9ec9fb27a33698fc7636afce5c1c16787e9ce3f3/Formula/gdb.rb

Yes, I'm a newbie to Homebrew, but have a better understanding of how formulas work now. In case it helps others, see below final .rb. After adding the file to the above homebrew-core/Formula directory, run brew install gdbCustom --with-all-targets. The make takes several minutes, so be patient.

class Gdbcustom < Formula
    desc "GNU debugger"
    homepage "https://www.gnu.org/software/gdb/"
    head "https://sourceware.org/git/binutils-gdb.git"

    stable do
      url "https://ftp.gnu.org/gnu/gdb/gdb-8.2.1.tar.xz"
      mirror "https://ftpmirror.gnu.org/gdb/gdb-8.2.1.tar.xz"
      sha256 "0a6a432907a03c5c8eaad3c3cffd50c00a40c3a5e3c4039440624bae703f2202"

      # Fix build with all targets. Remove for 8.3
      # https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commitdiff;h=0c0a40e0abb9f1a584330a1911ad06b3686e5361
      patch do
        url "https://raw.githubusercontent.com/Homebrew/formula-patches/d457e55/gdb/all-targets.diff"
        sha256 "1cb8a1b8c4b4833212e16ba8cfbe620843aba0cba0f5111c2728c3314e10d8fd"
      end

      # Fix debugging of executables of Xcode 10 and later
      # created for 10.14 and newer versions of macOS. Remove for 8.3
      # https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=fc7b364aba41819a5d74ae0ac69f050af282d057
      patch do
        url "https://raw.githubusercontent.com/Homebrew/formula-patches/d457e55/gdb/mojave.diff"
        sha256 "6264c71b57a0d5d4aed11430d352b03639370b7d36a5b520e189a6a1f105e383"
      end
    end

    bottle do
        sha256 "01b06c2983503c78bc346b5f5e2c2bdccbc41d6f5ca759542eef712bf123ca30" => :mojave
        sha256 "9824d06b8d0d44e725a1d29f6631828b3b43abb1952c883e9fad559b6a816c04" => :high_sierra
        sha256 "cf7371e9f6257d1a7dee80239d05917e424e5bb3e7577bd93f0e139fe5174198" => :sierra
    end

    # Owen: deprecated_option "with-brewed-python" => "with-python"
    # Owen: deprecated_option "with-guile" => "[email protected]"

    option "with-python", "Use the Homebrew version of Python; by default system Python is used"
    option "with-version-suffix", "Add a version suffix to program"
    option "with-all-targets", "Build with support for all targets"

    depends_on "pkg-config" => :build
    # Owen: depends_on "python" => :optional
    # Owen: depends_on "[email protected]" => :optional

    fails_with :clang do
        build 800
        cause <<~EOS
          probe.c:63:28: error: default initialization of an object of const type
          'const any_static_probe_ops' without a user-provided default constructor
        EOS
    end

    fails_with :clang do
      build 600
      cause <<~EOS
        clang: error: unable to execute command: Segmentation fault: 11
        Test done on: Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
      EOS
    end

    def install
      args = %W[
        --prefix=#{prefix}
        --disable-debug
        --disable-dependency-tracking
        --enable-targets=all
        --with-python=/usr
        --disable-binutils
    ]

        # Owen: args << "--with-guile" if build.with? "[email protected]"
        # Owen: args << "--enable-targets=all" if build.with? "all-targets"

      if build.with? "python"
        args << "--with-python=#{HOMEBREW_PREFIX}"
      else
        args << "--with-python=/usr"
      end

      if build.with? "version-suffix"
        args << "--program-suffix=-#{version.to_s.slice(/^\d/)}"
      end

      system "./configure", *args
      system "make"

      # Don't install bfd or opcodes, as they are provided by binutils
      # Owen: inreplace ["bfd/Makefile", "opcodes/Makefile"], /^install:/, "dontinstall:"

      # Owen: system "make", "install"
      system "make", "install-gdb"
    end

    def caveats; <<~EOS
      gdb requires special privileges to access Mach ports.
      You will need to codesign the binary. For instructions, see:

        https://sourceware.org/gdb/wiki/BuildingOnDarwin

      On 10.12 (Sierra) or later with SIP, you need to run this:

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

    test do
      system bin/"gdb", bin/"gdb", "-configuration"
    end
  end
like image 112
ChipsAndBits Avatar answered Dec 09 '22 18:12

ChipsAndBits