Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

debugging - Include source code of malloc.c in gdb?

How can I include/view the source code of malloc in gdb?

I want to do a step by step execution in gdb, and step into malloc.c source code when any of the malloc functions is called.

Currently what gdb says is: malloc.c: No such file or directory.

This guy here faced the same problem, but they do not mention a solution, ie how to actually step into the source code of malloc.

I am on Ubuntu server 14.04, and I have already tried to install the following: libc6-dbg, libc6-dev, and libc6-dbgsym. I don't even know if one of these packages might help, but installing the libc-dbgsym gives me the following error:

dpkg: error processing archive /var/cache/apt/archives/libc6-dbgsym_2.19-0ubuntu6.6_amd64.ddeb (--unpack):  trying to overwrite
    '/usr/lib/debug/usr/lib/x86_64-linux-gnu/audit/sotruss-lib.so', which
    is also in package libc6-dbg:amd64 2.19-0ubuntu6.6 dpkg-deb: error:
    subprocess paste was killed by signal (Broken pipe)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...