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

Commit 899c1bdf authored by Dimitry Ivanov's avatar Dimitry Ivanov Committed by Gerrit Code Review
Browse files

Revert "[Berberis][CrashReporting] Dump guest thread info to tom..."

Revert submission 3062926

Reason for revert: We want guest state to be present in all threads - revert to be able to fix the proto field type.

Reverted changes: /q/submissionid:3062926

Change-Id: I87b282a0d9caebe4eae2e7d8eca8ec8ebaa3eca6
parent 4c3a9dfd
Loading
Loading
Loading
Loading
+2 −37
Original line number Diff line number Diff line
@@ -30,7 +30,6 @@
#include <map>
#include <memory>
#include <set>
#include <string>
#include <vector>

#include <android-base/errno_restorer.h>
@@ -82,10 +81,6 @@ using android::base::ErrnoRestorer;
using android::base::StringPrintf;
using android::base::unique_fd;

// This stores guest architecture. When the architecture is supported, tombstone file will output
// guest state information.
static Architecture g_guest_arch;

static bool pid_contains_tid(int pid_proc_fd, pid_t tid) {
  struct stat st;
  std::string task_path = StringPrintf("task/%d", tid);
@@ -495,8 +490,6 @@ static void ReadGuestRegisters(std::unique_ptr<unwindstack::Regs>* regs, pid_t t
        arm_user_regs.regs[i] = guest_regs.regs_arm.r[i];
      }
      regs->reset(unwindstack::RegsArm::Read(&arm_user_regs));

      g_guest_arch = Architecture::ARM32;
      break;
    }
#if defined(__LP64__)
@@ -508,8 +501,6 @@ static void ReadGuestRegisters(std::unique_ptr<unwindstack::Regs>* regs, pid_t t
      arm64_user_regs.sp = guest_regs.regs_arm64.sp;
      arm64_user_regs.pc = guest_regs.regs_arm64.ip;
      regs->reset(unwindstack::RegsArm64::Read(&arm64_user_regs));

      g_guest_arch = Architecture::ARM64;
      break;
    }
    case NATIVE_BRIDGE_ARCH_RISCV64: {
@@ -520,8 +511,6 @@ static void ReadGuestRegisters(std::unique_ptr<unwindstack::Regs>* regs, pid_t t
        riscv64_user_regs.regs[i] = guest_regs.regs_riscv64.x[i];
      }
      regs->reset(unwindstack::RegsRiscv64::Read(&riscv64_user_regs, tid));

      g_guest_arch = Architecture::RISCV64;
      break;
    }
#endif
@@ -786,32 +775,8 @@ int main(int argc, char** argv) {

    {
      ATRACE_NAME("engrave_tombstone");
      unwindstack::ArchEnum regs_arch = unwindstack::ARCH_UNKNOWN;
      switch (g_guest_arch) {
        case Architecture::ARM32: {
          regs_arch = unwindstack::ARCH_ARM;
          break;
        }
        case Architecture::ARM64: {
          regs_arch = unwindstack::ARCH_ARM64;
          break;
        }
        case Architecture::RISCV64: {
          regs_arch = unwindstack::ARCH_RISCV64;
          break;
        }
        default: {
        }
      }
      if (regs_arch == unwindstack::ARCH_UNKNOWN) {
      engrave_tombstone(std::move(g_output_fd), std::move(g_proto_fd), &unwinder, thread_info,
                        g_target_thread, process_info, &open_files, &amfd_data);
      } else {
        unwindstack::AndroidRemoteUnwinder guest_unwinder(vm_pid, regs_arch);
        engrave_tombstone(std::move(g_output_fd), std::move(g_proto_fd), &unwinder, thread_info,
                          g_target_thread, process_info, &open_files, &amfd_data, &g_guest_arch,
                          &guest_unwinder);
      }
    }
  }

+2 −6
Original line number Diff line number Diff line
@@ -28,7 +28,6 @@
#include <android-base/unique_fd.h>

#include "open_files_list.h"
#include "tombstone.pb.h"
#include "types.h"

