ART: Pass ucontext to Backtrace in Stack Dump
In case of an unexpected signal on the host we dump the thread stack
ourselves. We have to pass the context given to the signal handler,
as the signal handler is run on an alternate stack. Otherwise
libbacktrace can't dump the actual faulty part.
Bug: 18933933
Change-Id: Id2710d2fd44b7c3b3335973a9288979a5793638b
diff --git a/runtime/runtime_linux.cc b/runtime/runtime_linux.cc
index 1de035c..a5a0204 100644
--- a/runtime/runtime_linux.cc
+++ b/runtime/runtime_linux.cc
@@ -35,9 +35,16 @@
static constexpr bool kDumpHeapObjectOnSigsevg = false;
struct Backtrace {
+ public:
+ explicit Backtrace(void* raw_context) : raw_context_(raw_context) {}
void Dump(std::ostream& os) const {
- DumpNativeStack(os, GetTid(), "\t");
+ DumpNativeStack(os, GetTid(), "\t", nullptr, raw_context_);
}
+ private:
+ // Stores the context of the signal that was unexpected and will terminate the runtime. The
+ // DumpNativeStack code will take care of casting it to the expected type. This is required
+ // as our signal handler runs on an alternate stack.
+ void* raw_context_;
};
struct OsInfo {
@@ -298,7 +305,7 @@
pid_t tid = GetTid();
std::string thread_name(GetThreadName(tid));
UContext thread_context(raw_context);
- Backtrace thread_backtrace;
+ Backtrace thread_backtrace(raw_context);
LOG(INTERNAL_FATAL) << "*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***\n"
<< StringPrintf("Fatal signal %d (%s), code %d (%s)",