Skip to content

Instantly share code, notes, and snippets.

@funny-falcon
Created August 10, 2022 10:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save funny-falcon/a83831fc09b0cbcd48938eb76b756adf to your computer and use it in GitHub Desktop.
Save funny-falcon/a83831fc09b0cbcd48938eb76b756adf to your computer and use it in GitHub Desktop.
cmake_minimum_required(VERSION 3.16)
project(test_backtrace VERSION 0.1 LANGUAGES C)
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_EXTENSIONS true)
find_library(LIBBACKTRACE backtrace)
add_executable(test_exe test_exe.c)
target_link_libraries(test_exe PUBLIC backtrace)
#include <stdlib.h>
#include <backtrace.h>
static int
local_backtrace_callback(void *data, uintptr_t pc,
const char* filename, int lineno,
const char* function)
{
return 0;
}
static void
local_try_backtrace(void) {
static struct backtrace_state * state = NULL;
if (state == NULL)
state = backtrace_create_state(NULL, 0, NULL, NULL);
backtrace_full(state, 0, local_backtrace_callback, NULL, NULL);
}
int main(void) {
local_try_backtrace();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment