diff --git a/debuggerd/debuggerd_test.cpp b/debuggerd/debuggerd_test.cpp index a308ffbc9..f396b1de8 100644 --- a/debuggerd/debuggerd_test.cpp +++ b/debuggerd/debuggerd_test.cpp @@ -37,6 +37,7 @@ #include #include +#include #include #include #include @@ -945,7 +946,7 @@ static char g_crash_detail_value2[] = "crash_detail_value2"; 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 @@ TEST_F(CrasherTest, crash_detail_single) { 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 @@ TEST_F(CrasherTest, crash_detail_single_bytes) { 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 @@ TEST_F(CrasherTest, crash_detail_many) { 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 @@ TEST_F(CrasherTest, crash_detail_remove) { 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 0098209b0..74f9a8c63 100644 --- a/debuggerd/libdebuggerd/tombstone_proto.cpp +++ b/debuggerd/libdebuggerd/tombstone_proto.cpp @@ -51,7 +51,7 @@ #include #include #include -#include +#include #include #include #include