【发布时间】:2020-02-14 06:01:20
【问题描述】:
我正在尝试编译我的项目以使用 Makefile 进行调试。 makefile 当前生成多个不同的目标文件,然后从所有这些不同的目标文件编译单个可执行文件。 make文件如下:
CC=gcc
Scheduler: scheduler-exec.o scheduler-impl.o lab5_linkedlist.o lab5_queue.o
$(CC) -o Scheduler scheduler-impl.o scheduler-exec.o lab5_linkedlist.o lab5_queue.o
scheduler-exec.o: scheduler-exec.c
$(CC) -c -o scheduler-exec.o scheduler-exec.c
scheduler-impl.o: scheduler-impl.c
$(CC) -c -o scheduler-impl.o scheduler-impl.c
queue.o: lab5_queue.c
$(CC) -c -o lab5_queue.o lab5_queue.c
linkedlist.o: lab5_linkedlist.c
$(CC) -c -o lab5_linkedlist.o lab5_linkedlist.c
clean:
rm *.o
我想维护这个分布式编译系统,以便生成这些不同的目标文件,然后使用 Makefile 中的Scheduler 任务将它们一起编译。我尝试将-g 标志添加到所有任务中,但是当我在生成的Scheduler 可执行文件上运行gdb 时,它仍然没有调试信息。 gdb 程序的输出是这样的:
GNU gdb (GDB) 8.3
Copyright (C) 2019 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-apple-darwin18.5.0".
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 Scheduler...
--Type <RET> for more, q to quit, c to continue without paging--
程序就卡在那里了。我希望有一种方法可以使用 Makefile 编译该程序并能够获取变量信息。谢谢
我尝试了以下 makefile 它没有工作:
CC=gcc
Scheduler: scheduler-exec.o scheduler-impl.o lab5_linkedlist.o lab5_queue.o
$(CC) -o Scheduler scheduler-impl.o scheduler-exec.o lab5_linkedlist.o lab5_queue.o -g
scheduler-exec.o: scheduler-exec.c
$(CC) -c -o scheduler-exec.o scheduler-exec.c -g
scheduler-impl.o: scheduler-impl.c
$(CC) -c -o scheduler-impl.o scheduler-impl.c -g
queue.o: lab5_queue.c
$(CC) -c -o lab5_queue.o lab5_queue.c -g
linkedlist.o: lab5_linkedlist.c
$(CC) -c -o lab5_linkedlist.o lab5_linkedlist.c -g
clean:
rm *.o
【问题讨论】:
-
您是否也将
-g添加到可执行规则中? -
你的意思是在没有Makefile的情况下构建时,GDB不会卡住吗?
-
我尝试将 -g 添加到所有任务中。编辑问题以反映这一点
-
@G.M.嘿,所以我启动了一个 Xubuntu 映像,调试器正确加载了符号。但是,当我尝试在 mac 上使用相同的 makefile 时,它不起作用。在 Xubuntu 上运行 readelf 确实显示了调试标志。有没有可以用来检查我的 mac 版本的 readelf 等价物?
-
好的,所以我运行了 objdump,但它没有输出任何用于调试的内容。但后来我重新创建了我的 gdb 证书,符号现在已加载到 GDB 中,但它仍然不能运行我的程序。但是由于符号正在加载,因此对于该线程来说不再是问题。非常感谢您的帮助。