【问题标题】:Reading symbols from sshell...(no debugging symbols found)...done. (Yes, I used -g when compiling)从 sshell 读取符号...(未找到调试符号)...完成。 (是的,我在编译时使用了-g)
【发布时间】:2017-01-22 03:58:45
【问题描述】:

出于某种原因,我得到了这个 错误消息,并且不允许我单步执行我的代码。

ubuntu (master *) ECS150-Simple-Shell $ gdb sshell
GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.04) 7.11.1
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from sshell...(no debugging symbols found)...done.
(gdb) b LoadTerminal
Breakpoint 1 at 0x4010e8
(gdb) r
Starting program: /media/ubuntu/folder/sshell 
warning: the debug information found in "/lib64/ld-2.23.so" does not match "/lib64/ld-linux-x86-64.so.2" (CRC mismatch).


Breakpoint 1, 0x00000000004010e8 in LoadTerminal ()
(gdb) n
Single stepping until exit from function LoadTerminal,
which has no line number information.
sshell$ 

它不是逐行单步执行,而是单步执行代码的末尾。

我的 Makefile

objects = main.o terminal.o history.o parser.o 
cc = gcc
cflags = -g -Werror
sshell: $(objects)
    $(cc) $(cflags) $(objects) -o sshell
    rm $(objects)
main.o: main.c
terminal.o: terminal.c
history.o: history.c
parser.o: parser.c
.PHONY: clean
clean:
    rm sshell

我的 Makefile 在每个目标文件上都带有 -g

objects = main.o terminal.o history.o parser.o 
cc = gcc
cflags = -g -Werror
sshell: $(objects)
    $(cc) $(cflags) $(objects) -o sshell
    rm $(objects)
main.o: main.c
gcc -g -Werror -c main.c -o main.o
terminal.o: terminal.c
gcc -g -Werror -c terminal.c -o terminal.o
history.o: history.c
gcc -g -Werror -c history.c -o history.o
parser.o: parser.c
gcc -g -Werror -c parser.c -o parser.o
.PHONY: clean
clean:
    rm sshell

我什至尝试将 -g 选项添加到我的目标文件中,但我得到了同样的错误。

【问题讨论】:

  • 在编译.c 文件时,您绝对必须使用-g。从您的 Makefile 片段中,没有迹象表明正在发生这种情况。您可以通过readelf -WS sshell | grep debug 验证sshell 是否有调试信息。

标签: c debugging gcc makefile gdb


【解决方案1】:

由于某种原因

有几个可能的原因。我猜到的最可能的原因是您的gcc 并不是真正的/usr/bin/gcc,而是一些外壳包装器,它将不同的标志传递给/usr/bin/gcc

另一个可能的原因是您正在调试错误的二进制文件。 GDB 说您正在调试 /media/ubuntu/folder/sshell,但这是您构建的二进制文件吗?

我的Makefile

您的Makefile 似乎没有任何问题(除了对CCCLFAGS 等使用非常规变量之外——make 区分大小写)。

您真的应该使用make clean sshell 生成的命令,而不是显示Makefile

以下是我将用于分类此问题的步骤:

  1. 验证编译和最终链接命令是否实际包含-g
  2. 验证gcc/usr/bin/gcc
  3. 验证/media/ubuntu/folder/sshell 已在预期时间修改(使用ls -l)。
  4. 验证它是否包含调试信息:readelf -WS /media/ubuntu/folder/sshell | grep '\.debug'

上述陈述中至少有一项可能是错误的。如果它们都是正确的,那么您的 GCC 或 binutils 安装已损坏。

【讨论】:

  • 我没有在我的 Makefile 中为 'all' 指定规则。但是 make clean 会产生输出:rm sshell。没有错误。你是什​​么意思调试错误的二进制文件? sshell 是我使用 -g 标志编译的可执行文件。并且#4,sshell 不包含调试信息。为什么?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多