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

Commit d06001d6 authored by Christopher Ferris's avatar Christopher Ferris
Browse files

Split arch data into separate files.

Add an ArchEnum to express the arch of the Elf objects and Reg objects.

Split out the regs code into per arch pieces and generic parts.
Also, split out the header files for each arch.

Do not break out the test code yet, there isn't enough and it doesn't
help to maintain the tests.

Test: libunwindstack/libbacktrace/debuggerd unit tests pass.
Test: Running debuggerd -b <PIDS> yields valid data on bullhead.
Change-Id: If61f6c730c9ff2249f986b41de8c4d62f7158325
parent 1ae6d14f
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -99,8 +99,7 @@ bool UnwindStackCurrent::UnwindFromContext(size_t num_ignore_frames, ucontext_t*
    // one extra function call appearing in the unwind.
    unwindstack::RegsGetLocal(regs.get());
  } else {
    regs.reset(
        unwindstack::Regs::CreateFromUcontext(unwindstack::Regs::CurrentMachineType(), ucontext));
    regs.reset(unwindstack::Regs::CreateFromUcontext(unwindstack::Regs::CurrentArch(), ucontext));
  }

  error_ = BACKTRACE_UNWIND_NO_ERROR;
@@ -120,8 +119,7 @@ bool UnwindStackPtrace::Unwind(size_t num_ignore_frames, ucontext_t* context) {
  if (context == nullptr) {
    regs.reset(unwindstack::Regs::RemoteGet(Tid()));
  } else {
    regs.reset(
        unwindstack::Regs::CreateFromUcontext(unwindstack::Regs::CurrentMachineType(), context));
    regs.reset(unwindstack::Regs::CreateFromUcontext(unwindstack::Regs::CurrentArch(), context));
  }

  error_ = BACKTRACE_UNWIND_NO_ERROR;
+4 −0
Original line number Diff line number Diff line
@@ -60,6 +60,10 @@ cc_library {
        "Maps.cpp",
        "Memory.cpp",
        "Regs.cpp",
        "RegsArm.cpp",
        "RegsArm64.cpp",
        "RegsX86.cpp",
        "RegsX86_64.cpp",
        "Unwinder.cpp",
        "Symbols.cpp",
    ],
+2 −2
Original line number Diff line number Diff line
@@ -23,11 +23,11 @@

#include <unwindstack/Log.h>
#include <unwindstack/Memory.h>
#include <unwindstack/Regs.h>
#include <unwindstack/RegsArm.h>

#include "ArmExidx.h"
#include "Check.h"
#include "Machine.h"
#include "MachineArm.h"

namespace unwindstack {

+10 −9
Original line number Diff line number Diff line
@@ -31,7 +31,6 @@
#include <unwindstack/Regs.h>

#include "ElfInterfaceArm.h"
#include "Machine.h"
#include "Symbols.h"

namespace unwindstack {
@@ -183,18 +182,15 @@ ElfInterface* Elf::CreateInterfaceFromMemory(Memory* memory) {
      return nullptr;
    }

    if (e_machine != EM_ARM && e_machine != EM_386) {
      // Unsupported.
      ALOGI("32 bit elf that is neither arm nor x86: e_machine = %d\n", e_machine);
      return nullptr;
    }

    machine_type_ = e_machine;
    if (e_machine == EM_ARM) {
      arch_ = ARCH_ARM;
      interface.reset(new ElfInterfaceArm(memory));
    } else if (e_machine == EM_386) {
      arch_ = ARCH_X86;
      interface.reset(new ElfInterface32(memory));
    } else {
      // Unsupported.
      ALOGI("32 bit elf that is neither arm nor x86: e_machine = %d\n", e_machine);
      return nullptr;
    }
@@ -203,12 +199,17 @@ ElfInterface* Elf::CreateInterfaceFromMemory(Memory* memory) {
    if (!memory->ReadFully(EI_NIDENT + sizeof(Elf64_Half), &e_machine, sizeof(e_machine))) {
      return nullptr;
    }
    if (e_machine != EM_AARCH64 && e_machine != EM_X86_64) {

    machine_type_ = e_machine;
    if (e_machine == EM_AARCH64) {
      arch_ = ARCH_ARM64;
    } else if (e_machine == EM_X86_64) {
      arch_ = ARCH_X86_64;
    } else {
      // Unsupported.
      ALOGI("64 bit elf that is neither aarch64 nor x86_64: e_machine = %d\n", e_machine);
      return nullptr;
    }
    machine_type_ = e_machine;
    interface.reset(new ElfInterface64(memory));
  }

+2 −2
Original line number Diff line number Diff line
@@ -18,11 +18,11 @@
#include <stdint.h>

#include <unwindstack/Memory.h>
#include <unwindstack/Regs.h>
#include <unwindstack/RegsArm.h>

#include "ArmExidx.h"
#include "ElfInterfaceArm.h"
#include "Machine.h"
#include "MachineArm.h"

namespace unwindstack {

Loading