如何在Mac M1(Apple Silicon)上安装GDB?

36

我使用brew安装gdb失败了。我使用了以下命令:

brew install gdb

gdb是否适用于Mac M1(Apple Silicon)?如果是,我该怎么做?

5个回答

25
gdb在M1 Mac上不受支持,您可以考虑使用lldb代替。

5
那个答案没有帮助,现在LLDB是一个不错的选择。比如,在Eclipse环境下尝试进行调试时。 我正在尝试在M1上本地模式构建GDB,但进展很小。仍然不知道原因,但是GDB配置文件拒绝在M1上创建适当的makefile。如果有进展,我会更新。 - juansolsona
1
rust-gdb 也需要 gdb。M1 上 Rust 的开发基本上是不可用的。 - A. K.
@juansolsona 你有进展了吗? - VimNing
1
©juansolsona 我认为这是“有帮助的”,虽然不是“最佳选择”,但这几乎是唯一的前进方式。 - MEMark

5

5
更具体地说,它支持在其他主机操作系统(例如Linux)上的aarch64架构,但不支持在macOS上。 - Peter Maydell

3

我曾经遇到过同样的问题,我的大学要求使用gdb作为调试器。

我考虑使用虚拟机(一种M1的WSL)并发现了lima

我安装并配置了Ubuntu虚拟机,然后在其中安装了gdb(apt-get install gdb)。

剩下的问题是配置VS Code以使用已安装在虚拟机上的gdb。为此,我使用了一个名为Remote - SSH的VS Code扩展程序。

通过这个扩展程序,我能够连接到我的虚拟机(本地主机),并像在Linux环境下一样使用VS Code。

希望这可以帮到你。


-1

看起来现在可以使用gdb了。我刚刚通过brew安装了它:

➜  ~ gdb -v
zsh: command not found: gdb
➜  ~ brew install gdb
Running `brew update --auto-update`...
==> Auto-updated Homebrew!
Updated 3 taps (homebrew/core, homebrew/cask and homebrew/services).
==> New Formulae
ada-url                         amber                           ata                             chatblade                       ffmpeg@5
==> New Casks
active-trader-pro                       reminders-menubar                       tuist                                   xtool-creative-space

You have 6 outdated formulae installed.

==> Fetching gdb
==> Downloading https://ghcr.io/v2/homebrew/core/gdb/manifests/13.1
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/gdb/blobs/sha256:de9efad28231614ea8281c5e56c0c844634401924fb152f2dd21d578323b3235
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:de9efad28231614ea8281c5e56c0c844634401924fb152f2dd21d578323b3235?se=2023-
######################################################################## 100.0%
==> Pouring gdb--13.1.ventura.bottle.tar.gz
==> Caveats
gdb requires special privileges to access Mach ports.
You will need to codesign the binary. For instructions, see:

  https://sourceware.org/gdb/wiki/PermissionsDarwin
==> Summary
  /usr/local/Cellar/gdb/13.1: 67 files, 30.6MB
==> Running `brew cleanup gdb`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
➜  ~ gdb -v          
GNU gdb (GDB) 13.1
Copyright (C) 2023 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.
➜  ~ 

(Apple M1 Max - Ventura 13.3.1)


3
截至4月23日,我无法安装它,提示如下:gdb:此软件需要x86_64架构。 错误:gdb:未满足此构建的某一要求。 - Joe Gasewicz
我仍然收到错误信息:brew install gdb gdb: 此软件需要 x86_64 架构。 错误:gdb:未满足要求,构建失败。 - Arya
是的,它能够工作是因为Rosetta技术。 - zzpzaf

-2
解决方案是:在Finder-Applications-Terminal-Profile中打开Rosetta选项,将Homebrew重新安装到/usr/local,并安装gdb。
官方的Homebrew脚本会根据系统是否为Arm64架构来确定Mac是否具有Intel或M1芯片,并选择安装路径为/usr/local/或/opt/Homebrew/。一般的想法是打开终端的Rosetta选项,卸载brew(也可以将brew文件夹保留在/opt下,但当您为arm安装软件时,需要指定/opt下的目录,例如:/opt/homebrew/bin/brew install vim)或者只删除该文件夹,确保在/opt下没有Homebrew文件夹,然后重新安装Homebrew到/usr/local。
这是我用来安装brew的脚本:/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
tbz@TBZ-2 ~ % gdb -v  
zsh: command not found: gdb
tbz@TBZ-2 ~ % brew install gdb
==> Fetching gdb
==> Downloading https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles//gdb-13.2.
######################################################################### 100.0%
==> Pouring gdb-13.2.ventura.bottle.tar.gz
==> Caveats
gdb requires special privileges to access Mach ports.
You will need to codesign the binary. For instructions, see:

  https://sourceware.org/gdb/wiki/PermissionsDarwin
==> Summary
  /usr/local/Cellar/gdb/13.2: 67 files, 30.6MB
==> Running `brew cleanup gdb`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
tbz@TBZ-2 ~ % which brew
/usr/local/Homebrew/bin/brew
tbz@TBZ-2 ~ % 

我是一名本科生,水平有限,请多包涵。

重新安装Homebrew到/usr/local,个人参考:https://blog.csdn.net/Le_1M/article/details/122685709

(Apple M1 pro - Ventura 13.4 (22F66))


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接