【发布时间】: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