ART: Reprint long messages on abort
Add an abort message parameter to Runtime::Abort. In case the message
is multiline (and will thus not be completely preserved in the
Android abort reason), reprint the message after all threads have
been dumped.
Bug: 31893081
Test: m test-art-host
Change-Id: I65bc77691fec79f7c868a90d6132805fcc91e473
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index df0dca0..f6a854c 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -422,7 +422,7 @@
}
};
-void Runtime::Abort() {
+void Runtime::Abort(const char* msg) {
gAborting++; // set before taking any locks
// Ensure that we don't have multiple threads trying to abort at once,
@@ -437,6 +437,12 @@
AbortState state;
LOG(FATAL_WITHOUT_ABORT) << Dumpable<AbortState>(state);
+ // Sometimes we dump long messages, and the Android abort message only retains the first line.
+ // In those cases, just log the message again, to avoid logcat limits.
+ if (msg != nullptr && strchr(msg, '\n') != nullptr) {
+ LOG(FATAL_WITHOUT_ABORT) << msg;
+ }
+
// Call the abort hook if we have one.
if (Runtime::Current() != nullptr && Runtime::Current()->abort_ != nullptr) {
LOG(FATAL_WITHOUT_ABORT) << "Calling abort hook...";