mac上安装gdb及使用中碰到的问题

来源:互联网 发布:网络数据拦截分析工具 编辑:程序博客网 时间:2024/04/30 03:43
  1. 安装homebriew,执行命令
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
      根据官方介绍,其功能是:“使用 Homebrew 安装 Apple 没有预装但 你需要的东西。”。
       完全基于 git 和 ruby,所以自由修改的同时你仍可以轻松撤销你的变更或与上游更新合并。
   $ brew edit wget # 使用 $EDITOR 编辑!
Homebrew 的配方都是简单的 Ruby 脚本:
  1. class Wget < Formula
      homepage "https://www.gnu.org/software/wget/"
      url "https://ftp.gnu.org/gnu/wget/wget-1.15.tar.gz"
      sha256 "52126be8cf1bddd7536886e74c053ad7d0ed2aa89b4b630f76785bac21695fcd"

      def install
        system "./configure", "--prefix=#{prefix}"
        system "make", "install"
      end
    end
  2. 然后执行 brew install gdb 进行安装
  3. 安装好了以后执行,出错,提示:
    “Unable to find Mach task port for process-id 7532: (os/kern) failure (0x5).”
    原因出于苹果系统的安全性,想想现在gdb是要对另一个进程进行全面的掌控,这件事不能随便轻易允许。
    因此需要创建证书,然后 :
    codesign -s gdb_cert /usr/local/bin/gdb 对gdb进行codesign签名方可允许。
  4. 现在执行gdb可以打开,但是依然运行出错,提示:
    “During startup program terminated with signal ?, Unknown signal.”
    这与sierra  的 System Runtime Integrity Protection 系统有关。
    据网友对Apple官网上的SIP介绍的总结,有以下几个关键点:
     + Security Integrity Protection applied to every process, including privileged code running unsandboxed.
    + Extends additional protections on system components on disk and at runtime
    + System binaries only can be modified by Apple Installer and Software Updater, and no longer permit runtime attachment or code injection.

    SIP系统保护机制可以用 crsutil status/disable/enable/clear 进行查看和修改。

    解决方法暂时有2个:
    + 关闭SIP。步骤:
        进入恢复模式(开机时按住Command+R,亲测有效),然后打开terminal 执行 csrutil disable,关闭SIP。
    + 关闭 startup-with-shell。步骤:

        在.gdbinit中加入 set startup-with-shell off。

    经过对比,在不关闭startup-with-shell的情况下,关闭SIP确实可以解决5中的问题.
0 0