6

I wanted to step into the code of ld.so whenever it will be used in my normal c code. I am trying to code flow through GDB in the TUI mode where you can see both source code and assembly as you step over the code.

For this I also installed libc-dbg binutils-source package from ubuntu package manager. GDB can find the debug symbols for the ld.so itself and I can step at the instruction level that is using si but I cant step at the source level as GDB is not able to find the source for ld.so and shows NO Source Available.

How can I make GDB find the source for ld.so so that I can also see which line in the ld.so source is actually being executed.

I am using Ubuntu 12.10 64bit with GCC 4.8.2

2 Answers 2

5

If you've libc's source code available, you can add sources to gdb's source path with dir command: Source_Path

Edit: To debug libc related files (in a Ubuntu distro) you would need to:

  1. Get libc's debug information by installing libc6-dbg packet.
  2. Get libc's source code by enabling source repositories (by running software-sources and and checking "enable source code repositories") and running apt-get source libc6
  3. Add libc's debug information into LD_LIBRARY_PATH: export LD_LIBRARY_PATH=/usr/lib/debug or LD_LIBRARY_PATH=/usr/lib/debug gdb <application>
  4. Add full path to c file to gdb's source path, this is: dir directory_path_libc_source/stdio-common
Sign up to request clarification or add additional context in comments.

8 Comments

I tried downloading the source through apt but got this error apt-get source libc6 Reading package lists... Done Building dependency tree Reading state information... Done Picking 'eglibc' as source package instead of 'libc6' E: Unable to find a source package for eglibc. So I did a wget the libc source for the version I have. I set the source_path using set directories absolute path to the root of the libc source. But I still can not see the source code for libc in GDB while stepping
@abhi This means that you miss enabling source repositories. You can enable them from "software sources" (you can reach it from "software center"'s edit menu or, from command line, running sofware-sources), and you will see a "enable source code repositories"
I corrected the apt-get source issue as you directed and downloaded the libc6 source in a directory. Started the gdb with simple test program to debug which had only one printf() and on stepping the code I still cant see the source. See the screen shot after i step on the printf() dropbox.com/s/0z8btk672vfaxot/gdb.png
@abhi Have you added libc's source directory with dir command? I mean, from your capture, it seems that it's not in gdb's source patch. Can you also try running info sources to check it?
This is exactly what I did: 1. gdb ./test -> dir directory_path_libc_source(the path is shown in show dir) the set a breakpoint before printf() and run. On hitting Breakpoint I did info sources (dropbox.com/s/z7b2rcysxqoexju/gdb1.png) stepped but cant see the code. On hitting printf() it says _printf (format=0x400594 "ABHI") at printf.c:30 30 printf.c: No such file or directory. (gdb) s 34 in printf.c (gdb) s 30 in printf.c
|
0

Download the Glibc source and path the same with gdb before debugging. Check this ubuntu blog

1 Comment

I tried the command given for gdb in the link you provided and gave it the path of the dir where I have the glibc source. I used a test program which had only a main with printf("ASAS") but on reaching the printf() it did not step into the printf() code in libc. Am I missing something

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.