Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2927369
  • 博文数量: 401
  • 博客积分: 12926
  • 博客等级: 上将
  • 技术积分: 4588
  • 用 户 组: 普通用户
  • 注册时间: 2009-02-22 14:51
文章分类

全部博文(401)

文章存档

2015年(16)

2014年(4)

2013年(12)

2012年(82)

2011年(98)

2010年(112)

2009年(77)

分类: C/C++

2014-08-07 16:07:31

#define _RET_IP_        (unsigned long)__builtin_return_address(0)
#define _THIS_IP_  ({ __label__ __here; __here: (unsigned long)&&__here; })


可以通过它来打印调用栈, addr参数传入_RET_IP

static void print_track(const char *s, struct track *t)
{
    if (!t->addr)
        return;


    printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
        s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
#ifdef CONFIG_STACKTRACE
    {    
        int i;
        for (i = 0; i < TRACK_ADDRS_COUNT; i++) 
            if (t->addrs[i])
                printk(KERN_ERR "\t%pS\n", (void *)t->addrs[i]);
            else 
                break;
    }    
#endif
}


Following copy from http://blog.chinaunix.net/uid-11455994-id-176451.html
— Built-in Function: void * __builtin_return_address (unsigned int level)

This function returns the return address of the current function, or of one of its callers. The level argument is number of frames to scan up the call stack. A value of 0 yields the return address of the current function, a value of 1 yields the return address of the caller of the current function, and so forth. When inlining the expected behavior is that the function will return the address of the function that will be returned to. To work around this behavior use the noinline function attribute. 


Refer to:

http://blog.chinaunix.net/u/12592/showart_1679862.html


阅读(3851) | 评论(0) | 转发(0) |
0

上一篇:git 冲突格式

下一篇:用vim画文本流程图

给主人留下些什么吧!~~