如何修复GDB找不到文件:"../sysdeps/unix/sysv/linux/raise.c:50"



我们正在学习在我的计算机体系结构课上使用GDB。为此,我们使用SSH连接到树莓派来完成大部分工作。当在某些代码上运行 GDB 时,他给了我们调试,尽管它以一条错误消息结束,说明它如何找不到 raise.c

我试过:

安装 libc6,libc6-dbg(表示它们已经是最新的(

apt-get source glibc(给我:"你必须在你的sources.list中放一些'源'URI"(

https://stackoverflow.com/a/48287761/12015458(apt source 返回与上面的 apt-get source 相同的内容,用户给出的"查找$PWD"命令不返回任何内容(

我试过手动查找它,它可能是在哪里?(/lib/libc 对我来说不存在(

这是他给我们的代码,让我们尝试在 GDB 上调试:

#include <stdio.h>
main()
{
int x,y;
y=54389;
for (x=10; x>=0; x--)
y=y/x;
printf("%dn",y);
}

但是,每当我在 GDB 中运行代码时,都会收到以下错误:

Program received signal SIGFPE, Arithmetic exception.
__GI_raise (sig=8) at ../sysdeps/unix/sysv/linux/raise.c:50
50      ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.

我问他这件事,他对如何解决它真的没有任何想法。

找不到raise()的来源并不重要。它只会显示最终引发异常的行,而不显示触发错误的位置。

在 GDB 中再次运行错误的程序。引发异常时,使用 GBD 命令调查调用堆栈和堆栈帧。这是你任务的重点,所以我不会给你更多的提示。

如果你很聪明,你可以通过查看它来看到给定来源中的错误。

当 GDB 不知道任何符号时,您需要使用选项-g进行编译以获得调试器支持。

编辑

现在在Windows系统上,这是我的日志(请原谅着色,我没有找到纯文本的语言选择器(:

D:tmpStackOverflowso_027 > type crash1.c
#include <stdio.h>
main()
{
int x,y;
y=54389;
for (x=10; x>=0; x--)
y=y/x;
printf("%dn",y);
}
D:tmpStackOverflowso_027 > gcc crash1.c -g -o crash1.out
crash1.c:2:1: warning: return type defaults to 'int' [-Wimplicit-int]
main()
^~~~
D:tmpStackOverflowso_027 > dir
[...cut...]
04.09.2019  08:33               144 crash1.c
04.09.2019  08:40            54.716 crash1.out
D:tmpStackOverflowso_027 > gdb crash1.out
GNU gdb (GDB) 8.1
[...cut...]
This GDB was configured as "x86_64-w64-mingw32".
[...cut...]
Reading symbols from crash1.out...done.
(gdb) run
Starting program: D:tmpStackOverflowso_027crash1.out
[New Thread 4520.0x28b8]
[New Thread 4520.0x33f0]
Thread 1 received signal SIGFPE, Arithmetic exception.
0x0000000000401571 in main () at crash1.c:7
7               y=y/x;
(gdb) backtrace
#0  0x0000000000401571 in main () at crash1.c:7
(gdb) help stack
Examining the stack.
The stack is made up of stack frames.  Gdb assigns numbers to stack frames
counting from zero for the innermost (currently executing) frame.
At any time gdb identifies one frame as the "selected" frame.
Variable lookups are done with respect to the selected frame.
When the program being debugged stops, gdb selects the innermost frame.
The commands below can be used to select other frames by number or address.
List of commands:
backtrace -- Print backtrace of all stack frames
bt -- Print backtrace of all stack frames
down -- Select and print stack frame called by this one
frame -- Select and print a stack frame
return -- Make selected stack frame return to its caller
select-frame -- Select a stack frame without printing anything
up -- Select and print stack frame that called this one
Type "help" followed by command name for full documentation.
Type "apropos word" to search for commands related to "word".
Command name abbreviations are allowed if unambiguous.
(gdb) next
Thread 1 received signal SIGFPE, Arithmetic exception.
0x0000000000401571 in main () at crash1.c:7
7               y=y/x;
(gdb) next
[Inferior 1 (process 4520) exited with code 030000000224]
(gdb) next
The program is not being run.
(gdb) quit
D:tmpStackOverflowso_027 >

好吧,它直接标记了错误的源行。当您使用 Raspi 时,这与您的环境不同。但是,它显示了一些要尝试的 GDB 命令。

关于您的视频:

  • 很明显,在raise()内部,您无法访问x.这就是为什么GDB对此呻吟的原因。
  • 如果引发异常,程序通常即将退出。因此,挺身而出是没有价值的。
  • 相反,如我的日志所示,使用 GDB 命令来调查堆栈帧。我认为这是您将要学习的问题。

顺便说一句,你知道你应该能够复制屏幕内容吗?这将使我们的阅读变得更加容易。

从实际的角度来看,另一个答案是正确的,但如果你确实想要libc源代码:

apt-get source 是获取 libc 源代码的正确方法,但是是的,您确实需要在/etc/apt/sources.list 中配置源代码存储库。

如果您使用的是 Ubuntu,请参阅 https://help.ubuntu.com/community/Repositories/CommandLine 中的 deb-src 行

对于 debian,请参阅 https://wiki.debian.org/SourcesList#Example_sources.list

然后 apt-get 源应该可以工作。请记住使用"目录"命令告诉GDB这些源的位置。

最新更新