how to check the source code of musl in gdb

138 views Asked by At

First of all, I don't speak English very well. Please forgive me. I want to check the source code of musl in gdb. This is what i have done.

  1. apt install musl-tools

  2. git://git.musl-libc.org/musl ,i have put it into ~

  3. set the path for gdb,below is what in my '/~/.gdbinit':

    layout src
    directory ~/musl/src                        
    
  4. i create a c program:

    #include <stdio.h>
    
    int main(){
      printf("hello\n");
    
      return 0;
    }
    
  5. i compile it with 'musl-gcc -O1 -g3 -static test.c'

  6. then i run it with gdb.But when i use 's' to try to step into the source code of printf,it just skip it.

i have tried to ask chatgpt,but still can't solve it. can anybody tell me why this happen and how can i sovle it.

1

There are 1 answers

6
Allan Wind On BEST ANSWER
  1. Build musl with debug symbols:

    $ (cd musl; configure --enable-debug; make)
    
  2. Build you program against library with debug symbols:

    $ musl-gcc -g3 -static -Lmusl/lib test.c
    
  3. Enjoy the sweet success:

    $ gdb ./a.out
    (gdb) start
    Temporary breakpoint 1 at 0x40113d: file test.c, line 4.
    Starting program: /home/allan/a.out 
    
    Temporary breakpoint 1, main () at test.c:4
    4               printf("hello\n");
    (gdb) s
    puts (s=0x402000 "hello") at src/stdio/puts.c:6
    6       FLOCK(stdout);