Build a custom GDB supported python debuging in a Alpine based docker container

in python •  4 years ago 

image.png

Currently one of our services has a strange bug. The process is always going to a sleep state after running serveral hours with no exception errors, no more output logs, just hunged up.

We are tring to install GDB in the container. But GDB from alpine packages does not support python debugging. We have to rebuild a custom GDB for debugging.

Install the necessary dependencies

~ # apk update && apk add  musl-dev python3 python3-dev wget musl-dbg binutils-dev binutils expat expat-dev texinfo
 linux-headers gcc g++ make

Download and unarchive the GDB source code

# GDB in alpine 3.7 is version 8.0.1
~ # wget https://ftp.gnu.org/gnu/gdb/gdb-8.0.1.tar.gz
~ # tar zxvf gdb-8.0.1.tar.gz

Download and unarchive the Python3.6.9

~ # wget https://www.python.org/ftp/python/3.6.9/Python-3.6.9.tgz
~ # tar zxvf Python-3.6.9.tgz

Build the GDB

~ # cd gdb-8.0.1

~/gdb-8.0.1 # ./configure --with-python=/usr/bin/python3 \
--with-expat --with-gdb-datadir=/usr/share/gdb \
--with-jit-reader-dir=/usr/lib/gdb \
--with-separate-debug-dir=/usr/lib/debug

~/gdb-8.0.1 # make

~/gdb-8.0.1 # make install

Test if GDB has supported py* tool

Run GDB with PYTHONPATH env parameter.

~ # PYTHONPATH=/root/Python-3.6.10/Tools/gdb  /usr/local/bin/gdb  python3

If you see any no debugging symbols found error info, to search related dbg package.
For example, run apk add python3-dbg to add python3 debugging symbols support.

Import libpython

(gdb) python import libpython

Test if py-* exist

image.png

Any Issue

If you have any issue, please join our discord for help.

https://discord.gg/C6CgUqUmUU

Vote

I'm also a witness. Thank you for voting me.

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!