[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] backtrace() on Linux

From: Yakov
Subject: Re: [Tinycc-devel] backtrace() on Linux
Date: Fri, 9 Mar 2018 15:25:51 +0545

I had to write this code to be able to get the stack trace under TinyC:

ifdef __TINYC__ int backtrace(void **buffer, int size) { extern uint64_t *__libc_stack_end; uint64_t **p, *bp, *frame; asm ("mov %%rbp, %0;" : "=r" (bp)); p = (uint64_t**) bp; int i = 0; while (i < size) { frame = p[0]; if (frame < bp || frame > __libc_stack_end) { return i; } buffer[i++] = p[1]; p = (uint64_t**) frame; } return i; } #endif

2018-03-09 15:24 GMT+05:45 Yakov <address@hidden>:

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

void show_bt() {
    int n;
    void *buffer[111];
    char **strings;
    n = backtrace(buffer, 111);
    strings = backtrace_symbols(buffer, n);
    while (strings && n) printf("%s\n", strings[n---1]);

void c() { show_bt(); }
void b() { c(); }
void a() { b(); }
int main() { a(); }

The above code does not work on Tiny. Although works on GCC/Clang for me.

$ tcc -version
tcc version 0.9.26 (x86-64 Linux)

I have tried to no avail: "-bt 100", "-g", "-rdynamic", also tried to link with gcc and ld.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]