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

标签 c gdb musl

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

  1. apt 安装 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,但仍然无法解决。 谁能告诉我为什么会发生这种情况以及我该如何解决它。

最佳答案

  1. 使用调试符号构建 musl:

    $ (cd musl; configure --enable-debug; make)
    
  2. 使用调试符号针对库构建程序:

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

    $ 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);
    

关于c - 如何在gdb中查看musl的源代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77673440/

相关文章:

c - 存储 gdb 调用 expr 返回值

c++ - 如果我创建了一个进程,是否意味着我总能终止它?

c - C中相同结构的两个名称

c - Mingw - 从规范文件中删除选项

c - 如何实际检测 musl libc?

c - 在 Eclipse for C 中包含外部 header

使用 gdb 为 C 模块调试 Python 源代码

c++ - 具有继承的C++中的段错误

docker - 标准_init_linux.go :219: exec user process caused: no such file or directory