Skip to content

Instantly share code, notes, and snippets.

@securisec
Last active February 4, 2025 13:44
Show Gist options
  • Save securisec/b88cf9e89f957669b95043c9c380a26e to your computer and use it in GitHub Desktop.
Save securisec/b88cf9e89f957669b95043c9c380a26e to your computer and use it in GitHub Desktop.
gdb debugging on ARM/m1 mac with docker

Instructions to setup a GDB container for an ARM mac

Improvement suggestions very welcome including automatically loading gdb commands etc

References

https://web.archive.org/web/20230419045554/https://sporks.space/2023/04/12/debugging-an-x86-application-in-rosetta-for-linux/

Build base docker image

FROM --platform=linux/amd64 ubuntu:22.04
RUN apt update && apt install git vim curl python3 binutils-multiarch file gdb gdb-multiarch -y
RUN git clone https://github.com/longld/peda.git ~/peda && \
  echo "source ~/peda/peda.py" > ~/.gdbinit && \
  echo "set architecture i386:x86-64\ntarget remote localhost:1234" > /x86-64 # this line doesnt do anything atm. 🚧 

Run docker container

docker run --rm -it -v $PWD:/data --cap-add=SYS_PTRACE --security-opt seccomp=unconfined --platform=linux/amd64 securisec/gdb /bin/bash

In terminal 1 Run LC_CTYPE=C.UTF-8 gdb normally without any binaries The following commands are run inside gdb

(gdb) set architecture i386:x86-64
# Read symbols. Without this, peda does not show the registers sometimes
(gdb) file /target_binary
# gbd remote debugging
(gdb) target remote localhost:1234

In Terminal 2, run the target binary with the following command ROSETTA_DEBUGSERVER_PORT=1234 ./target_binary

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment