如何在gdb中查看musl的源代码

问题描述 投票:0回答:1

首先,我英语说得不太好。请原谅我。 我想检查gdb中musl的源代码。 这就是我所做的。

  1. 安装 musl-tools

  2. git://git.musl-libc.org/musl ,我已经放进去了~

  3. 设置gdb的路径,下面是我的'/~/.gdbinit'中的内容:

    layout src
    directory ~/musl/src                        
    
  4. 我创建一个c程序:

    #include <stdio.h>
    
    int main(){
      printf("hello\n");
    
      return 0;
    }
    
  5. 我用'musl-gcc -O1 -g3 -static test.c'编译它

  6. 然后我用gdb运行它。但是当我使用's'尝试进入printf的源代码时,它只是跳过它。

我尝试询问chatgpt,但仍然无法解决。 谁能告诉我为什么会发生这种情况以及我该如何解决它。

c gdb musl
1个回答
0
投票
  1. 您需要使用调试符号构建 musl:

    $ cd musl
    $ configure --enable-debug
    
  2. 告诉 musl-gcc 在构建程序时使用这些:

    $ musl-gcc -g3 -static -Lmusl/lib test.c
    
  3. 享受甜蜜的成功:

    Temporary breakpoint 1 at 0x40113d: file test.c, line 4.
    Starting program: /home/allan/1/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);
    
© www.soinside.com 2019 - 2024. All rights reserved.