bombela / backward-cpp

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

Compilation fails on macOS #200

Closed Philanatidae closed 3 years ago

Philanatidae commented 3 years ago

When attempting to add Backward to my C++ project on macOS, compilation fails with this error:

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);
                                          ~~~~~~~~~~~~~~~~~ ^

I'm able to reproduce this with a simple "Hello World" project. I'm unsure if this is caused by compiling on Big Sur or an issue compiling for the M1 chip (I'm running a 2020 Mac mini). I haven't dived too deep into this but wanted to report an issue to see if anybody has run into the same problem or knows of a solution. I pulled the latest from master.

Philanatidae commented 3 years ago

It appears this is an issue when building for arm64 for M1 chips. In backward.hpp, with the population of the error address (if-else chain beginning on line 4153), __aarch64__ is defined since an ARM chip is being compiled. However, the error address is not uctx->uc_mcontext.pc for macOS. It is instead uctx->uc_mcontext->__ss.__pc. Adding a conditional for __APPLE__ and using uctx->uc_mcontext->__ss.__pc fixes the issue.

I've only tested compiling for Apple Silicon currently, I'll verify that this works in a Universal 2 binary and then I'll make a pull request.

bombela commented 3 years ago

Thank you! A new architecture, this is exciting :)

On Sat, 2 Jan 2021, 18:27 Phil, notifications@github.com wrote:

It appears this is an issue when building for arm64 for M1 chips. In backward.hpp, with the population of the error address (if-else chain beginning on line 4153), aarch64 https://github.com/bombela/backward-cpp/blob/27a89004a86fe2a665f041c198c7fbab7489e278/backward.hpp#L4159 is defined since an ARM chip is being compiled. However, the error address is not uctx->uc_mcontext.pc for macOS. It is instead uctx->uc_mcontext->ss.pc. Adding a conditional for APPLE and using uctx->uc_mcontext->ss.pc fixes the issue.

I've only tested compiling for Apple Silicon currently, I'll verify that this works in a Universal 2 binary and then I'll make a pull request.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/bombela/backward-cpp/issues/200#issuecomment-753557907, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABUZDGWDPWPTOMNVOOJCRLSX7IZRANCNFSM4VROVSAA .