Merge changes from topics "crashapi2", "crashapi3" into main am: acafa40d82 am: 1a7a68461f

Original change: https://android-review.googlesource.com/c/platform/system/core/+/2962950

Change-Id: I38b7d0ce388a324d4f2f0e85f7603e76702d3a1a
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/debuggerd/debuggerd_test.cpp b/debuggerd/debuggerd_test.cpp
index a308ffb..f396b1d 100644
--- a/debuggerd/debuggerd_test.cpp
+++ b/debuggerd/debuggerd_test.cpp
@@ -37,6 +37,7 @@
 #include <string>
 #include <thread>
 
+#include <android/crash_detail.h>
 #include <android/dlext.h>
 #include <android/fdsan.h>
 #include <android/set_abort_message.h>
@@ -945,7 +946,7 @@
 
 inline crash_detail_t* _Nullable android_register_crash_detail_strs(const char* _Nonnull name,
                                                                     const char* _Nonnull data) {
-  return android_register_crash_detail(name, strlen(name), data, strlen(data));
+  return android_crash_detail_register(name, strlen(name), data, strlen(data));
 }
 
 TEST_F(CrasherTest, crash_detail_single) {
@@ -967,6 +968,52 @@
   ASSERT_MATCH(result, R"(CRASH_DETAIL_NAME: 'crash_detail_value')");
 }
 
+TEST_F(CrasherTest, crash_detail_replace_data) {
+  int intercept_result;
+  unique_fd output_fd;
+  StartProcess([]() {
+    auto *cd = android_register_crash_detail_strs("CRASH_DETAIL_NAME", "original_data");
+    android_crash_detail_replace_data(cd, "new_data", strlen("new_data"));
+    abort();
+  });
+  StartIntercept(&output_fd);
+  FinishCrasher();
+  AssertDeath(SIGABRT);
+  FinishIntercept(&intercept_result);
+
+  ASSERT_EQ(1, intercept_result) << "tombstoned reported failure";
+
+  std::string result;
+  ConsumeFd(std::move(output_fd), &result);
+  ASSERT_MATCH(result, R"(CRASH_DETAIL_NAME: 'new_data')");
+  // Ensure the old one no longer shows up, i.e. that we actually replaced
+  // it, not added a new one.
+  ASSERT_NOT_MATCH(result, R"(CRASH_DETAIL_NAME: 'original_data')");
+}
+
+TEST_F(CrasherTest, crash_detail_replace_name) {
+  int intercept_result;
+  unique_fd output_fd;
+  StartProcess([]() {
+    auto *cd = android_register_crash_detail_strs("old_name", g_crash_detail_value);
+    android_crash_detail_replace_name(cd, "new_name", strlen("new_name"));
+    abort();
+  });
+  StartIntercept(&output_fd);
+  FinishCrasher();
+  AssertDeath(SIGABRT);
+  FinishIntercept(&intercept_result);
+
+  ASSERT_EQ(1, intercept_result) << "tombstoned reported failure";
+
+  std::string result;
+  ConsumeFd(std::move(output_fd), &result);
+  ASSERT_MATCH(result, R"(new_name: 'crash_detail_value')");
+  // Ensure the old one no longer shows up, i.e. that we actually replaced
+  // it, not added a new one.
+  ASSERT_NOT_MATCH(result, R"(old_name: 'crash_detail_value')");
+}
+
 TEST_F(CrasherTest, crash_detail_single_byte_name) {
   int intercept_result;
   unique_fd output_fd;
@@ -991,7 +1038,7 @@
   int intercept_result;
   unique_fd output_fd;
   StartProcess([]() {
-    android_register_crash_detail("CRASH_DETAIL_NAME", strlen("CRASH_DETAIL_NAME"), "\1",
+    android_crash_detail_register("CRASH_DETAIL_NAME", strlen("CRASH_DETAIL_NAME"), "\1",
                                   sizeof("\1"));
     abort();
   });
@@ -1035,7 +1082,7 @@
       std::string name = "CRASH_DETAIL_NAME" + std::to_string(i);
       std::string value = "CRASH_DETAIL_VALUE" + std::to_string(i);
       auto* h = android_register_crash_detail_strs(name.data(), value.data());
-      android_unregister_crash_detail(h);
+      android_crash_detail_unregister(h);
     }
 
     android_register_crash_detail_strs("FINAL_NAME", "FINAL_VALUE");
@@ -1103,7 +1150,7 @@
   unique_fd output_fd;
   StartProcess([]() {
     auto* detail1 = android_register_crash_detail_strs("CRASH_DETAIL_NAME", g_crash_detail_value);
-    android_unregister_crash_detail(detail1);
+    android_crash_detail_unregister(detail1);
     android_register_crash_detail_strs("CRASH_DETAIL_NAME2", g_crash_detail_value2);
     abort();
   });
diff --git a/debuggerd/libdebuggerd/tombstone_proto.cpp b/debuggerd/libdebuggerd/tombstone_proto.cpp
index 0098209..74f9a8c 100644
--- a/debuggerd/libdebuggerd/tombstone_proto.cpp
+++ b/debuggerd/libdebuggerd/tombstone_proto.cpp
@@ -51,7 +51,7 @@
 #include <android/set_abort_message.h>
 #include <bionic/macros.h>
 #include <bionic/reserved_signals.h>
-#include <bionic/set_abort_message_internal.h>
+#include <bionic/crash_detail_internal.h>
 #include <log/log.h>
 #include <log/log_read.h>
 #include <log/logprint.h>