Debug libc

Debug glibc function with source code in gdb

Download source code

1
2
3
4
5
$ sudo apt-get install libc6-dbg
# sudo apt-get install eglibc-source
$ sudo apt-get install glibc-source
$ cd /usr/src/glibc
$ sudo tar xvf glibc-2.27.tar.xz

Tell gdb where to find the source

1
2
# gdb --directory /usr/src/glibc/glibc-2.27/TheFuncYouWant2Debug program
$ gdb --directory /usr/src/glibc/glibc-2.27/malloc program

malloc

1
2
$ gdb
(gdb) dir /usr/src/glibc/glibc-2.27/stdio-common

printf

(It’s undoubtable that you can specify more than one source path)

1
2
3
4
$ gdb
(gdb) dir /usr/src/glibc/glibc-2.27/stdio-common
(gdb) dir /usr/src/glibc/glibc-2.27/malloc
(gdb) dir /usr/src/glibc/glibc-2.27/....

origin