如何在 Linux 中调试 FUSE 文件系统崩溃
目前我正在Linux(2.6内核)中用C语言开发一个使用FUSE文件系统模块的应用程序。由于某些编程错误,应用程序在安装文件系统后崩溃。由于我是 Linux/C 环境中的新手开发人员。您能否告诉我调试此类程序的可能选项?
Currently I am developing an application using FUSE filesystem module in Linux (2.6 Kernel) in C language. Due to some programming error, the application crashes after mounting the filesystem. Since I am a novice developer in Linux/C environment. Could you please let me tell me possible options to debug such programs?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
FUSE 有几个特性可能会导致调试变得困难:它通常在后台运行(这意味着它与标准输入/输出分离)并且是多线程的(这可能会引入竞争条件,并且使用 gdb 进行调试更加复杂)。幸运的是,这两个功能都可以禁用:
-f
开关将应用程序保持在前台。这将使您的 printf 行正常工作。-s
开关禁用多线程。禁用多线程会限制性能,但也会隐藏某些错误(竞争条件),简化 gdb 的使用,并确保 printf 输出可读(当多个线程大约同时调用 printf 时,它们的输出可能会混合)。我还建议阅读 Geoff Kuenning 的 FUSE 文档。
There are a couple features of FUSE that can make it difficult to debug: it normally runs in the background (which means it detaches from stdin/out) and is multithreaded (which can introduce race conditions and is more complicated to debug with gdb). Luckily, both features can be disabled:
-f
switch to keep your application in the foreground. This will make your printf lines work.-s
switch to disable multithreading. Disabling multithreading will limit performance, but will also hide certain bugs (race conditions), simplify the use of gdb, and ensure printf output is readable (when multiple threads call printf at about the same time their output can get mixed up).I'd also recommend reading Geoff Kuenning's FUSE documentation.
使用
-d
选项运行您的 fusion 客户端。Run your fuse client with the
-d
option.首先,确保您在启用调试符号的情况下进行编译(
gcc
的-g
选项)。在运行程序之前,使用 shell 命令启用核心转储:然后,当应用程序崩溃时,它将在当前工作目录中留下一个 core 文件(只要它可以写入)。
然后,您可以在
gdb
调试器中加载核心文件:...它会向您显示崩溃的位置,并让您检查变量等。
First, make sure you're compiling with debugging symbols enabled (
-g
option togcc
). Before you run your program, enable core dumps with the shell command:Then when the application crashes, it'll leave a
core
file in the current working directory (as long as it can write to it).You can then load the core file in the
gdb
debugger:...and it'll show you where it crashed, and let you examine variables and so forth.
您可以将Valgrind与FUSE一起使用,但是首先阅读本文以了解 setuid 解决方法。实际上,我做了以下事情,以方便其他可能需要调试我的文件系统的人:
我经常使用 FUSE .. 90% 的崩溃是由于泄漏导致 OOM 杀手采取行动,取消引用错误的指针、双重 free() 等。Valgrind 是一个很好的工具来捕获这些问题。 GDB 很有帮助,但我发现 Valgrind 是不可或缺的。
You can use Valgrind with FUSE, however read this first to learn about a setuid work-around. I actually do the following as a convenience for others who might need to debug my file system:
I work on FUSE a lot .. and 90% of the time my crashes are due to a leak which causes the OOM killer to take action, dereferencing a bad pointer, double free(), etc. Valgrind is a great tool to catch that. GDB is helpful, but I've found Valgrind to be indispensable.
UML 非常适合调试 Linux 内核的通用部分,例如文件系统、调度,但不适用于调试内核的硬件平台或驱动程序特定部分。
http://www.csee.wvu.edu/~katta/uml/ x475.html
http://valerieaurora.org/uml_tips.html
看看仔细看图:
您将看到应用程序“hello”,它正在实现所有 FUSE 回调处理程序。因此,大部分调试是在用户空间程序中进行的,因为 FUSE 内核模块(和 libfuse)通常供所有 FUSE 文件系统使用。
UML is very good for debugging generic parts of linux kernel like filesystem, scheduling but not the hardware platform or drivers specific part of kernel.
http://www.csee.wvu.edu/~katta/uml/x475.html
http://valerieaurora.org/uml_tips.html
And looking at the diagram carefully:
You will see the application "hello" which is implementing all the FUSE callback handlers. So majority of debugging is in userspace program, as the FUSE kernel module (and libfuse) is generically meant to be used by ALL FUSE filesystem.