什么是段错误 rip/rsp 编号以及如何使用它们
当我的 Linux 应用程序崩溃时,它会在日志中生成一行,如下所示:
segfault at 0000000 rip 00003f32a823 rsp 000123ade323 error 4
这些 rip 和 rsp 地址是什么?我如何使用它们来查明问题?它们是否与 objdump 或 readelf 输出中的内容相对应?如果我的程序将其符号删除(到一个单独的文件,可以使用gdb
),它们有用吗?
When my linux application crashes, it produces a line in the logs something like:
segfault at 0000000 rip 00003f32a823 rsp 000123ade323 error 4
What are those rip and rsp addresses? How do I use them to pinpoint the problem? Do they correspond to something in the objdump
or readelf
outputs? Are they useful if my program gets its symbols stripped out (to a separate file, which can be used using gdb
)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
那么 rip 指针会告诉您导致崩溃的指令。您需要在地图文件中查找它。
在映射文件中,您将有一个函数列表及其起始地址。当您加载应用程序时,它会加载到基地址。 rip 指针 - 基地址为您提供映射文件地址。如果您随后在映射文件中搜索某个函数,该函数的起始地址略低于您的 rip 指针,并且在列表中后跟一个具有更高地址的函数,那么您就找到了崩溃的函数。
从那里您需要尝试找出代码中出了什么问题。它不是很有趣,但至少为您提供了一个起点。
编辑:“段错误”位告诉您,我敢打赌,您已经取消引用了 NULL 指针。 rsp 是当前堆栈指针。唉,它可能没那么有用。通过内存转储,您“可能”能够更准确地确定您在函数中的位置,但要准确地确定您在优化构建中的位置可能非常困难
Well the rip pointer tells you the instruction that caused the crash. You need to look it up in a map file.
In the map file you will have a list of functions and their starting address. When you load the application it is loaded to a base address. The rip pointer - the base address gives you the map file address. If you then search through the map file for a function that starts at an address slightly lower than your rip pointer and is followed, in the list, by a function with a higher address you have located the function that crashed.
From there you need to try and identify what went wrong in your code. Its not much fun but it, at least, gives you a starting point.
Edit: The "segfault at" bit is telling you, i'd wager, that you have dereferenced a NULL pointer. The rsp is the current stack pointer. Alas its probably not all that useful. With a memory dump you "may" be able to figure out more accurately where you'd got to in the function but it can be really hard to work out, exactly, where you are in an optimised build
我也得到了这个错误。当我看到:
probe.out是一个使用libavformat(ffmpeg)的应用程序。我把它拆开了。
rip 是指令运行的地方:
最后,我发现应用程序在函数
ff_rtp_queued_packet_time
中崩溃了。附言。有时地址不完全匹配,但几乎就在那里。
I got the error, too. When I saw:
probe.out is an app which using libavformat (ffmpeg). I disassembled it.
The rip is where the instruction will run:
finally, I found the app crashed in the function
ff_rtp_queued_packet_time
.PS. sometimes the address doesn't exactly match, but it is almost there.