// Forward declarations
@@ -55,17 +54,14 @@ void engrave_tombstone(android::base::unique_fd output_fd, android::base::unique
                       unwindstack::AndroidUnwinder* unwinder,
                       const std::map<pid_t, ThreadInfo>& thread_info, pid_t target_thread,
                       const ProcessInfo& process_info, OpenFilesList* open_files,
                       std::string* amfd_data, Architecture* guest_arch = nullptr,
                       unwindstack::AndroidUnwinder* guest_unwinder = nullptr);
                       std::string* amfd_data);

void engrave_tombstone_ucontext(int tombstone_fd, int proto_fd, uint64_t abort_msg_address,
                                siginfo_t* siginfo, ucontext_t* ucontext);

void engrave_tombstone_proto(Tombstone* tombstone, unwindstack::AndroidUnwinder* unwinder,
                             const std::map<pid_t, ThreadInfo>& threads, pid_t target_thread,
                             const ProcessInfo& process_info, const OpenFilesList* open_files,
                             Architecture* guest_arch,
                             unwindstack::AndroidUnwinder* guest_unwinder);
                             const ProcessInfo& process_info, const OpenFilesList* open_files);

bool tombstone_proto_to_text(
    const Tombstone& tombstone,
+2 −4
Original line number Diff line number Diff line
@@ -125,12 +125,10 @@ void engrave_tombstone(unique_fd output_fd, unique_fd proto_fd,
                       unwindstack::AndroidUnwinder* unwinder,
                       const std::map<pid_t, ThreadInfo>& threads, pid_t target_thread,
                       const ProcessInfo& process_info, OpenFilesList* open_files,
                       std::string* amfd_data, Architecture* guest_arch,
                       unwindstack::AndroidUnwinder* guest_unwinder) {
                       std::string* amfd_data) {
  // Don't copy log messages to tombstone unless this is a development device.
  Tombstone tombstone;
  engrave_tombstone_proto(&tombstone, unwinder, threads, target_thread, process_info, open_files,
                          guest_arch, guest_unwinder);
  engrave_tombstone_proto(&tombstone, unwinder, threads, target_thread, process_info, open_files);

  if (proto_fd != -1) {
    if (!tombstone.SerializeToFileDescriptor(proto_fd.get())) {
+3 −31
Original line number Diff line number Diff line
@@ -482,8 +482,7 @@ static void dump_thread_backtrace(std::vector<unwindstack::FrameData>& frames, T
}

static void dump_thread(Tombstone* tombstone, unwindstack::AndroidUnwinder* unwinder,
                        const ThreadInfo& thread_info, bool memory_dump = false,
                        unwindstack::AndroidUnwinder* guest_unwinder = nullptr) {
                        const ThreadInfo& thread_info, bool memory_dump = false) {
  Thread thread;

  thread.set_id(thread_info.tid);
@@ -510,26 +509,6 @@ static void dump_thread(Tombstone* tombstone, unwindstack::AndroidUnwinder* unwi

  auto& threads = *tombstone->mutable_threads();
  threads[thread_info.tid] = thread;

  if (guest_unwinder) {
    if (!thread_info.guest_registers) {
      async_safe_format_log(ANDROID_LOG_INFO, LOG_TAG,
                            "No guest state registers information for tid %d", thread_info.tid);
      return;
    }
    Thread guest_thread;
    unwindstack::AndroidUnwinderData guest_data;
    guest_data.saved_initial_regs = std::make_optional<std::unique_ptr<unwindstack::Regs>>();
    if (guest_unwinder->Unwind(thread_info.guest_registers.get(), guest_data)) {
      dump_thread_backtrace(guest_data.frames, guest_thread);
    } else {
      async_safe_format_log(ANDROID_LOG_ERROR, LOG_TAG,
                            "Unwind guest state registers failed for tid %d: Error %s",
                            thread_info.tid, guest_data.GetErrorString().c_str());
    }
    dump_registers(guest_unwinder, *guest_data.saved_initial_regs, guest_thread, memory_dump);
    *tombstone->mutable_guest_thread() = guest_thread;
  }
}

static void dump_mappings(Tombstone* tombstone, unwindstack::Maps* maps,
@@ -707,17 +686,10 @@ static void dump_tags_around_fault_addr(Signal* signal, const Tombstone& tombsto

void engrave_tombstone_proto(Tombstone* tombstone, unwindstack::AndroidUnwinder* unwinder,
                             const std::map<pid_t, ThreadInfo>& threads, pid_t target_tid,
                             const ProcessInfo& process_info, const OpenFilesList* open_files,
                             Architecture* guest_arch,
                             unwindstack::AndroidUnwinder* guest_unwinder) {
                             const ProcessInfo& process_info, const OpenFilesList* open_files) {
  Tombstone result;

  result.set_arch(get_arch());
  if (guest_arch != nullptr) {
    result.set_guest_arch(*guest_arch);
  } else {
    result.set_guest_arch(Architecture::NONE);
  }
  result.set_build_fingerprint(android::base::GetProperty("ro.build.fingerprint", "unknown"));
  result.set_revision(android::base::GetProperty("ro.revision", "unknown"));
  result.set_timestamp(get_timestamp());
@@ -778,7 +750,7 @@ void engrave_tombstone_proto(Tombstone* tombstone, unwindstack::AndroidUnwinder*
  dump_abort_message(&result, unwinder->GetProcessMemory(), process_info);
  dump_crash_details(&result, unwinder->GetProcessMemory(), process_info);
  // Dump the target thread, but save the memory around the registers.
  dump_thread(&result, unwinder, target_thread, /* memory_dump */ true, guest_unwinder);
  dump_thread(&result, unwinder, target_thread, /* memory_dump */ true);

  for (const auto& [tid, thread_info] : threads) {
    if (tid != target_tid) {
+3 −34
Original line number Diff line number Diff line
@@ -79,8 +79,8 @@ static std::string describe_pac_enabled_keys(long value) {
  return describe_end(value, desc);
}

static const char* abi_string(const Architecture& arch) {
  switch (arch) {
static const char* abi_string(const Tombstone& tombstone) {
  switch (tombstone.arch()) {
    case Architecture::ARM32:
      return "arm";
    case Architecture::ARM64:
@@ -578,37 +578,11 @@ void print_logs(CallbackType callback, const Tombstone& tombstone, int tail) {
  }
}

static void print_guest_thread(CallbackType callback, const Tombstone& tombstone,
                               const Thread& guest_thread) {
  CBS("--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---");
  CBS("Guest thread information");
  print_thread_registers(callback, tombstone, guest_thread, true);

  CBS("");
  CB(true, "%d total frames", guest_thread.current_backtrace().size());
  CB(true, "backtrace:");
  print_backtrace(callback, tombstone, guest_thread.current_backtrace(), true);

  print_thread_memory_dump(callback, tombstone, guest_thread);

  CBS("");

  // No memory maps to print.
  if (!tombstone.memory_mappings().empty()) {
    print_memory_maps(callback, tombstone);
  } else {
    CBS("No memory maps found");
  }
}

bool tombstone_proto_to_text(const Tombstone& tombstone, CallbackType callback) {
  CBL("*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***");
  CBL("Build fingerprint: '%s'", tombstone.build_fingerprint().c_str());
  CBL("Revision: '%s'", tombstone.revision().c_str());
  CBL("ABI: '%s'", abi_string(tombstone.arch()));
  if (tombstone.guest_arch() != Architecture::NONE) {
    CBL("Guest architecture: '%s'", abi_string(tombstone.guest_arch()));
  }
  CBL("ABI: '%s'", abi_string(tombstone));
  CBL("Timestamp: %s", tombstone.timestamp().c_str());
  CBL("Process uptime: %ds", tombstone.process_uptime());

@@ -661,10 +635,5 @@ bool tombstone_proto_to_text(const Tombstone& tombstone, CallbackType callback)

  print_logs(callback, tombstone, 0);

  // Process guest thread
  if (tombstone.has_guest_thread()) {
    print_guest_thread(callback, tombstone, tombstone.guest_thread());
  }

  return true;
}
Loading