小编lai*_*dir的帖子

在Raspberry Pi上,backtrace()返回0帧

我正在玩glibc's backtrace(),我似乎无法让它在我的Raspberry Pi上正常工作.一切都没有警告编译,但backtrace()返回0作为存储的帧数.完全相同的代码确实在x86_64(Debian stable)上产生了回溯,backtrace()返回6帧:


/*test.c*/
#include <stdio.h>
#include <execinfo.h>
#include <unistd.h>

void foo(void)
{
    void *stack[10];
    int n = backtrace(stack, 10);
    fprintf(stderr, "Last %d frames:\n", n);
    backtrace_symbols_fd(stack, n, STDERR_FILENO);
}

void bar(void)
{
    foo();
}

void baz(void)
{
    bar();
}

int main(void)
{
    printf("Hello, Backtrace\n");
    baz();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)
#Makefile
CFLAGS=-Wall -Wextra -g
LDFLAGS=-rdynamic
Run Code Online (Sandbox Code Playgroud)

x86_64上的输出(gcc (Debian 4.7.2-5) 4.7.2使用GNU libc6:amd64 2.13-38+deb7u1):

Hello, Backtrace
Last 6 frames:
./test(foo+0x19)[0x4009a5]
./test(bar+0x9)[0x4009e5]
./test(baz+0x9)[0x4009f0]
./test(main+0x13)[0x400a05]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xfd)[0x7f9286ddbead]
./test[0x4008a9]
Run Code Online (Sandbox Code Playgroud)

Raspberry …

c linux glibc raspberry-pi raspbian

5
推荐指数
1
解决办法
1904
查看次数

标签 统计

c ×1

glibc ×1

linux ×1

raspberry-pi ×1

raspbian ×1