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

Commit 358de18b authored by Josh Gao's avatar Josh Gao
Browse files

libunwindstack: expose UnwindStackMap::GetFunctionName.

Test: mma
Change-Id: I8736ff5c2ed7c5e64eb68df5f4eccfed614612c7
parent 45c4a56f
Loading
Loading
Loading
Loading
+2 −24
Original line number Diff line number Diff line
@@ -44,28 +44,6 @@
#include "UnwindStack.h"
#include "UnwindStackMap.h"

static std::string GetFunctionName(BacktraceMap* back_map, uintptr_t pc, uintptr_t* offset) {
  *offset = 0;
  unwindstack::Maps* maps = reinterpret_cast<UnwindStackMap*>(back_map)->stack_maps();

  // Get the map for this
  unwindstack::MapInfo* map_info = maps->Find(pc);
  if (map_info == nullptr || map_info->flags & PROT_DEVICE_MAP) {
    return "";
  }

  UnwindStackMap* stack_map = reinterpret_cast<UnwindStackMap*>(back_map);
  unwindstack::Elf* elf = map_info->GetElf(stack_map->process_memory(), true);

  std::string name;
  uint64_t func_offset;
  if (!elf->GetFunctionName(elf->GetRelPc(pc, map_info), &name, &func_offset)) {
    return "";
  }
  *offset = func_offset;
  return name;
}

bool Backtrace::Unwind(unwindstack::Regs* regs, BacktraceMap* back_map,
                       std::vector<backtrace_frame_data_t>* frames, size_t num_ignore_frames) {
  static std::set<std::string> skip_names{"libunwindstack.so", "libbacktrace.so"};
@@ -111,7 +89,7 @@ UnwindStackCurrent::UnwindStackCurrent(pid_t pid, pid_t tid, BacktraceMap* map)
    : BacktraceCurrent(pid, tid, map) {}

std::string UnwindStackCurrent::GetFunctionNameRaw(uintptr_t pc, uintptr_t* offset) {
  return ::GetFunctionName(GetMap(), pc, offset);
  return GetMap()->GetFunctionName(pc, offset);
}

bool UnwindStackCurrent::UnwindFromContext(size_t num_ignore_frames, ucontext_t* ucontext) {
@@ -134,7 +112,7 @@ UnwindStackPtrace::UnwindStackPtrace(pid_t pid, pid_t tid, BacktraceMap* map)
    : BacktracePtrace(pid, tid, map) {}

std::string UnwindStackPtrace::GetFunctionNameRaw(uintptr_t pc, uintptr_t* offset) {
  return ::GetFunctionName(GetMap(), pc, offset);
  return GetMap()->GetFunctionName(pc, offset);
}

bool UnwindStackPtrace::Unwind(size_t num_ignore_frames, ucontext_t* context) {
+21 −0
Original line number Diff line number Diff line
@@ -75,6 +75,27 @@ void UnwindStackMap::FillIn(uintptr_t addr, backtrace_map_t* map) {
  map->load_bias = elf->GetLoadBias();
}

std::string UnwindStackMap::GetFunctionName(uintptr_t pc, uintptr_t* offset) {
  *offset = 0;
  unwindstack::Maps* maps = stack_maps();

  // Get the map for this
  unwindstack::MapInfo* map_info = maps->Find(pc);
  if (map_info == nullptr || map_info->flags & PROT_DEVICE_MAP) {
    return "";
  }

  unwindstack::Elf* elf = map_info->GetElf(process_memory(), true);

  std::string name;
  uint64_t func_offset;
  if (!elf->GetFunctionName(elf->GetRelPc(pc, map_info), &name, &func_offset)) {
    return "";
  }
  *offset = func_offset;
  return name;
}

//-------------------------------------------------------------------------
// BacktraceMap create function.
//-------------------------------------------------------------------------
+2 −0
Original line number Diff line number Diff line
@@ -34,6 +34,8 @@ class UnwindStackMap : public BacktraceMap {

  void FillIn(uintptr_t addr, backtrace_map_t* map) override;

  virtual std::string GetFunctionName(uintptr_t pc, uintptr_t* offset) override;

  unwindstack::Maps* stack_maps() { return stack_maps_.get(); }

  const std::shared_ptr<unwindstack::Memory>& process_memory() { return process_memory_; }
+3 −0
Original line number Diff line number Diff line
@@ -62,6 +62,9 @@ public:
  // Fill in the map data structure for the given address.
  virtual void FillIn(uintptr_t addr, backtrace_map_t* map);

  // Only supported with the new unwinder.
  virtual std::string GetFunctionName(uintptr_t /*pc*/, uintptr_t* /*offset*/) { return ""; }

  // The flags returned are the same flags as used by the mmap call.
  // The values are PROT_*.
  int GetFlags(uintptr_t pc) {