From 1d0d6623238f9a0de8edbf8a59e64f90847e6e1f Mon Sep 17 00:00:00 2001 From: Misha Wagner Date: Thu, 18 Apr 2019 16:07:33 +0100 Subject: [PATCH] Add UID printing to tombstone headers This is for Android Telemetry to be able to categorise the processes that produce tombstones. Bug: 129933535 Test: atest debugerd_test:TombstoneTest Change-Id: Ie635347c9839eb58bfd27739050bd68cbdbf98da Merged-In: Ie635347c9839eb58bfd27739050bd68cbdbf98da (cherry picked from commit e5b7913d2c5da92c37233fef15ab3109e37d9c90) --- debuggerd/libdebuggerd/include/libdebuggerd/types.h | 3 +++ debuggerd/libdebuggerd/test/tombstone_test.cpp | 10 ++++++++++ debuggerd/libdebuggerd/tombstone.cpp | 3 +++ 3 files changed, 16 insertions(+) diff --git a/debuggerd/libdebuggerd/include/libdebuggerd/types.h b/debuggerd/libdebuggerd/include/libdebuggerd/types.h index 70583af30..eb4b1b844 100644 --- a/debuggerd/libdebuggerd/include/libdebuggerd/types.h +++ b/debuggerd/libdebuggerd/include/libdebuggerd/types.h @@ -23,6 +23,9 @@ struct ThreadInfo { std::unique_ptr registers; + + pid_t uid; + pid_t tid; std::string thread_name; diff --git a/debuggerd/libdebuggerd/test/tombstone_test.cpp b/debuggerd/libdebuggerd/test/tombstone_test.cpp index 3196ce84b..88c206f8d 100644 --- a/debuggerd/libdebuggerd/test/tombstone_test.cpp +++ b/debuggerd/libdebuggerd/test/tombstone_test.cpp @@ -343,6 +343,16 @@ TEST_F(TombstoneTest, dump_header_info) { ASSERT_STREQ(expected.c_str(), amfd_data_.c_str()); } +TEST_F(TombstoneTest, dump_thread_info_uid) { + dump_thread_info(&log_, ThreadInfo{.uid = 1, + .pid = 2, + .tid = 3, + .thread_name = "some_thread", + .process_name = "some_process"}); + std::string expected = "pid: 2, tid: 3, name: some_thread >>> some_process <<<\nuid: 1\n"; + ASSERT_STREQ(expected.c_str(), amfd_data_.c_str()); +} + TEST_F(TombstoneTest, dump_timestamp) { setenv("TZ", "UTC", 1); tzset(); diff --git a/debuggerd/libdebuggerd/tombstone.cpp b/debuggerd/libdebuggerd/tombstone.cpp index cc337ed30..89a5a455f 100644 --- a/debuggerd/libdebuggerd/tombstone.cpp +++ b/debuggerd/libdebuggerd/tombstone.cpp @@ -151,6 +151,7 @@ static void dump_thread_info(log_t* log, const ThreadInfo& thread_info) { _LOG(log, logtype::HEADER, "pid: %d, tid: %d, name: %s >>> %s <<<\n", thread_info.pid, thread_info.tid, thread_info.thread_name.c_str(), thread_info.process_name.c_str()); + _LOG(log, logtype::HEADER, "uid: %d\n", thread_info.uid); } static void dump_stack_segment(log_t* log, unwindstack::Maps* maps, unwindstack::Memory* memory, @@ -622,6 +623,7 @@ static void dump_logs(log_t* log, pid_t pid, unsigned int tail) { void engrave_tombstone_ucontext(int tombstone_fd, uint64_t abort_msg_address, siginfo_t* siginfo, ucontext_t* ucontext) { + pid_t uid = getuid(); pid_t pid = getpid(); pid_t tid = gettid(); @@ -643,6 +645,7 @@ void engrave_tombstone_ucontext(int tombstone_fd, uint64_t abort_msg_address, si std::map threads; threads[gettid()] = ThreadInfo{ .registers = std::move(regs), + .uid = uid, .tid = tid, .thread_name = thread_name, .pid = pid,