[vm] On Android set abort message before aborting
Android L and newer (API level 21) provides a way to
specify abort message which will be included into
crash report created by debuggerd.
Make sure our DynamicAssertionHelper uses this functionality
if available.
TEST=tested manually
Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-android-release-arm64-try,vm-kernel-mac-release-x64-try
Change-Id: If25cd168d43677e0a0fe9b63e21a017415686ab7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/191140
Auto-Submit: Vyacheslav Egorov <vegorov@google.com>
Commit-Queue: Vyacheslav Egorov <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
diff --git a/runtime/platform/assert.cc b/runtime/platform/assert.cc
index b1dbd65..85e4ea2 100644
--- a/runtime/platform/assert.cc
+++ b/runtime/platform/assert.cc
@@ -8,11 +8,17 @@
#include "platform/globals.h"
#include "platform/syslog.h"
+#if defined(HOST_OS_ANDROID)
+extern "C" __attribute__((weak)) void android_set_abort_message(const char*);
+#endif // defined(HOST_OS_ANDROID)
+
namespace dart {
bool Expect::failed_ = false;
-void DynamicAssertionHelper::Print(const char* format, va_list arguments) {
+void DynamicAssertionHelper::Print(const char* format,
+ va_list arguments,
+ bool will_abort /* = false */) {
// Take only the last 1KB of the file name if it is longer.
const intptr_t file_len = strlen(file_);
const intptr_t file_offset = (file_len > (1 * KB)) ? file_len - (1 * KB) : 0;
@@ -30,12 +36,17 @@
// Print the buffer on stderr and/or syslog.
Syslog::PrintErr("%s\n", buffer);
+#if defined(HOST_OS_ANDROID)
+ if (will_abort && (&android_set_abort_message != nullptr)) {
+ android_set_abort_message(buffer);
+ }
+#endif // defined(HOST_OS_ANDROID)
}
void Assert::Fail(const char* format, ...) {
va_list arguments;
va_start(arguments, format);
- Print(format, arguments);
+ Print(format, arguments, /*will_abort=*/true);
va_end(arguments);
// Abort right away.
diff --git a/runtime/platform/assert.h b/runtime/platform/assert.h
index 64351b6..c4155d0 100644
--- a/runtime/platform/assert.h
+++ b/runtime/platform/assert.h
@@ -30,7 +30,7 @@
: file_(file), line_(line) {}
protected:
- void Print(const char* format, va_list arguments);
+ void Print(const char* format, va_list arguments, bool will_abort = false);
const char* const file_;
const int line_;