手臂中尿骨的后部痕迹 [英] back trace for ulibc in arm

查看:82
本文介绍了手臂中尿骨的后部痕迹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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



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



任何帮助将不胜感激。



非常感谢。



-Keshav

解决方案

我们在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( -----开始堆栈跟踪----- \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,
去污,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( -----结束堆栈跟踪----- \n);


}

  int __arm_backtrace(int ** arr,int maxsize)

{

int cnt = 0;
void * fp = __builtin_frame_address(0);
结构布局* lp =(结构布局*)((char *)fp-12);
而(cnt< maxsize)
{

arr [cnt ++] =(int *)lp-> return_address;
如果(!lp-> next)
{
休息;
}
lp = lp-> next-1;
}
return cnt;
}


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

解决方案

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;
}

这篇关于手臂中尿骨的后部痕迹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