C 正在从sshell读取符号…(未找到调试符号)…已完成。(是的,我在编译时使用了-g)

C 正在从sshell读取符号…(未找到调试符号)…已完成。(是的,我在编译时使用了-g),c,debugging,gcc,makefile,gdb,C,Debugging,Gcc,Makefile,Gdb,出于某种原因,我得到了这个 错误消息,不允许我单步执行代码 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/gp

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

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在每个对象文件上都有-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选项添加到我的对象文件中,但我得到了相同的错误

出于某种原因

有几个可能的原因。我能猜到的最可能的原因是,您的
gcc
实际上不是一个
/usr/bin/gcc
,而是一个shell包装器,它将不同的标志传递给
/usr/bin/gcc

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

我的
Makefile

您的
Makefile
似乎没有任何问题(除了对
CC
使用非常规变量,
CLFAGS
等--
make
区分大小写)

您不应该显示
Makefile
,而应该使用
makecleansshell
生成的命令

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

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

  • 上述陈述中至少有一项可能是错误的。如果它们都是真的,则说明GCC或binutils安装已损坏。

    在编译
    .c
    文件时,必须使用
    -g
    。从Makefile片段看,没有迹象表明发生了这种情况。您可以通过
    readelf-WS-sshell | grep debug
    验证
    sshell
    是否具有调试信息。我尚未在Makefile中为“all”指定规则。但是makeclean生成输出:rmsshell。没有错误。调试错误的二进制文件是什么意思?sshell是我用-g标志编译的可执行文件。和#4,sshell不包含调试信息。为什么?
    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