bombela / backward-cpp

A beautiful stack trace pretty printer for C++
MIT License
3.73k stars 471 forks source link

Add support for Apple Silicon #201

Closed Philanatidae closed 3 years ago

Philanatidae commented 3 years ago

Fixes #200.

When compiling on Apple Silicon at commit 27a8900, the following build error is produced:

In file included from ../backward-cpp/backward.cpp:36:
../backward-cpp/backward.hpp:4160:60: error: member reference type 'struct __darwin_mcontext64 *' is a pointer; did you mean to use '->'?
    error_addr = reinterpret_cast<void *>(uctx->uc_mcontext.pc);
                                          ~~~~~~~~~~~~~~~~~^
                                                           ->
../backward-cpp/backward.hpp:4160:61: error: no member named 'pc' in '__darwin_mcontext64'
    error_addr = reinterpret_cast<void *>(uctx->uc_mcontext.pc);
                                          ~~~~~~~~~~~~~~~~~ ^

This is caused by __aarch64__ being defined on Apple Silicon, however is incorrect for assigning the error address.

A conditional to check for __APPLE__ was added to the __aarch64__ #ifdef case with the appropriate error address cast.

All tests pass when compiling for ARM64 and Universal 2, ran on an M1 Mac (both ARM64 and Universal 2 binaries) and an Intel Mac.

eboasson commented 3 years ago

Works for me for doing native builds in ROS 2, and this one is a bit cleaner than my quick fix at https://github.com/osrf/osrf_testing_tools_cpp/pull/62

Any chance of it getting merged quickly so we can merge it into the ROS 2 one?

bombela commented 3 years ago

Thanks!