Closed Ghost-LZW closed 3 days ago
I found it can work on linux.
Stack trace (most recent call first):
#0 0x00000000004036fe in test() at cmake_test/test.cc:7:27
#1 0x0000000000403722 in main at cmake_test/test.cc:11:7
#2 0x00007f4f0f87909a in __libc_start_main at /libc-start.c:308:16
#3 0x0000000000403629 at /cmake_test/build/my_target
Thank you for opening this and providing suchc a clear minimal reproducible example. I will look into this tomorrow.
Alright, I have reproduced the behavior you describe. I think what's happening here is that _Unwind_Backtrace
relies on unwinding tables on arm and these aren't generated under -fno-exceptions. I've seen this before in #134. A workaround is to use execinfo's unwinding, -DCPPTRACE_UNWIND_WITH_EXECINFO=On
, which doesn't rely on these. I expect libunwind would also work, however, I haven't tested that.
I'll look into how to and whether to provide a better library default here to prevent issues in the future.
libunwind indeed work, I test it with this patch https://github.com/jeremy-rifkin/cpptrace/pull/162
# cmake -S . -B build_libunwind -DCMAKE_BUILD_TYPE=Debug -DCPPTRACE_UNWIND_WITH_LIBUNWIND=ON
Stack trace (most recent call first):
I found that I might not have built it correctly, which means the output is wrong. The stack is generated but does not properly resolve symbols, similar to jeremy-rifkin's result.
Thanks so much for taking the time to figure that out! I gave your patch a try with the repro setup using PATCH_COMMAND
and it built using libunwind however unfortunately I still got an empty trace. If it worked for you and not for me I'd like to understand why. It might be a configuration issue on my end.
Sorry for the synchronization issue. When I use GCC on macOS, the stack is generated correctly (even with unwind). However, with Apple Clang or Clang, the stack remains empty.
Thanks for clarifying, interesting that it doesn't work on clang
Tested a number of configurations:
I didn't test -stdlib=libstdc++ behavior. I will proceed with setting execinfo as the default for clang on apple.
We can build this library without the -no-exceptions flag and then link it with a no-exceptions library. However, I found that without exception support, the stack will be empty. Here is an simple example.
I test it on Apple M2 Pro macbook.