From 15d3402bbf8265eb1165694da2e4117eb128f3bc Mon Sep 17 00:00:00 2001 From: Mathieu Chartier Date: Wed, 26 Feb 2014 17:16:38 -0800 Subject: Add custom SIGSEGV handler to help find heap corruption. The new signal handler prints heap diagnostics when you get a SIGSEGV. Added a fault message member in runtime which is modifiable by Runtime::SetFaultMessage. When you get a SIGSEGV it will print out whatever is stored in this string as well as the normal information. This is useful for debugging heap corruption since it lets you see which threads were in which methods when the last GC occured. Added some smarter object dumping logic when the faulting address is in the heap. Bug: 12934910 Change-Id: Ia72be2c39f70ad711cbd746d66fad2b617d5d29f --- runtime/runtime.cc | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'runtime/runtime.cc') diff --git a/runtime/runtime.cc b/runtime/runtime.cc index 1ef15f7..90ba7d3 100644 --- a/runtime/runtime.cc +++ b/runtime/runtime.cc @@ -91,6 +91,8 @@ Runtime::Runtime() resolution_method_(nullptr), imt_conflict_method_(nullptr), default_imt_(nullptr), + fault_message_lock_("Fault message lock"), + fault_message_(""), method_verifiers_lock_("Method verifiers lock"), threads_being_born_(0), shutdown_cond_(new ConditionVariable("Runtime shutdown", *Locks::runtime_shutdown_lock_)), @@ -1598,4 +1600,9 @@ void Runtime::RecordWeakStringRemoval(mirror::String* s, uint32_t hash_code) con DCHECK(IsActiveTransaction()); preinitialization_transaction->RecordWeakStringRemoval(s, hash_code); } + +void Runtime::SetFaultMessage(const std::string& message) { + MutexLock mu(Thread::Current(), fault_message_lock_); + fault_message_ = message; +} } // namespace art -- cgit v1.1