如何使用GDB调试动态链接库(libfuse.so)?

huangapple go评论55阅读模式
英文:

How to debug a Dynamic Link Library (libfuse.so) using GDB?

问题

我是一个新手开发者在Linux/C中。最近,我正在使用WSL2 Ubuntu 20.04.6中的C语言使用libfuse开发文件系统,我需要调试libfuse的代码以查看确切的调用过程。但是当我尝试在GDB中加载.so文件时,它显示消息'You can't do that when your target is exec'。

以下是GDB消息。

(gdb) dir /lib/x86_64-linux-gnu
Source directories searched: /lib/x86_64-linux-gnu:$cdir:$cwd
(gdb) load libfuse.so.2
You can't do that when your target is `exec'

并且我在Makefile中使用了pkg-config fuse --cflags --libs来在编译过程中链接库。

我需要在调试模式下运行程序。但是我不知道如何进入libfuse的代码,但是GDB显示了以下信息。

(gdb) n
Single stepping until exit from function fuse_fs_write_buf,
which has no line number information.
0x00007ffff755558b in ?? () from /lib/x86_64-linux-gnu/libfuse.so.2
(gdb) n
Cannot find bounds of current function

我该怎么处理它?

英文:

I am a novice developer in Linux/C. Recently, I am developing a file system using libfuse in WSL2 Ubuntu 20.04.6 in C language, and I need to debug the code of libfuse to see the exact calling procedure. But when I try to load the .so file in GDB, it shows message 'You can't do that when your target is `exec''.

Here is the GDB message.

(gdb)  dir /lib/x86_64-linux-gnu
Source directories searched: /lib/x86_64-linux-gnu:$cdir:$cwd
(gdb) load libfuse.so.2
You can't do that when your target is `exec'

And I used pkg-config fuse --cflags --libs in Makefile to link the library during compiling .

I need to run the program in the debug mode. And I don't know how to step into the code of libfuse, but the GDB shows the follow information.

(gdb) n
Single stepping until exit from function fuse_fs_write_buf,
which has no line number information.
0x00007ffff755558b in ?? () from /lib/x86_64-linux-gnu/libfuse.so.2
(gdb) n
Cannot find bounds of current function

How can I deal with it?

答案1

得分: 1

你需要安装libfuse的调试信息:sudo apt install libfuse-dev

如果无法安装,可以从源代码构建,并包含调试信息。

英文:

You need install debug information for libfuse sudo apt install libfuse-dev.

If you can't install, then build it from sources with debug info.

huangapple
  • 本文由 发表于 2023年5月6日 21:50:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/76189243.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定