简体   繁体   English

如何在 Linux 中调试 FUSE 文件系统崩溃

[英]How to debug FUSE filesystem crash in Linux

Currently I am developing an application using FUSE filesystem module in Linux (2.6 Kernel) in C language.目前我正在用 C 语言在 Linux(2.6 内核)中使用 FUSE 文件系统模块开发一个应用程序。 Due to some programming error, the application crashes after mounting the filesystem.由于一些编程错误,应用程序在挂载文件系统后崩溃。 Since I am a novice developer in Linux/C environment.由于我是 Linux/C 环境中的新手开发人员。 Could you please let me tell me possible options to debug such programs?你能告诉我调试这些程序的可能选项吗?

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). FUSE 有几个特性会使调试变得困难:它通常在后台运行(这意味着它与 stdin/out 分离)并且是多线程的(这会引入竞争条件并且使用 gdb 调试更复杂)。 Luckily, both features can be disabled:幸运的是,这两个功能都可以禁用:

  1. Use the -f switch to keep your application in the foreground.使用-f开关将您的应用程序保持在前台。 This will make your printf lines work.这将使您的 printf 行起作用。
  2. Use the -s switch to disable multithreading.使用-s开关禁用多线程。 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).禁用多线程会限制性能,但也会隐藏某些错误(竞争条件),简化 gdb 的使用,并确保 printf 输出可读(当多个线程大约同时调用 printf 时,它们的输出可能会混淆)。

I'd also recommend reading Geoff Kuenning's FUSE documentation .我还建议阅读 Geoff Kuenning 的FUSE 文档

使用-d选项运行您的保险丝客户端。

First, make sure you're compiling with debugging symbols enabled ( -g option to gcc ).首先,确保您在编译时启用调试符号( gcc -g选项)。 Before you run your program, enable core dumps with the shell command:在运行程序之前,使用 shell 命令启用核心转储:

ulimit -c unlimited

Then when the application crashes, it'll leave a core file in the current working directory (as long as it can write to it).然后当应用程序崩溃时,它会在当前工作目录中留下一个core文件(只要它可以写入)。

You can then load the core file in the gdb debugger:然后您可以在gdb调试器中加载核心文件:

gdb <executable file> <core file>

...and it'll show you where it crashed, and let you examine variables and so forth. ...它会告诉你它在哪里崩溃,并让你检查变量等等。

You can use Valgrind with FUSE, however read this first to learn about a setuid work-around.您可以将Valgrind与 FUSE 结合使用,但请先阅读本文以了解 setuid 解决方法。 I actually do the following as a convenience for others who might need to debug my file system:为了方便可能需要调试我的文件系统的其他人,我实际上做了以下操作:

#include <valgrind/valgrind.h>

if (RUNNING_ON_VALGRIND) {
    fprintf(stderr,
        "******** Valgrind has been detected by %s\n"
        "******** If you have difficulties getting %s to work under"
        " Valgrind,\n"
        "******** see the following thread:\n"
        "******** http://www.nabble.com/valgrind-and-fuse-file-systems"
        "-td13112112.html\n"
        "******** Sleeping for 5 seconds so this doesn't fly by ....",
            progname, progname);
    sleep(5);
    fprintf(stderr, "\n");
}

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.我在 FUSE 上工作了很多 .. 90% 的时间我的崩溃是由于泄漏导致 OOM 杀手采取行动,取消引用一个坏指针,双 free() 等。 Valgrind 是一个很好的工具来捕捉它. GDB is helpful, but I've found Valgrind to be indispensable. GDB 很有帮助,但我发现 Valgrind 是必不可少的。

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. UML 非常适合调试 linux 内核的通用部分,如文件系统、调度,但不适用于内核的硬件平台或驱动程序特定部分。

http://www.csee.wvu.edu/~katta/uml/x475.html http://www.csee.wvu.edu/~katta/uml/x475.html

http://valerieaurora.org/uml_tips.html http://valerieaurora.org/uml_tips.html

And looking at the diagram carefully:并仔细查看图表:

FUSE 文件系统的图像结果

You will see the application "hello" which is implementing all the FUSE callback handlers.您将看到正在实现所有 FUSE 回调处理程序的应用程序“hello”。 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.所以大部分调试都是在用户空间程序中进行的,因为 FUSE 内核模块(和 libfuse)通常是由 ALL FUSE 文件系统使用的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM