Major reliability improvement for logging stack traces#287
Major reliability improvement for logging stack traces#287
Conversation
1. set_unexpected is supposed to be removed in c++17 2. Need to unwind through the signal trampoline 3. iOS will not allow signal handling in app store, probably
No std, no snprintf, almost nothing is allowed inside a signal handler
It now gets caught in the abort handler
| "_C_A_T_C_H____T_E_S_T_", | ||
| "Catch::TestInvokerAsFunction::invoke() const", |
There was a problem hiding this comment.
Have you checked that these names are still valid after we upgraded Catch2?
There was a problem hiding this comment.
I have not. Is there a method you used to determine them in the first place?
| } | ||
| } | ||
|
|
||
| char* unmangle(const char* function) { |
There was a problem hiding this comment.
Likewise, could this be a private static member of Backtrace?
There was a problem hiding this comment.
This was originally not even before my PR. Making it a private static member requires bringing the other Unmangle methods along with it. Is that the outcome you want?
| [[nodiscard]] static std::shared_ptr<Backtrace> capture(void* from, unsigned maxFrames = 50, | ||
| void* context = nullptr); | ||
|
|
||
| static int raw_capture(void** buffer, int max, void* context = nullptr); |
There was a problem hiding this comment.
Likewise, is there a need to make this public?
There was a problem hiding this comment.
It needs to be callable from the signal handler, as well as from Backtrace itself.
| /// @param maxFrames Maximum number of frames to capture | ||
| explicit Backtrace(unsigned skipFrames =0, unsigned maxFrames =50); | ||
| /// @param context If non-null, a platform-specific context to capture from | ||
| /// @param from If non-null, the address to start from instead of the current frame |
There was a problem hiding this comment.
Where is "from" in the signature?
As it is, it can be linked to Core without changes in Core, right?
How platform passes the context to Backtrace?
There was a problem hiding this comment.
The "platform" doesn't pass anything, it's all handled via the various Backtrace capture classes I've written. I think "from" here is a dangling comment from something I removed.
This took many days of effort and so it's involved a lot with various stack unwinding and address retrieval mechanisms so I'll try to provide a high level summary here. Firstly to avoid a giant spaghetti of ifdef I broke out the implementation across several files that only get compiled on certain platforms:
backtrace_symbolsanddladdrsince the implementation on Apple is much more enhanced than the glibc linux counterpart (Most likely the compiler is more friendly about it when it emits machine code).StackWalk64API.Note that since we cannot use ostreams in signal handlers, I created a new crash log in the logs directory that a crash will be written to upon a signal. The existing logs are all buried inside of ofstream objects.