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

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

Fix unwind_reg_info tool.

I was using the pc as the offest into the elf. That is obviously not
correct. Added an optional OFFSET argument like in unwind_info along
with this change.

Test: Verified that with no offest works, verified with a zero offset
Test: works, verified with a non-zero offset results in a bad elf
Test: on an elf without an offset.
Change-Id: I4b6d02609627288e9f8a0eb26988d03adf95cb1f
parent 8c8ce02e
Loading
Loading
Loading
Loading
+17 −5
Original line number Diff line number Diff line
@@ -165,8 +165,8 @@ void PrintArmRegInformation(ElfInterfaceArm* interface, uint64_t pc) {
  }
}

int GetInfo(const char* file, uint64_t pc) {
  Elf elf(Memory::CreateFileMemory(file, pc).release());
int GetInfo(const char* file, uint64_t offset, uint64_t pc) {
  Elf elf(Memory::CreateFileMemory(file, offset).release());
  if (!elf.Init() || !elf.valid()) {
    printf("%s is not a valid elf file.\n", file);
    return 1;
@@ -243,12 +243,14 @@ int GetInfo(const char* file, uint64_t pc) {
}  // namespace unwindstack

int main(int argc, char** argv) {
  if (argc != 3) {
    printf("Usage: unwind_reg_info ELF_FILE PC\n");
  if (argc != 3 && argc != 4) {
    printf("Usage: unwind_reg_info ELF_FILE PC [OFFSET]\n");
    printf("  ELF_FILE\n");
    printf("    The path to an elf file.\n");
    printf("  PC\n");
    printf("    The pc for which the register information should be obtained.\n");
    printf("  OFFSET\n");
    printf("    Use the offset into the ELF file as the beginning of the elf.\n");
    return 1;
  }

@@ -270,5 +272,15 @@ int main(int argc, char** argv) {
    return 1;
  }

  return unwindstack::GetInfo(argv[1], pc);
  uint64_t offset = 0;
  if (argc == 4) {
    char* end;
    offset = strtoull(argv[3], &end, 16);
    if (*end != '\0') {
      printf("Malformed OFFSET value: %s\n", argv[3]);
      return 1;
    }
  }

  return unwindstack::GetInfo(argv[1], offset, pc);
}