mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-09 23:34:20 +00:00
Merge 366fa5fed0 into 0e43b31e50
This commit is contained in:
commit
147ead70c5
2 changed files with 61 additions and 1 deletions
|
|
@ -121,6 +121,9 @@
|
||||||
#if JUCE_ANDROID
|
#if JUCE_ANDROID
|
||||||
#include <ifaddrs.h>
|
#include <ifaddrs.h>
|
||||||
#include <android/log.h>
|
#include <android/log.h>
|
||||||
|
#include <unwind.h>
|
||||||
|
#include <dlfcn.h>
|
||||||
|
#include <cxxabi.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#undef check
|
#undef check
|
||||||
|
|
|
||||||
|
|
@ -190,7 +190,7 @@ String SystemStats::getStackBacktrace()
|
||||||
{
|
{
|
||||||
String result;
|
String result;
|
||||||
|
|
||||||
#if JUCE_ANDROID || JUCE_WASM
|
#if JUCE_WASM
|
||||||
jassertfalse; // sorry, not implemented yet!
|
jassertfalse; // sorry, not implemented yet!
|
||||||
|
|
||||||
#elif JUCE_WINDOWS
|
#elif JUCE_WINDOWS
|
||||||
|
|
@ -224,6 +224,63 @@ String SystemStats::getStackBacktrace()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#elif JUCE_ANDROID
|
||||||
|
|
||||||
|
struct AndroidBacktraceState
|
||||||
|
{
|
||||||
|
void** current;
|
||||||
|
void** end;
|
||||||
|
};
|
||||||
|
|
||||||
|
auto androidUnwindCallback = [] (_Unwind_Context* context, void* arg) -> _Unwind_Reason_Code
|
||||||
|
{
|
||||||
|
auto* state = (AndroidBacktraceState*) arg;
|
||||||
|
if (auto pc = _Unwind_GetIP(context))
|
||||||
|
{
|
||||||
|
if (state->current == state->end)
|
||||||
|
return _URC_END_OF_STACK;
|
||||||
|
|
||||||
|
*state->current++ = reinterpret_cast<void*> (pc);
|
||||||
|
}
|
||||||
|
|
||||||
|
return _URC_NO_REASON;
|
||||||
|
};
|
||||||
|
|
||||||
|
const int max = 100;
|
||||||
|
void* buffer[max];
|
||||||
|
|
||||||
|
AndroidBacktraceState state;
|
||||||
|
state.current = buffer;
|
||||||
|
state.end = buffer + max;
|
||||||
|
_Unwind_Backtrace (androidUnwindCallback, &state);
|
||||||
|
|
||||||
|
const auto count = (int) (state.current - buffer);
|
||||||
|
|
||||||
|
for (int i = 0; i < count; ++i)
|
||||||
|
{
|
||||||
|
const void* addr = buffer[i];
|
||||||
|
result << i << " " << String::toHexString ((intptr_t) addr);
|
||||||
|
|
||||||
|
Dl_info info;
|
||||||
|
if (dladdr (addr, &info) != 0 && info.dli_sname != nullptr)
|
||||||
|
{
|
||||||
|
const char* symbol = info.dli_sname;
|
||||||
|
|
||||||
|
int status = 0; // NB: '0' means success
|
||||||
|
auto* demangled = abi::__cxa_demangle (symbol, nullptr, nullptr, &status);
|
||||||
|
|
||||||
|
if (demangled != nullptr && status == 0)
|
||||||
|
result << demangled;
|
||||||
|
else
|
||||||
|
result << symbol;
|
||||||
|
|
||||||
|
if (demangled != nullptr)
|
||||||
|
free (demangled);
|
||||||
|
}
|
||||||
|
|
||||||
|
result << newLine;
|
||||||
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
void* stack[128];
|
void* stack[128];
|
||||||
auto frames = backtrace (stack, numElementsInArray (stack));
|
auto frames = backtrace (stack, numElementsInArray (stack));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue