Skip to content

Commit

Permalink
Add posix stack traces.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjp41 committed Apr 2, 2020
1 parent e6244f5 commit b5dfc69
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ if(NOT DEFINED SNMALLOC_ONLY_HEADER_LIBRARY)
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /DEBUG")
else()
add_compile_options(-fno-exceptions -fno-rtti -g -ftls-model=initial-exec -fomit-frame-pointer)
# Get better stack traces in CI.
add_link_options(-rdynamic)

if((${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64") OR
(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86") OR
Expand Down
11 changes: 10 additions & 1 deletion src/pal/pal_posix.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

#include "../ds/address.h"
#include "../mem/allocconfig.h"

#include <execinfo.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/mman.h>
#include <unistd.h>

extern "C" int puts(const char* str);

Expand Down Expand Up @@ -41,8 +42,16 @@ namespace snmalloc
*/
static void error(const char* const str) noexcept
{
constexpr int SIZE = 1024;
void *buffer[SIZE];

puts(str);
fflush(stdout);

auto nptrs = backtrace(buffer, SIZE);
backtrace_symbols_fd(buffer, nptrs, STDOUT_FILENO);
fflush(stdout);

abort();
}

Expand Down

0 comments on commit b5dfc69

Please sign in to comment.