我是否需要安装带有调试符号的包才能在我的 C 编译可执行文件上使用 Valgrind?

Do I need to install packages with debug symbols to use Valgrind on my C-compiled executable?

我从事系统编程 class,我们的一项作业的基于 python 的测试驱动程序需要 运行 C 编译的可执行文件上的 Valgrind。

我正在尝试将 Valgrind 安装到我的笔记本电脑上。我正在使用 Ubuntu 18.04.4 LTS。我正在阅读有关此的 Ubuntu wiki and the page on Valgrind said to "have packages with debug symbols installed." I checked the page they reference,但我仍然不知道我需要使用调试符号安装哪些包。

我正在阅读一些堆栈溢出的答案,this one mentions that "Valgrind is readily usable for C/C++ code, but can even be used for other languages when configured." The Valgrind quickstart guide 也没有给出有关调试符号的警告。它只是说在编译时使用标志-g

Ubuntu wiki 关于调试符号的警告是否仅适用于不是从 C 编译的其他程序?

Wiki 说明了您的代码 link 所使用的任何库。为了从 valgrind 分析 stracktraces,最好使用这些库调试版本 link。这些库是什么仅取决于您的应用程序。

假设您开发了一些应用程序。然后您想跟踪一些内存泄漏或分段错误。所以你 运行 你在 valgrind 下编译的程序。您使用 -g 标志编译您的程序,以便在 valgrind 打印出分配的堆栈跟踪时收到来自 valgrind 的良好消息。多亏了这个标志,您可以在堆栈跟踪中看到更多信息,例如您编写的函数的确切函数名称。

wiki 所说的内容。 它说明了您的代码 link 所使用的任何库。例如。你 link with boost Stacktraces 可能还包括来自 boost 的函数调用。为了在堆栈跟踪中获得更多关于 boost 函数名称的调试信息,您需要 link 和 boost 使用调试符号编译。

您在 wiki 上找到的是一个建议,如果您 link 使用例如来自 xserver-xorg-core 的一些库,那么安装 xserver-xorg-core-dbg、link 和 运行 这样一个在 valgrind 下的 linked 应用程序可能对你有好处。你的堆栈跟踪会看起来更好,即使部分不是你编码的,但你只使用 xserver-xorg-core(-dbg) 提供的库。就这些了。

他们引用的页面说:

If you want to debug a crash from an application provided by Ubuntu, you are developing yourself, provided by a third-party, or need the debug symbols for particular libraries very often, it is helpful to install the relevant debugging packages.

For many, but not all, packages, one can simply add a -dbg suffix to the package name to install it. For example:

sudo apt-get install xserver-xorg-core-dbg

这和我写的意思一样。我只是想详细说明一下。