C++ 使用 gdb 时找不到调试符号

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5244509/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 17:44:43  来源:igfitidea点击:

no debugging symbols found when using gdb

c++gdb

提问by ant2009

GNU gdb Fedora (6.8-37.el5) Kernal 2.6.18-164.el5

GNU gdb Fedora (6.8-37.el5) 内核 2.6.18-164.el5

I am trying to debug my application. However, everytime I pass the binary to the gdb it says:

我正在尝试调试我的应用程序。但是,每次我将二进制文件传递给 gdb 时,它都会说:

(no debugging symbols found)

Here is the file output of the binary, and as you can see it is not stripped:

这是二进制文件的文件输出,正如您所看到的,它没有被剥离:

vid: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), for GNU/Linux 2.6.9, not stripped

I am compiling with the following CFLAGS:

我正在使用以下 CFLAGS 进行编译:

CFLAGS = -Wall -Wextra -ggdb -O0 -Wunreachable-code

Can anyone tell me if I am missing some simple here?

谁能告诉我这里是否缺少一些简单的东西?

采纳答案by geekosaur

Some Linux distributions don't use the gdbstyle debugging symbols. (IIRC they prefer dwarf2.)

某些 Linux 发行版不使用gdb样式调试符号。(他们更喜欢 IIRC dwarf2。)

In general, gccand gdbwill be in sync as to what kind of debugging symbols they use, and forcing a particular style will just cause problems; unless you know that you need something else, use just -g.

在一般情况下,gccgdb会同步以什么样的调试他们使用的符号,并迫使特定样式只会导致问题; 除非你知道你需要别的东西,否则只使用-g.

回答by Employed Russian

The most frequent cause of "no debugging symbols found" when -gis present is that there is some "stray" -sor -Sargument somewhere on the link line.

出现“未找到调试符号”的最常见原因是链接线上某处-g存在一些“杂散”-s-S参数。

From man ld:

来自man ld

   -s
   --strip-all
       Omit all symbol information from the output file.

   -S
   --strip-debug
       Omit debugger symbol information (but not all symbols) from the output file.

回答by Maxim Egorushkin

The application has to be both compiledand linkedwith -goption. I.e. you need to put -gin both CPPFLAGSand LDFLAGS.

应用程序必须同时编译并与选项链接-g。即你需要-g同时输入CPPFLAGSLDFLAGS

回答by Kevin Parker

You should also try -ggdb instead of -g if you're compiling for Android!

如果您正在为 Android 编译,您还应该尝试 -ggdb 而不是 -g!

回答by Dave

I know this was answered a long time ago, but I've recently spent hours trying to solve a similar problem. The setup is local PC running Debian 8 using Eclipse CDT Neon.2, remote ARM7 board (Olimex) running Debian 7. Tool chain is Linaro 4.9 using gdbserver on the remote board and the Linaro GDB on the local PC. My issue was that the debug session would start and the program would execute, but breakpoints did not work and when manually paused "no source could be found" would result. My compile line options (Linaro gcc) included -ggdb -O0 as many have suggested but still the same problem. Ultimately I tried gdb proper on the remote board and it complained of no symbols. The curious thing was that 'file' reported debug not stripped on the target executable.

我知道这是很久以前的答案,但我最近花了几个小时试图解决类似的问题。设置是使用 Eclipse CDT Neon.2 运行 Debian 8 的本地 PC,运行 Debian 7 的远程 ARM7 板 (Olimex)。工具链是使用远程板上的 gdbserver 的 Linaro 4.9 和本地 PC 上的 Linaro GDB。我的问题是调试会话将启动并且程序将执行,但断点不起作用并且当手动暂停时“找不到源”会导致。我的编译行选项 (Linaro gcc) 包括 -ggdb -O0 正如许多人所建议的那样,但仍然是同样的问题。最终,我在远程板上正确地尝试了 gdb,但它抱怨没有符号。奇怪的是,“文件”报告的调试未在目标可执行文件上剥离。

I ultimately solved the problem by adding -g to the linker options. I won't claim to fully understand why this helped, but I wanted to pass this on for others just in case it helps. In this case Linux did indeed need -g on the linker options.

我最终通过在链接器选项中添加 -g 解决了这个问题。我不会声称完全理解为什么这会有所帮助,但我想将其传递给其他人,以防万一。在这种情况下,Linux 确实需要在链接器选项上使用 -g。

回答by atx

Replace -ggdb with -g and make sure you aren't stripping the binary with the strip command.

将 -ggdb 替换为 -g 并确保您没有使用 strip 命令剥离二进制文件。

回答by Swagger 68

Hope the sytem you compiled on and the system you are debugging on have the same architecture. I ran into an issue where debugging symbols of 32 bit binary refused to load up on my 64 bit machine. Switching to a 32 bit system worked for me.

希望您编译的系统和您正在调试的系统具有相同的体系结构。我遇到了一个问题,即 32 位二进制的调试符号拒绝加载到我的 64 位机器上。切换到 32 位系统对我有用。