Arm 中 ulibc 的回溯

发布于 2024-09-30 10:53:17 字数 479 浏览 1 评论 0原文

我想知道是否有任何移植可用于 arm 中 uclibc 的反向跟踪实现,我可以在信号处理程序中使用它来调试分段错误。

我确实在这里遇到了一个有用的代码,并尝试在我的内部使用它信号处理程序,但它在第一次检查时失败并从那里返回。

我还尝试了一个递归回溯函数,它简单地使用 (current_frame_p)-3) 递归,直到它为 NULL 并打印 (current_frame_p)-1)。这似乎也给我带来了问题。我得到的只是处理程序的地址和一些垃圾大地址(我假设它可能是信号地址)。但我不会超出这个范围。我希望我的足迹能够超越这个范围。

崩溃的代码是专门为调试而编写的,以取消引用和无效地址。

任何帮助将不胜感激。

提前非常感谢。

-克沙夫

I wanted to know if any porting is available for back trace implementation for uclibc in arm that I can use in my signal handler to debug segmentation faults.

I did come across a useful code here and tried using it inside my signal handler but it fails at the first check and returns from there.

I also tried a recurcive backtrace function which simply recursed using (current_frame_p)-3) till it was NULL and printed (current_frame_p)-1). This too seems to give me issues. All I get is the address of the handler and some garbage big address (I assume it might be the signal address). But I don't go beyond that. I want my trace to go beyond that.

The code that crashes is purposefully written for debug to dereference and invalid address.

Any help will be much appreciated.

Many many thanks in advance.

-Keshav

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

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

发布评论

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

评论(2

李白 2024-10-07 10:53:17

我们在 Arm 设备上使用以下代码(但是 glibc)。
我几年前找到了这段代码(不记得具体在哪里)。
它工作得很好,没有任何问题。

void __printBacktrace(int skipCount,bool segv=false)
{

int * func_addresses[BACKTRACE_MAXDEPTH];
char demangle_output[1000];
int nfuncs = __arm_backtrace(func_addresses, BACKTRACE_MAXDEPTH );
printf("-----   Start Stack Trace   -----\n");
for (int i = skipCount; i < nfuncs; ++i)
{
    Dl_info info;
    if (dladdr(func_addresses[i], &info))
    {
        int dStat;
        size_t dLength = 1000;
        char * demangled = abi::__cxa_demangle(info.dli_sname,
                demangle_output, &dLength, &dStat);
        if (demangled && !dStat)
        printf(
                "return addr: %p: object:%s %p symbol:%s [%p+0x%x]\n",
                func_addresses[i], info.dli_fname, info.dli_fbase,
                demangled, info.dli_saddr, (int) func_addresses[i]
                - (int) info.dli_saddr);
        else
        printf(
                "return addr: %p: object:%s %p symbol:%s [%p+0x%x]\n",
                func_addresses[i], info.dli_fname, info.dli_fbase,
                info.dli_sname, info.dli_saddr, (int) func_addresses[i]
                - (int) info.dli_saddr);
    } else
    fprintf(fCrash, "return addr: %p\n", func_addresses[i]);
}
printf("-----   End Stack Trace -----\n");


}

int __arm_backtrace(int **arr, int maxsize)

{

    int cnt = 0;
void *fp = __builtin_frame_address(0);
struct layout *lp = (struct layout *) ((char*) fp - 12);
while (cnt < maxsize)
{

    arr[cnt++] = (int *) lp->return_address;
    if (!lp->next)
    {
        break;
    }
    lp = lp->next - 1;
}
return cnt;
}

We are using the following code on an Arm device (glibc however).
I have found this code couple of years ago (van't remember where exactly).
It's working just fine without any problems.

void __printBacktrace(int skipCount,bool segv=false)
{

int * func_addresses[BACKTRACE_MAXDEPTH];
char demangle_output[1000];
int nfuncs = __arm_backtrace(func_addresses, BACKTRACE_MAXDEPTH );
printf("-----   Start Stack Trace   -----\n");
for (int i = skipCount; i < nfuncs; ++i)
{
    Dl_info info;
    if (dladdr(func_addresses[i], &info))
    {
        int dStat;
        size_t dLength = 1000;
        char * demangled = abi::__cxa_demangle(info.dli_sname,
                demangle_output, &dLength, &dStat);
        if (demangled && !dStat)
        printf(
                "return addr: %p: object:%s %p symbol:%s [%p+0x%x]\n",
                func_addresses[i], info.dli_fname, info.dli_fbase,
                demangled, info.dli_saddr, (int) func_addresses[i]
                - (int) info.dli_saddr);
        else
        printf(
                "return addr: %p: object:%s %p symbol:%s [%p+0x%x]\n",
                func_addresses[i], info.dli_fname, info.dli_fbase,
                info.dli_sname, info.dli_saddr, (int) func_addresses[i]
                - (int) info.dli_saddr);
    } else
    fprintf(fCrash, "return addr: %p\n", func_addresses[i]);
}
printf("-----   End Stack Trace -----\n");


}

and

int __arm_backtrace(int **arr, int maxsize)

{

    int cnt = 0;
void *fp = __builtin_frame_address(0);
struct layout *lp = (struct layout *) ((char*) fp - 12);
while (cnt < maxsize)
{

    arr[cnt++] = (int *) lp->return_address;
    if (!lp->next)
    {
        break;
    }
    lp = lp->next - 1;
}
return cnt;
}
傲鸠 2024-10-07 10:53:17

我知道问题是关于 uclibc 的,但我现在已经找到了如何使用 glibc 进行回溯,所以我想我会说。使用“gcc -funwind-tables -rdynamic”。 unwind-tables 选项使 libc:backtrace() 工作,而动态选项使 libc:backtrace_symbols() 工作。

I know the question was about uclibc, but I've found out how to get backtrace working with glibc now so I thought I'd say. Use "gcc -funwind-tables -rdynamic". The unwind-tables option makes libc:backtrace() work and the dynamic option makes libc:backtrace_symbols() work.

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