在MIPS Linux中回溯时GDB如何找到函数的符号?

发布于 2024-07-26 09:21:23 字数 117 浏览 3 评论 0原文

我正在尝试实现一个函数来回溯内核中崩溃的用户空间进程。 因为我在内核中工作,所以我没有任何库的奢侈,并且提供的回溯函数不支持 MIPS 架构。 我只是想知道我是否可以模仿 GDB 的做法。 内核版本是2.6.21。

I'm trying to implement a function to backtrace a crashed user space process in kernel. Since, I'm working in Kernel, I don't have the luxury of any libraries and provided backtrace function doesn't support MIPS architecture. I'm just wondering if I can emulate what GDB does.
The version of the kernel is 2.6.21.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

夜深人未静 2024-08-02 09:21:23

我认为你可以参考 oprofile 的实现。

Oprofile 使用帧指针来获取回溯信息,因此它要求用户空间应用程序及其相关库都启用帧指针。(“-fno-omit-frame-pointer”选项)。

另一种方法是,如果用户应用程序包含调试信息,您可能需要检查用户应用程序的 DWARF 信息,即 DWARF 调用帧信息为调试器提供了有关函数如何调用的足够信息,以便调试器可以找到函数的每个参数,找到当前的调用帧,并找到调用信息的调用帧。

如果您想在不支持“帧指针”或任何调试信息的情况下简单地抓取反向跟踪信息,那么您必须检查用户应用程序的 mips 指令,循环遍历子上下文(SP,IP,RP)以获取父上下文(SP,IP,RP) 根据 mips ABI 规范,这有点复杂且耗时,因为您必须反汇编内存中的许多指令,但效果还不错。 例如,对于很多路由,在开头都有一个类似“add sp, sp, -32”的指令,你就会知道父进程的sp是当前的sp加32。

第二种和第三种方法你必须实现它因为你在内核中工作,所以你自己。

I think you can reference the oprofile's implementation.

Oprofile use frame-pointer to get the back trace infomation, so it requires the user space applications and its related libraries all built with frame-pointer enabled.("-fno-omit-frame-pointer" option).

Another way is that if the user applications contains debug infomation, you may need check the user application's DWARF infomation, the DWARF call frame infomation proides the debugger with enough infomation about how a function called, so that it can locate each of the arguments to the function, locate the current call frame, and locate the call frame for the calling infomation.

If you want to simple crawl the back trace infomation without "frame-pointer" supported or any debug infomation, then you have to check the user application's mips instruction, loop through child's context(SP,IP,RP) things to get the parent context(SP,IP,RP) by the mips ABI specification, this is a little complicated and time consuming since you have to disassemble many instruction in the memory, but it works not bad. For example, for many routie, there is an "add sp, sp, -32" like instruction at the begging, and you will know that the parent'sp is current sp plus 32.

The second and third way you have to implement it yourself since you work in kernel.

南城追梦 2024-08-02 09:21:23

核心文件采用 ELF 格式。 这是一项标准,只需谷歌一下即可在许多网站上找到。

然而,这种文件格式并不简单。 很多怪癖和细节。 任何有理智的人都应该使用第三方库。 如果你真的想这样做,请从 libelf 和 readelf 开始。 祝自己好运。

The core file is in ELF format. This is a standard, which is available on many web site just one google away.

HOWEVER, this file format is non-trival. Lots of quirks and bits. Any reasonable person should use an 3rd party library. If you really want to do that, start with libelf and readelf. and wish yourself good luck.

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