__builtin_frame_address - 尝试访问功能堆栈帧失败

时间:2018-05-25 08:26:33

标签: c++ g++ 32bit-64bit

在64位编译/运行时,(示例)代码崩溃,而在32位Linux(Opensuse)上运行正常。 理想情况下,当没有可用的帧堆栈或达到跟踪深度(此处为10)时,代码应正常退出。

<input onkeypress="myFunc()" onclick="myFunc()"/>

示例输出:  32位opensuse10.2(g ++(GCC)4.9.3)

#include <stdio.h>
#include <inttypes.h>

#define TRACE_DEPTH 10

void fourth()
{
        uintptr_t ebp_val;
        unsigned int i;
        unsigned long *ebp_ptr;
        ebp_val=reinterpret_cast<uintptr_t>(__builtin_frame_address(0));
        for(ebp_ptr=static_cast<unsigned long*>(reinterpret_cast<void*>(ebp_val)),i=0; i<TRACE_DEPTH ; i++)
        {
            printf("\n ebp_ptr=%"PRIxPTR"\n",ebp_ptr);
            if( (ebp_ptr=(unsigned long*)(*(ebp_ptr)))==0 )
            {
                printf("BREAK\n");
                break;
            }
        }
}
void third()
{
    fourth();
}

void second()
{
    third();
}

void first()
{
    second();
}

int main()
{
    first();
    return 0;
}

64位Opensuse 42.2(g ++(GCC)7.3.0)

ebp_ptr=bfca9aa8

ebp_ptr=bfca9ab8

ebp_ptr=bfca9ac8

ebp_ptr=bfca9ad8

ebp_ptr=bfca9ae8
BREAK

0 个答案:

没有答案