Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1d0d6623 authored by Misha Wagner's avatar Misha Wagner
Browse files

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)
parent 6b8caf8e
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -23,6 +23,9 @@

struct ThreadInfo {
  std::unique_ptr<unwindstack::Regs> registers;

  pid_t uid;

  pid_t tid;
  std::string thread_name;

+10 −0
Original line number Diff line number Diff line
@@ -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();
+3 −0
Original line number Diff line number Diff line
@@ -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<pid_t, ThreadInfo> threads;
  threads[gettid()] = ThreadInfo{
      .registers = std::move(regs),
      .uid = uid,
      .tid = tid,
      .thread_name = thread_name,
      .pid = pid,