什么是段错误 rip/r​​sp 编号以及如何使用它们

发布于 2024-08-05 04:32:55 字数 248 浏览 2 评论 0原文

当我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

哥,最终变帅啦 2024-08-12 04:32:55

那么 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

酒绊 2024-08-12 04:32:55

我也得到了这个错误。当我看到:

probe.out[28503]: segfault at 0000000000000180 rip 00000000004450c0 rsp 00007fff4d508178 error 4

probe.out是一个使用libavformat(ffmpeg)的应用程序。我把它拆开了。

objdump -d probe.out

rip 是指令运行的地方:

00000000004450c0 <ff_rtp_queued_packet_time>:
  4450c0:       48 8b 97 80 01 00 00    mov    0x180(%rdi),%rdx
  44d25d:       e8 5e 7e ff ff          callq  4450c0 <ff_rtp_queued_packet_time>

最后,我发现应用程序在函数 ff_rtp_queued_pa​​cket_time 中崩溃了。

附言。有时地址不完全匹配,但几乎就在那里。

I got the error, too. When I saw:

probe.out[28503]: segfault at 0000000000000180 rip 00000000004450c0 rsp 00007fff4d508178 error 4

probe.out is an app which using libavformat (ffmpeg). I disassembled it.

objdump -d probe.out

The rip is where the instruction will run:

00000000004450c0 <ff_rtp_queued_packet_time>:
  4450c0:       48 8b 97 80 01 00 00    mov    0x180(%rdi),%rdx
  44d25d:       e8 5e 7e ff ff          callq  4450c0 <ff_rtp_queued_packet_time>

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文