[libcxx-commits] [PATCH] D130708: [libc++] Properly log crashes with the assertion handler on older Androids

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu Jul 28 07:26:57 PDT 2022


ldionne created this revision.
ldionne added a reviewer: thakis.
Herald added a subscriber: danielkiss.
Herald added a project: All.
ldionne requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

This reintroduces the same workaround we have in libc++abi for older
Androids based on https://reviews.llvm.org/D130507#inline-1255914.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130708

Files:
  libcxx/src/assert.cpp


Index: libcxx/src/assert.cpp
===================================================================
--- libcxx/src/assert.cpp
+++ 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 @@
   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);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130708.448337.patch
Type: text/x-patch
Size: 1290 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220728/792ea640/attachment.bin>


More information about the libcxx-commits mailing list