嵌入式arm开发C语言调用栈回溯实战

本文介绍了在嵌入式ARM开发中如何进行C语言调用栈的回溯实战,包括参考StackOverflow上的方法,通过backtrace获取函数调用栈,以及利用ucontext_t结构来定位segment错误时的指令地址,旨在深化对函数栈帧回溯的理解。
摘要由CSDN通过智能技术生成

嵌入式arm开发C语言调用栈回溯实战

参考: https://stackoverflow.com/questions/77005/how-to-automatically-generate-a-stacktrace-when-my-program-crashes

  • 代码

    #define _GNU_SOURCE
    #endif
    #ifndef __USE_GNU
    #define __USE_GNU
    #endif
    
    #include <execinfo.h>
    #include <signal.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <ucontext.h>
    #include <unistd.h>
    
    /* This structure mirrors the one found in /usr/include/asm/ucontext.h (arm: arm-linux-gnueabihf/libc/usr/include/asm-generic/ucontext.h) */
    typedef struct _sig_ucontext {
         
      unsigned long     uc_flags;
      struct ucontext   *uc_link;
      stack_t           uc_stack;
      struct sigcontext uc_mcontext;
      sigset_t          uc_sigmask;
    } sig_ucontext_t;
    
    void crit_err_hdlr(int sig_num, siginfo_t * info, void * ucontext)
    {
         
      void *             array[50];
      void *             caller_address;
      char **            messages;
      int                size, i;
      sig_ucontext_t *   uc;
    
      uc = (sig_ucontext_t *)ucontext;
    
      /* Get the address at the time the signal was raised */
    #if defined(__i386__) 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值