xo-arena: build: can't assume elfutils on osx

This commit is contained in:
Roland Conybeare 2026-04-19 20:47:40 -04:00
commit c206dd2e16
3 changed files with 22 additions and 3 deletions

View file

@ -25,7 +25,11 @@ xo_install_include_tree3(include/xo/arena)
xo_dependency(${SELF_LIB} xo_reflectutil)
xo_dependency(${SELF_LIB} indentlog)
if (NOT APPLE)
xo_external_pkgconfig_dependency(${SELF_LIB} LIBUNWIND libunwind-generic)
xo_external_pkgconfig_dependency(${SELF_LIB} LIBDW libdw)
else()
endif()
# end src/CMakeLists.txt

View file

@ -12,6 +12,7 @@
#include <xo/indentlog/scope.hpp>
#include <xo/indentlog/print/tag.hpp>
#include <cassert>
#include <exception>
#include <sys/mman.h> // for ::munmap()
#include <unistd.h> // for ::getpagesize()
#include <string.h> // for ::memset()
@ -587,7 +588,7 @@ namespace xo {
fprintf(stderr, "DArena::expand: mprotect failed (system oom?)");
print_backtrace_dwarf(false /*!demangle_flag*/);
return false;
}

View file

@ -4,13 +4,16 @@
**/
#include "backtrace.hpp"
#include <iostream>
#include <array>
#include <cstdio>
#include <cstdlib>
#include <libunwind.h>
#include <cxxabi.h>
#include <unistd.h>
#include <elfutils/libdwfl.h>
#ifndef __APPLE__
# include <elfutils/libdwfl.h>
#endif
namespace xo {
void
@ -67,6 +70,7 @@ namespace xo {
}
}
namespace {
#ifndef __APPLE__
// libdwfl requires callbacks for find_elf and find_debuginfo.
// The offline defaults work for the current process.
//
@ -76,10 +80,18 @@ namespace xo {
.section_address = nullptr,
.debuginfo_path = nullptr,
};
#endif
}
void
print_backtrace_dwarf(bool demangle_flag) {
print_backtrace_dwarf(bool demangle_flag)
{
#ifdef __APPLE__
(void)demangle_flag;
std::cerr << "backtrace with dwarf symbols not supported on osx" << std::endl;
#else
unw_cursor_t cursor;
unw_context_t cx;
@ -152,6 +164,8 @@ namespace xo {
if (dwfl)
dwfl_end(dwfl);
#endif
}
} /*namespace xo*/