本文介绍了任何可用于 uclibc 的回溯移植?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在 ARM 9 上运行 uclibc linux.问题是 uclibc 不支持回溯.当发生核心转储时,我无法获取调用堆栈.

We are running the uclibc linux on ARM 9. The problem is uclibc doesn't support backtrace. When a core dump happens, I cannot grab the call stack.

有没有人有好的解决方案?

Does anyone have a good solution for that?

例如,现有的 uclibc 回溯移植,或者在发生核心转储时获取调用堆栈的任何好方法 (uclibc+ARM+Linux)?

For example, an existing porting of backtrace for uclibc, or any good method to grab the call stack when a core dump happens (uclibc+ARM+Linux)?

推荐答案

更新:

似乎是一个补丁 的创建是为了在 x86 和 ARM (XScale) 的 uclibc 上支持 backtrace(),它使用了 __libc_stack_end 符号.

It seems that a patch was created to support backtrace() on uclibc for x86 and ARM (XScale) and it makes use of the __libc_stack_end symbol.

原答案:

我参与了一个项目,其中我们使用的 glibc 版本没有为我们的 ARM 处理器提供功能性的 backtrace(),所以我们使用 __libc_stack_end 在 glibc 之外开发了我们自己的 符号.下面是结果代码.也许你可以用它来写一个 uclibc backtrace() 函数.

I worked on a project where the version of glibc we were using did not provide a functional backtrace() for our ARM processor, so we developed our own outside of glibc using the __libc_stack_end symbol. Below is the resulting code. Perhaps you can use it to write a uclibc backtrace() function.

extern void * __libc_stack_end;

struct backtrace_frame_t
{
    void * fp;
    void * sp;
    void * lr;
    void * pc;
};

int backtrace(void ** array, int size)
{
    void * top_frame_p;
    void * current_frame_p;
    struct backtrace_frame_t * frame_p;
    int frame_count;

    top_frame_p = __builtin_frame_address(0);
    current_frame_p = top_frame_p;
    frame_p = (struct backtrace_frame_t*)((void**)(current_frame_p)-3);
    frame_count = 0;

    if (__builtin_return_address(0) != frame_p->lr)
    {
        fprintf(stderr, "backtrace error: __builtin_return_address(0) != frame_p->lr\n");
        return frame_count;
    }

    if (current_frame_p != NULL
        && current_frame_p > (void*)&frame_count
        && current_frame_p < __libc_stack_end)
    {
        while (frame_count < size
               && current_frame_p != NULL
               && current_frame_p > (void*)&frame_count
               && current_frame_p < __libc_stack_end)
        {
            frame_p = (struct backtrace_frame_t*)((void**)(current_frame_p)-3);
            array[frame_count] = frame_p->lr;
            frame_count++;
            current_frame_p = frame_p->fp;
        }
    }

    return frame_count;
}

注意:__libc_stack_end 符号不再在较新版本的 glibc 中导出,我不确定它是否存在或在 uclibc 中存在类似符号.

Note: The __libc_stack_end symbol is no longer exported in more recent versions of glibc and I'm not sure of the existence of it or a similar symbol in uclibc.

这篇关于任何可用于 uclibc 的回溯移植?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-16 17:43