bug: gdb cannot be used in alpine3.13 and later versions in the docker image under arm64 architecture
I'm building a docker base image with alpine3.14, but after the build is complete, I find that gdb doesn't work and can't see stack info. I switched to alpine3.12 version, and gdb can work fine. My os info like:
$ uname -a
Darwin 192.168.0.104 21.3.0 Darwin Kernel Version 21.3.0: Wed Jan 5 21:37:58 PST 2022; root:xnu-8019.80.24~20/RELEASE_ARM64_T8101 arm64
$ docker version
Client:
Cloud integration: v1.0.22
Version: 20.10.12
API version: 1.41
Go version: go1.16.12
Git commit: e91ed57
Built: Mon Dec 13 11:46:56 2021
OS/Arch: darwin/arm64
Context: default
Experimental: true
Server: Docker Desktop 4.5.0 (74594)
Engine:
Version: 20.10.12
API version: 1.41 (minimum version 1.12)
Go version: go1.16.12
Git commit: 459d0df
Built: Mon Dec 13 11:43:07 2021
OS/Arch: linux/arm64
Experimental: false
containerd:
Version: 1.4.12
GitCommit: 7b11cfaabd73bb80907dd23182b9347b4245eb5d
runc:
Version: 1.0.2
GitCommit: v1.0.2-0-g52b36a2
docker-init:
Version: 0.19.0
GitCommit: de40ad0
You can use the following steps to reproduce:
step 1: Download the dockerfile and anyother tools
$ wget https://github.com/api7/apisix-build-tools/archive/refs/tags/apisix/2.12.1.tar.gz
step 2: Decompress
$ tar -zxvf apisix-build-tools-apisix-2.12.1.tar.gz
$ cd apisix-build-tools-apisix-2.12.1
step 3: Build docker images
$ make package version=1.19.9.1.4 image_base=alpine image_tag=3.13 app=apisix-base type=apk
step 4: Start the above-built instance via the docker-compose file
version: "3"
services:
apisix-arm:
image: apache/apisix-base-apk:1.19.9.1.4
restart: "no"
privileged: true
ulimits:
core: -1
command:
/usr/local/openresty/bin/openresty -g "daemon off;"
networks:
apisix_base_net:
networks:
apisix_base_net:
driver: bridge
step 5: According to your environment, go into the container started above
step 6: update apk and install gdb
$ apk update
$ apk add gdb
step 7: Adjust kernel parameters
$ sysctl -w kernel.core_pattern=/tmp/core-%e.%p.%t
$ sysctl -p /etc/sysctl.conf
step 8: kill openresty work with signal SIGABRT
$ ps -elf|grep nginx|grep worker|awk '{print $1}'|xargs kill -6
And then you will see coredumps in /tmp.
step 9: Use gdb to get some statk info
$ gdb /usr/local/openresty/nginx/sbin/nginx /tmp/core.xxxxxx
GNU gdb (GDB) 10.1
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 "aarch64-alpine-linux-musl".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://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 /usr/local/openresty/nginx/sbin/nginx...
warning: Can't open file /dev/zero (deleted) during file-backed mapping note processing
warning: core file may not match specified executable file.
[New LWP 8]
Core was generated by `nginx: worker process '.
Program terminated with signal SIGABRT, Aborted.
#0 0x0000ffffb52f1428 in ?? () from /lib/ld-musl-aarch64.so.1
(gdb) bt
#0 0x0000ffffb52f1428 in ?? () from /lib/ld-musl-aarch64.so.1
#1 0xffffffffffffffff in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
So, is this a bug? Is this related to the upgrade of QEMU?
In step 3, if I use alpine with 3.12, the gdb works well
$ make package version=1.19.9.1.4 image_base=alpine image_tag=3.12 app=apisix-base type=apk