Include source code of malloc.c in gdb?

The following worked for me. Not sure whether there is a better way.

  1. Install libc6-dbg (which you have already done):
    sudo apt-get install libc6-dbg
  2. Install the eglibc-source package (ubuntu actually uses eglibc): sudo apt-get install eglibc-source.
  3. Unpack the tar file that was installed in /usr/src/glibc: /usr/src/glibc $ sudo tar xvf eglibc-2.19.tar.xz
  4. Crank up gdb and add in the path to the malloc source: (gdb) dir /usr/src/glibc/eglibc-2.19/malloc

(gdb) n

13 char *c = malloc(100);

(gdb) s

__GI___libc_malloc (bytes=100) at malloc.c:2876 2876

{

(gdb)

Leave a Comment