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

Commit 7937a36c authored by Christopher Ferris's avatar Christopher Ferris
Browse files

Change all uintptr_t to uint64_t in API.

In order to support the offline unwinding properly, get rid of the
usage of non-fixed type uintptr_t from all API calls.

In addition, completely remove the old local and remote unwinding code
that used libunwind.

The next step will be to move the offline unwinding to the new unwinder.

Bug: 65682279

Test: Ran unit tests for libbacktrace/debuggerd.
Test: Ran debuggerd -b on a few arm and arm64 processes.
Test: Ran crasher and crasher64 and verified tombstones look correct.
Change-Id: Ib0c6cee3ad6785a102b74908a3d8e5e93e5c6b33
parent 2c4f487d
Loading
Loading
Loading
Loading
+3 −3
Original line number Original line Diff line number Diff line
@@ -40,16 +40,16 @@ int open_tombstone(std::string* path);
/* Creates a tombstone file and writes the crash dump to it. */
/* Creates a tombstone file and writes the crash dump to it. */
void engrave_tombstone(int tombstone_fd, BacktraceMap* map, const OpenFilesList* open_files,
void engrave_tombstone(int tombstone_fd, BacktraceMap* map, const OpenFilesList* open_files,
                       pid_t pid, pid_t tid, const std::string& process_name,
                       pid_t pid, pid_t tid, const std::string& process_name,
                       const std::map<pid_t, std::string>& threads, uintptr_t abort_msg_address,
                       const std::map<pid_t, std::string>& threads, uint64_t abort_msg_address,
                       std::string* amfd_data);
                       std::string* amfd_data);


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


void engrave_tombstone(android::base::unique_fd output_fd, BacktraceMap* map,
void engrave_tombstone(android::base::unique_fd output_fd, BacktraceMap* map,
                       unwindstack::Memory* process_memory,
                       unwindstack::Memory* process_memory,
                       const std::map<pid_t, ThreadInfo>& thread_info, pid_t target_thread,
                       const std::map<pid_t, ThreadInfo>& thread_info, pid_t target_thread,
                       uintptr_t abort_msg_address, OpenFilesList* open_files,
                       uint64_t abort_msg_address, OpenFilesList* open_files,
                       std::string* amfd_data);
                       std::string* amfd_data);


#endif  // _DEBUGGERD_TOMBSTONE_H
#endif  // _DEBUGGERD_TOMBSTONE_H
+1 −1
Original line number Original line Diff line number Diff line
@@ -68,7 +68,7 @@ namespace unwindstack {
class Memory;
class Memory;
}
}


void dump_memory(log_t* log, unwindstack::Memory* backtrace, uintptr_t addr, const char* fmt, ...);
void dump_memory(log_t* log, unwindstack::Memory* backtrace, uint64_t addr, const char* fmt, ...);


void read_with_default(const char* path, char* buf, size_t len, const char* default_value);
void read_with_default(const char* path, char* buf, size_t len, const char* default_value);


+2 −2
Original line number Original line Diff line number Diff line
@@ -437,9 +437,9 @@ TEST_F(TombstoneTest, multiple_maps_fault_address_after) {
  map_mock_->AddMap(map);
  map_mock_->AddMap(map);


#if defined(__LP64__)
#if defined(__LP64__)
  uintptr_t addr = 0x12345a534040UL;
  uint64_t addr = 0x12345a534040UL;
#else
#else
  uintptr_t addr = 0xf534040UL;
  uint64_t addr = 0xf534040UL;
#endif
#endif
  dump_all_maps(&log_, map_mock_.get(), nullptr, addr);
  dump_all_maps(&log_, map_mock_.get(), nullptr, addr);


+18 −18
Original line number Original line Diff line number Diff line
@@ -127,7 +127,7 @@ static void dump_thread_info(log_t* log, const ThreadInfo& thread_info) {
}
}


