[llvm-branch-commits] [libcxx] 6ba660d - [libc++] Properly log crashes with the assertion handler on older Androids
Tom Stellard via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Aug 2 21:50:13 PDT 2022
Author: Louis Dionne
Date: 2022-08-02T21:48:48-07:00
New Revision: 6ba660d17410d02f5fa71d878ac49e2fdee4169f
URL: https://github.com/llvm/llvm-project/commit/6ba660d17410d02f5fa71d878ac49e2fdee4169f
DIFF: https://github.com/llvm/llvm-project/commit/6ba660d17410d02f5fa71d878ac49e2fdee4169f.diff
LOG: [libc++] Properly log crashes with the assertion handler on older Androids
This reintroduces the same workaround we have in libc++abi for older
Androids based on https://reviews.llvm.org/D130507#inline-1255914.
Differential Revision: https://reviews.llvm.org/D130708
(cherry picked from commit 1422a9689d7907a4561da7b906ec392840d9e635)
Added:
Modified:
libcxx/src/assert.cpp
Removed:
################################################################################
diff --git a/libcxx/src/assert.cpp b/libcxx/src/assert.cpp
index c218645f17712..d6e96f255e353 100644
--- a/libcxx/src/assert.cpp
+++ b/libcxx/src/assert.cpp
@@ -14,9 +14,13 @@
#ifdef __BIONIC__
# include <android/api-level.h>
-# include <syslog.h>
+# if __ANDROID_API__ >= 21
+# include <syslog.h>
extern "C" void android_set_abort_message(const char* msg);
-#endif
+# else
+# include <assert.h>
+# endif // __ANDROID_API__ >= 21
+#endif // __BIONIC__
#if defined(__APPLE__) && __has_include(<CrashReporterClient.h>)
# include <CrashReporterClient.h>
@@ -48,14 +52,22 @@ void __libcpp_assertion_handler(char const* format, ...) {
vasprintf(&buffer, format, list);
CRSetCrashLogMessage(buffer);
#elif defined(__BIONIC__)
- // Show error in tombstone.
vasprintf(&buffer, format, list);
+
+# if __ANDROID_API__ >= 21
+ // Show error in tombstone.
android_set_abort_message(buffer);
// Show error in logcat.
openlog("libc++", 0, 0);
syslog(LOG_CRIT, "%s", buffer);
closelog();
+# else
+ // The good error reporting wasn't available in Android until L. Since we're
+ // about to abort anyway, just call __assert2, which will log _somewhere_
+ // (tombstone and/or logcat) in older releases.
+ __assert2(__FILE__, __LINE__, __func__, buffer);
+# endif // __ANDROID_API__ >= 21
#endif
va_end(list);
More information about the llvm-branch-commits
mailing list