首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何修复GDB找不到文件:“../sysdeps/unix/sysv/linux/rise.c:50”

如何修复GDB找不到文件:“../sysdeps/unix/sysv/linux/rise.c:50”
EN

Stack Overflow用户
提问于 2019-09-04 00:01:26
回答 2查看 5.3K关注 0票数 0

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

我试过了:

安装libc6,libc6-dbg (说它们已经是最新的)

apt-get source glibc (告诉我:“你必须在你的sources.list中放一些‘源’URI”)

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

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

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

代码语言:javascript
复制
#include <stdio.h>
main()
{
        int x,y;
        y=54389;
        for (x=10; x>=0; x--)
        y=y/x;
        printf("%d\n",y);
}

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

代码语言:javascript
复制
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.

我问他这个问题,他真的没有任何想法来解决这个问题。

EN

回答 2

Stack Overflow用户

发布于 2019-09-04 00:48:57

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

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

如果你很聪明,你可以通过查看给定源代码中的错误。;-)

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

编辑

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

代码语言:javascript
复制
D:\tmp\StackOverflow\so_027 > type crash1.c
#include <stdio.h>
main()
{
        int x,y;
        y=54389;
        for (x=10; x>=0; x--)
        y=y/x;
        printf("%d\n",y);
}

D:\tmp\StackOverflow\so_027 > gcc crash1.c -g -o crash1.out
crash1.c:2:1: warning: return type defaults to 'int' [-Wimplicit-int]
 main()
 ^~~~

D:\tmp\StackOverflow\so_027 > dir
[...cut...]
04.09.2019  08:33               144 crash1.c
04.09.2019  08:40            54.716 crash1.out

D:\tmp\StackOverflow\so_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:\tmp\StackOverflow\so_027\crash1.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:\tmp\StackOverflow\so_027 >

嗯,它直接标记错误的源代码行。这与您的环境不同,因为您使用Raspi。但是,它向您展示了一些可以尝试的GDB命令。

关于你的视频:

  • 很明显,在raise()中你不能访问x。这就是GDB抱怨的原因。
  • 如果出现异常,程序通常会退出。因此,单步执行forward.
  • Instead,没有任何价值,请使用GDB命令调查堆栈帧。我想这就是你将要学习的问题。

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

票数 1
EN

Stack Overflow用户

发布于 2019-09-15 12:53:35

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

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

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

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

那么apt-get源代码应该可以工作。记住使用"directory“命令告诉GDB这些源代码在哪里。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57775190

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档