kentzhou 发表于 2008-09-22 15:32

通过内嵌汇编怎么取得调用函数的代码的地址

arm中想要读lr寄存器来取得调用函数的代码的地址, 不知道对不对, 代码如下,

      u32 ret = 0;
        __asm__ __volatile__ (
                "mov lr, %0"
                :"=r" (ret)
                :);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printk("<2> %s lr =%x\n", __func__, ret);

这段代码是在module中但是打印出lr是0xc01c7960, 是kernel的地址吧
另外要实现这个功能有别的好办法吗 Thanks.

albcamus 发表于 2008-09-22 21:39

不懂arm。不过在gcc中你可以用这个方式:
printf("caller at %p\n", __builtin_return_address(0));

smartham_whl 发表于 2008-09-23 11:02

__builtin_return_address(0)   每个体系统不同

MIPS下是读取RA寄存器的值

cjaizss 发表于 2008-09-23 11:12

要想检验,那么编译成汇编码再看
页: [1]
查看完整版本: 通过内嵌汇编怎么取得调用函数的代码的地址