__cyg_profile_func_enter print function nam

本文深入探讨了一段使用C语言编写的程序,通过详细解析`__cyg_profile_func_enter`和`__cyg_profile_func_exit`函数的作用,展示了如何进行函数调用的跟踪和调试。文章介绍了程序中涉及的变量作用、函数嵌套调用以及使用`backtrace`和`backtrace_symbols`获取调用堆栈的方法,旨在帮助开发者更高效地理解和维护复杂的C语言程序。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include <stdio.h>
#import <execinfo.h>

void __cyg_profile_func_enter (void *, void *) __attribute__((no_instrument_function));
void __cyg_profile_func_exit (void *, void *) __attribute__((no_instrument_function));

int depth = -1;

void __cyg_profile_func_enter (void *func,  void *caller)
{
 int n;


 depth++;
 for (n = 0; n < depth; n++)
   printf (" ");
 printf ("-> %p\n", func);
 
 void *bt[2];
         int bt_size;
         char **bt_syms;

         bt_size = backtrace(bt, 2);
         bt_syms = backtrace_symbols(bt, bt_size);
         if(bt_size>=2){
                 printf("a%s\n",bt_syms[1]);
         }
    if(bt_syms) free((void*)bt_syms);
}


void __cyg_profile_func_exit (void *func, void *caller)
{
 int n;


 for (n = 0; n < depth; n++)
   printf (" ");
 printf ("<- %p\n", func);
 depth--;
}


void bar(void)
{
}


void foo (void)
{
 int x;
 for (x = 0; x < 4; x++)
   bar ();
}


int main (int argc, char *argv[])
{
   foo ();
   bar ();
 return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值