How to install GDB on mac m1 (apple silicon)?
Asked Answered
C

5

41

I failed using brew to install gdb. I was using the following command:

brew install gdb

Is gdb available on mac m1 (apple silicon)? If so, what should I do?

Chacon answered 29/4, 2021 at 2:8 Comment(0)
L
34

gdb is not supported on M1 Macs; you can instead consider using lldb.

Lovett answered 30/4, 2021 at 2:12 Comment(4)
That answer is not helpful, now always LLDB is a good option. I.e. when trying to debug using Eclipse environment. I am trying to build GDB in native mode for M1 with little success. Still do not know why, but GDB config files refuses to create a proper makefile on M1. Will update if progressMeredith
gdb is needed for rust-gdb as well. Rust development is pretty much broken on M1Marquita
@Meredith So did you progress?Marcy
©juansolsona I think it is helpful, though not optimal, as it's pretty much the only way forward.Unbrace
J
7

GDB currently (September 2022) does not support the aarch64 architecture. See also:

https://mcmap.net/q/393173/-building-gdb-from-source-on-macos

Juncture answered 2/9, 2022 at 7:9 Comment(1)
More specifically, it supports the aarch64 architecture on other host OSes (eg Linux), but not on macos.Impracticable
H
3

I had the same problem, my university requires the use of gdb as a debugger.

I thought about using a virtual machine (a kind of WSL for M1) and I discovered lima.

I installed and configured my virtual machine with Ubuntu and then installed gdb on it (apt-get install gdb).

The remaining problem was configuring VS Code to use gdb (which was installed on the virtual machine). To do this, I used a VS Code extension called Remote - SSH.

With this extension, I was able to connect to my virtual machine (localhost) and use VS Code as if I were on a Linux environment.

I hope this can help you.

Haddad answered 21/3, 2023 at 22:3 Comment(0)
C
3

I had the same problem and was able to solve it using lima as mentioned above (it's a virtual linux terminal inside macos - similar to WSL in Windows). Here's a detailed step by step guide to activate this and integrate it into vs code:

  1. Install lima using homebrew

    brew install lima
    
  2. start the lima terminal from your mac terminal

    limactl start
    

This will initialize the linux terminal (i.e., install ubuntu image by default and activate it). Wait for it to finish the installation process.

  1. open ubuntu terminal from mac terminal using

    lima
    

Now, you will see that your terminal becomes an ubuntu terminal and you can access all your files from there. You can exit your linux terminal using exit. This will return you back to mac terminal.

  1. Install the needed libraries within ubuntu terminal

    sudo apt install build-essential gdb gfortran
    
  2. Give lima write access to your local files (to be able to run codes and write outputs).

    a. from mac terminal do the following:

    open ~/.lima/default/lima.yaml
    

    In this file set writable: true for - location: "~"

    b. restart lima (linux termianl) using the following:

    limactl stop default #or name of the machine 
    limactl start default #or name of the machine 
    

    note, that your machine's name is default (this is the default name).

Now you have your linux machine (terminal) ready and you can use gdb from the terminal.


Integration with vs code

Once you do the above steps, you can allow an ssh connection to your linux virtual machine to be able to connect to it and debug codes using gdb from vs code.

  1. Install Remote Development extention in vs code, which enables ssh connection to your virtual machine

  2. add the ssh configuration of your linux vm to vs code

    a. do the following from mac terminal:

    open ${LIMA_HOME:-$HOME/.lima}/default/ssh.config
    

    this will open the ssh.config file of your vm

    b. copy the content of the above file and paste it into ~/.ssh/config, which is vs code ssh config file. If you don't have that file, create a new one in the same location.

  3. open vs code and establish an ssh connection using command + shift + p -> Remote-SSH: connect to host -> choose lima-default.

Now, you are connected to the virtual machine (lima), you can navigate to your local files by opening a new directory and navigating to /Users/username/... Note that vs code by default directs you to /home/username.linux/, which won't have your local files. You can install any needed extensions from vs code to the ssh (linux vm) by clicking on the install in SSH: lima-default option under the locally installed extensions.

enter image description here

You now can debug codes in vs code using gdb on mac silicon M series.

Creamer answered 24/1, 2024 at 21:16 Comment(0)
C
2

This is only a partial answer, but for cross-architecture debugging, eg to communicate with gdbserver running on another device, you can try brew install arm-none-eabi-gdb or brew install aarch64-elf-gdb which should work to let you connect with gdbservers on those respective architectures.

Cordula answered 28/2, 2024 at 17:0 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.