static void dump_stack_segment(log_t* log, BacktraceMap* backtrace_map, Memory* process_memory,
static void dump_stack_segment(log_t* log, BacktraceMap* backtrace_map, Memory* process_memory,
                               uintptr_t* sp, size_t words, int label) {
                               uint64_t* sp, size_t words, int label) {
  // Read the data all at once.
  // Read the data all at once.
  word_t stack_data[words];
  word_t stack_data[words];


@@ -144,18 +144,18 @@ static void dump_stack_segment(log_t* log, BacktraceMap* backtrace_map, Memory*
    } else {
    } else {
      line += "     ";
      line += "     ";
    }
    }
    line += StringPrintf("%" PRIPTR "  %" PRIPTR, *sp, stack_data[i]);
    line += StringPrintf("%" PRIPTR "  %" PRIxPTR, *sp, stack_data[i]);


    backtrace_map_t map;
    backtrace_map_t map;
    backtrace_map->FillIn(stack_data[i], &map);
    backtrace_map->FillIn(stack_data[i], &map);
    if (BacktraceMap::IsValid(map) && !map.name.empty()) {
    if (BacktraceMap::IsValid(map) && !map.name.empty()) {
      line += "  " + map.name;
      line += "  " + map.name;
      uintptr_t offset = 0;
      uint64_t offset = 0;
      std::string func_name = backtrace_map->GetFunctionName(stack_data[i], &offset);
      std::string func_name = backtrace_map->GetFunctionName(stack_data[i], &offset);
      if (!func_name.empty()) {
      if (!func_name.empty()) {
        line += " (" + func_name;
        line += " (" + func_name;
        if (offset) {
        if (offset) {
          line += StringPrintf("+%" PRIuPTR, offset);
          line += StringPrintf("+%" PRIu64, offset);
        }
        }
        line += ')';
        line += ')';
      }
      }
@@ -185,7 +185,7 @@ static void dump_stack(log_t* log, BacktraceMap* backtrace_map, Memory* process_
  first--;
  first--;


  // Dump a few words before the first frame.
  // Dump a few words before the first frame.
  word_t sp = frames[first].sp - STACK_WORDS * sizeof(word_t);
  uint64_t sp = frames[first].sp - STACK_WORDS * sizeof(word_t);
  dump_stack_segment(log, backtrace_map, process_memory, &sp, STACK_WORDS, -1);
  dump_stack_segment(log, backtrace_map, process_memory, &sp, STACK_WORDS, -1);


  // Dump a few words from all successive frames.
  // Dump a few words from all successive frames.
@@ -213,19 +213,19 @@ static void dump_stack(log_t* log, BacktraceMap* backtrace_map, Memory* process_
  }
  }
}
}


static std::string get_addr_string(uintptr_t addr) {
static std::string get_addr_string(uint64_t addr) {
  std::string addr_str;
  std::string addr_str;
#if defined(__LP64__)
#if defined(__LP64__)
  addr_str = StringPrintf("%08x'%08x",
  addr_str = StringPrintf("%08x'%08x",
                          static_cast<uint32_t>(addr >> 32),
                          static_cast<uint32_t>(addr >> 32),
                          static_cast<uint32_t>(addr & 0xffffffff));
                          static_cast<uint32_t>(addr & 0xffffffff));
#else
#else
  addr_str = StringPrintf("%08x", addr);
  addr_str = StringPrintf("%08x", static_cast<uint32_t>(addr));
#endif
#endif
  return addr_str;
  return addr_str;
}
}


static void dump_abort_message(log_t* log, Memory* process_memory, uintptr_t address) {
static void dump_abort_message(log_t* log, Memory* process_memory, uint64_t address) {
  if (address == 0) {
  if (address == 0) {
    return;
    return;
  }
  }
@@ -251,7 +251,7 @@ static void dump_abort_message(log_t* log, Memory* process_memory, uintptr_t add
  _LOG(log, logtype::HEADER, "Abort message: '%s'\n", msg);
  _LOG(log, logtype::HEADER, "Abort message: '%s'\n", msg);
}
}


static void dump_all_maps(log_t* log, BacktraceMap* map, Memory* process_memory, uintptr_t addr) {
static void dump_all_maps(log_t* log, BacktraceMap* map, Memory* process_memory, uint64_t addr) {
  bool print_fault_address_marker = addr;
  bool print_fault_address_marker = addr;


  ScopedBacktraceMapIteratorLock lock(map);
  ScopedBacktraceMapIteratorLock lock(map);
@@ -301,7 +301,7 @@ static void dump_all_maps(log_t* log, BacktraceMap* map, Memory* process_memory,
    } else {
    } else {
      line += '-';
      line += '-';
    }
    }
    line += StringPrintf("  %8" PRIxPTR "  %8" PRIxPTR, entry->offset, entry->end - entry->start);
    line += StringPrintf("  %8" PRIx64 "  %8" PRIx64, entry->offset, entry->end - entry->start);
    bool space_needed = true;
    bool space_needed = true;
    if (entry->name.length() > 0) {
    if (entry->name.length() > 0) {
      space_needed = false;
      space_needed = false;
@@ -315,7 +315,7 @@ static void dump_all_maps(log_t* log, BacktraceMap* map, Memory* process_memory,
      if (space_needed) {
      if (space_needed) {
        line += ' ';
        line += ' ';
      }
      }
      line += StringPrintf(" (load bias 0x%" PRIxPTR ")", entry->load_bias);
      line += StringPrintf(" (load bias 0x%" PRIx64 ")", entry->load_bias);
    }
    }
    _LOG(log, logtype::MAPS, "%s\n", line.c_str());
    _LOG(log, logtype::MAPS, "%s\n", line.c_str());
  }
  }
@@ -335,9 +335,9 @@ static void print_register_row(log_t* log,
                               const std::vector<std::pair<std::string, uint64_t>>& registers) {
                               const std::vector<std::pair<std::string, uint64_t>>& registers) {
  std::string output;
  std::string output;
  for (auto& [name, value] : registers) {
  for (auto& [name, value] : registers) {
    output += android::base::StringPrintf("  %-3s %0*" PRIxPTR, name.c_str(),
    output += android::base::StringPrintf("  %-3s %0*" PRIx64, name.c_str(),
                                          static_cast<int>(2 * sizeof(void*)),
                                          static_cast<int>(2 * sizeof(void*)),
                                          static_cast<uintptr_t>(value));
                                          static_cast<uint64_t>(value));
  }
  }


  _LOG(log, logtype::REGISTERS, "  %s\n", output.c_str());
  _LOG(log, logtype::REGISTERS, "  %s\n", output.c_str());
@@ -389,7 +389,7 @@ void dump_memory_and_code(log_t* log, Memory* memory, Regs* regs) {
}
}


static bool dump_thread(log_t* log, BacktraceMap* map, Memory* process_memory,
static bool dump_thread(log_t* log, BacktraceMap* map, Memory* process_memory,
                        const ThreadInfo& thread_info, uintptr_t abort_msg_address,
                        const ThreadInfo& thread_info, uint64_t abort_msg_address,
                        bool primary_thread) {
                        bool primary_thread) {
  UNUSED(process_memory);
  UNUSED(process_memory);
  log->current_tid = thread_info.tid;
  log->current_tid = thread_info.tid;
@@ -425,10 +425,10 @@ static bool dump_thread(log_t* log, BacktraceMap* map, Memory* process_memory,
  if (primary_thread) {
  if (primary_thread) {
    dump_memory_and_code(log, process_memory, thread_info.registers.get());
    dump_memory_and_code(log, process_memory, thread_info.registers.get());
    if (map) {
    if (map) {
      uintptr_t addr = 0;
      uint64_t addr = 0;
      siginfo_t* si = thread_info.siginfo;
      siginfo_t* si = thread_info.siginfo;
      if (signal_has_si_addr(si->si_signo, si->si_code)) {
      if (signal_has_si_addr(si->si_signo, si->si_code)) {
        addr = reinterpret_cast<uintptr_t>(si->si_addr);
        addr = reinterpret_cast<uint64_t>(si->si_addr);
      }
      }
      dump_all_maps(log, map, process_memory, addr);
      dump_all_maps(log, map, process_memory, addr);
    }
    }
@@ -572,7 +572,7 @@ static void dump_logs(log_t* log, pid_t pid, unsigned int tail) {
  dump_log_file(log, pid, "main", tail);
  dump_log_file(log, pid, "main", tail);
}
}


void engrave_tombstone_ucontext(int tombstone_fd, uintptr_t abort_msg_address, siginfo_t* siginfo,
void engrave_tombstone_ucontext(int tombstone_fd, uint64_t abort_msg_address, siginfo_t* siginfo,
                                ucontext_t* ucontext) {
                                ucontext_t* ucontext) {
  pid_t pid = getpid();
  pid_t pid = getpid();
  pid_t tid = gettid();
  pid_t tid = gettid();
@@ -614,7 +614,7 @@ void engrave_tombstone_ucontext(int tombstone_fd, uintptr_t abort_msg_address, s


void engrave_tombstone(unique_fd output_fd, BacktraceMap* map, Memory* process_memory,
void engrave_tombstone(unique_fd output_fd, BacktraceMap* map, Memory* process_memory,
                       const std::map<pid_t, ThreadInfo>& threads, pid_t target_thread,
                       const std::map<pid_t, ThreadInfo>& threads, pid_t target_thread,
                       uintptr_t abort_msg_address, OpenFilesList* open_files,
                       uint64_t abort_msg_address, OpenFilesList* open_files,
                       std::string* amfd_data) {
                       std::string* amfd_data) {
  // don't copy log messages to tombstone unless this is a dev device
  // don't copy log messages to tombstone unless this is a dev device
  bool want_logs = android::base::GetBoolProperty("ro.debuggable", false);
  bool want_logs = android::base::GetBoolProperty("ro.debuggable", false);
+3 −3
Original line number Original line Diff line number Diff line
@@ -124,7 +124,7 @@ void _LOG(log_t* log, enum logtype ltype, const char* fmt, ...) {
#define MEMORY_BYTES_TO_DUMP 256
#define MEMORY_BYTES_TO_DUMP 256
#define MEMORY_BYTES_PER_LINE 16
#define MEMORY_BYTES_PER_LINE 16


void dump_memory(log_t* log, unwindstack::Memory* memory, uintptr_t addr, const char* fmt, ...) {
void dump_memory(log_t* log, unwindstack::Memory* memory, uint64_t addr, const char* fmt, ...) {
  std::string log_msg;
  std::string log_msg;
  va_list ap;
  va_list ap;
  va_start(ap, fmt);
  va_start(ap, fmt);
@@ -159,7 +159,7 @@ void dump_memory(log_t* log, unwindstack::Memory* memory, uintptr_t addr, const
    bytes &= ~(sizeof(uintptr_t) - 1);
    bytes &= ~(sizeof(uintptr_t) - 1);
  }
  }


  uintptr_t start = 0;
  uint64_t start = 0;
  bool skip_2nd_read = false;
  bool skip_2nd_read = false;
  if (bytes == 0) {
  if (bytes == 0) {
    // In this case, we might want to try another read at the beginning of
    // In this case, we might want to try another read at the beginning of
@@ -206,7 +206,7 @@ void dump_memory(log_t* log, unwindstack::Memory* memory, uintptr_t addr, const
    std::string ascii;
    std::string ascii;
    for (size_t i = 0; i < MEMORY_BYTES_PER_LINE / sizeof(uintptr_t); i++) {
    for (size_t i = 0; i < MEMORY_BYTES_PER_LINE / sizeof(uintptr_t); i++) {
      if (current >= start && current + sizeof(uintptr_t) <= total_bytes) {
      if (current >= start && current + sizeof(uintptr_t) <= total_bytes) {
        android::base::StringAppendF(&logline, " %" PRIPTR, *data_ptr);
        android::base::StringAppendF(&logline, " %" PRIPTR, static_cast<uint64_t>(*data_ptr));


        // Fill out the ascii string from the data.
        // Fill out the ascii string from the data.
        uint8_t* ptr = reinterpret_cast<uint8_t*>(data_ptr);
        uint8_t* ptr = reinterpret_cast<uint8_t*>(data_ptr);
Loading