Skip to content
mhahnFr edited this page Oct 14, 2022 · 25 revisions

Here you can find all informations about the CallstackLibrary as well as the documentation of the source code.

The features

This library can translate backtraces obtained by the function backtrace into a human readable format. It will use the debug symbols of the application, in case they are not available, the informations obtained by the dynamic linker are used.
Additionally, the name demangler for C++ names can be enabled.

There is also a wrapper class for easy use with C++ code.

How to use

Example:

#include <callstack.h>

#include <stdio.h>

int main() {
    struct callstack * callstack = callstack_new();
    char ** frames = callstack_toArray(callstack);
    
    printf("The current callstack:\n");
    for (size_t i = 0; i < callstack_getFrameCount(callstack); ++i) {
        printf("In: %s\n", frames[i]);
    }
    
    callstack_delete(callstack);
}

C++ support

Using the wrapper class, the integration into C++ is simplified.
To use it, you need to do nothing - it is automatically included if you compile your code with a C++ compiler.

However, the C++ name demangler needs to be enabled independendly, see below.

The move semantic is also supported by the wrapper!

Example:

#include <callstack.h>

#include <iostream>

int main() {
    cs::callstack callstack;
    char ** frames = callstack_toArray(callstack);
    
    std::cout << "The current callstack:" << std::endl;
    for (size_t i = 0; i < callstack_getFrameCount(callstack); ++i) {
        std::cout << "In: " << frames[i] << std::endl;
    }
}

C++ name demangler

The name demangler is disabled by default. You can enable it in the Makefile: set the variable CXX_DEMANGLER to true.

In order to link statically with the name demangler being enabled, you need to link your program with the C++ standard library of your compiler (this is usually already the case when linking C++ code).

Clone this wiki locally