docker arm32 gdb ptrace: Could not trace the inferior process

Viewed 604

I am struggling with the arm32v7/ubuntu image. My host is Win10 professional and docker with command:

docker container run --cap-add=CAP_SYS_PTRACE --security-opt seccomp=unconfined --privileged -it --name ubuntuTest -h arm32 -v /C/WS/Docker:/WS arm32v7/ubuntu

the binaries are built with crosscompiler(on host) and with gcc (on docker). The problem which I am facing with is:

root@arm32:/WS/workspace/out# gdb TCP_server_arm32.out
GNU gdb (Ubuntu 9.2-0ubuntu1~20.04.1) 9.2
Copyright (C) 2020 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.
Type "show copying" and "show warranty" for details.
This GDB was configured as "arm-linux-gnueabihf".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from TCP_server_arm32.out...
(gdb) run
Starting program: /WS/workspace/out/TCP_server_arm32.out
warning: Could not trace the inferior process.
warning: ptrace: Function not implemented
During startup program exited with code 127.
(gdb)

for some reason, the gdb can't work. I am interested if this is because of the QEMU layer since the OS is emulated. But I have no idea what to try next. My idea was to build arm32 docker and debug applications in it with VS code.

Does someone knows how to make gdb or QEMU run with ptrace or enable ptrace somehow?

Thanks

2 Answers

QEMU's user-mode emulation does not support the ptrace system call, which means you can't run a gdb inside a chroot or container that is using QEMU to emulate each process and connect to an emulated process.

If you need to debug something that's running inside QEMU, you can instead enable QEMU's builtin gdbstub, and connect a target-architecture aware gdb running on your host system to it.

The solution is to install qemu-user and qemu-user-static in the docker container. On the Docker start the application with GDB stub on which you can connect from the host via gdb-multiarch.

which means:

  1. In the docker container start the application (built with gcc -g...)

qemu-arm localhost:1234 ./app.out

  1. On the host environment(my is ubuntu 20.04 LTS) run:

gdb-multiarch -q --nh -ex 'set architecture arm' -ex 'file app.out' -ex 'target remote docker_container_ip:1234'

and that is it.

Related