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

Commit 4ae266cc authored by Christopher Ferris's avatar Christopher Ferris
Browse files

Add indicator that an elf is memory backed.

Modify the unwinder library to indicate that at least one of the stack
frames contains an elf file that is unreadable.

Modify debuggerd to display a note about the unreadable frame and a possible
way to fix it.

Bug: 129769339

Test: New unit tests pass.
Test: Ran an app that crashes and has an unreadable file and verified the
Test: message is displayed. Then setenforce 0 and verify the message is
Test: not displayed.
Change-Id: Ibc4fe1d117e9b5840290454e90914ddc698d3cc2
parent 5c421695
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -183,6 +183,12 @@ cc_library_static {
            ],
        },
    },

    product_variables: {
        debuggable: {
            cflags: ["-DROOT_POSSIBLE"],
        },
    },
}

cc_test {
+1 −4
Original line number Diff line number Diff line
@@ -74,10 +74,7 @@ void dump_backtrace_thread(int output_fd, unwindstack::Unwinder* unwinder,
    return;
  }

  unwinder->SetDisplayBuildID(true);
  for (size_t i = 0; i < unwinder->NumFrames(); i++) {
    _LOG(&log, logtype::BACKTRACE, "  %s\n", unwinder->FormatFrame(i).c_str());
  }
  log_backtrace(&log, unwinder, "  ");
}

void dump_backtrace(android::base::unique_fd output_fd, unwindstack::Unwinder* unwinder,
+3 −0
Original line number Diff line number Diff line
@@ -73,9 +73,12 @@ typedef uint32_t word_t;
void _LOG(log_t* log, logtype ltype, const char* fmt, ...) __attribute__((format(printf, 3, 4)));

namespace unwindstack {
class Unwinder;
class Memory;
}

void log_backtrace(log_t* log, unwindstack::Unwinder* unwinder, const char* prefix);

void dump_memory(log_t* log, unwindstack::Memory* backtrace, uint64_t addr, const std::string&);

void read_with_default(const char* path, char* buf, size_t len, const char* default_value);
+1 −8
Original line number Diff line number Diff line
@@ -371,13 +371,6 @@ static void dump_all_maps(log_t* log, unwindstack::Unwinder* unwinder, uint64_t
  }
}

void dump_backtrace(log_t* log, unwindstack::Unwinder* unwinder, const char* prefix) {
  unwinder->SetDisplayBuildID(true);
  for (size_t i = 0; i < unwinder->NumFrames(); i++) {
    _LOG(log, logtype::BACKTRACE, "%s%s\n", prefix, unwinder->FormatFrame(i).c_str());
  }
}

static void print_register_row(log_t* log,
                               const std::vector<std::pair<std::string, uint64_t>>& registers) {
  std::string output;
@@ -470,7 +463,7 @@ static bool dump_thread(log_t* log, unwindstack::Unwinder* unwinder, const Threa
    _LOG(log, logtype::THREAD, "Failed to unwind");
  } else {
    _LOG(log, logtype::BACKTRACE, "\nbacktrace:\n");
    dump_backtrace(log, unwinder, "    ");
    log_backtrace(log, unwinder, "    ");

    _LOG(log, logtype::STACK, "\nstack:\n");
    dump_stack(log, unwinder->frames(), unwinder->GetMaps(), unwinder->GetProcessMemory().get());
+20 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@
#include <debuggerd/handler.h>
#include <log/log.h>
#include <unwindstack/Memory.h>
#include <unwindstack/Unwinder.h>

using android::base::unique_fd;

@@ -422,3 +423,22 @@ const char* get_sigcode(const siginfo_t* si) {
  // Then give up...
  return "?";
}

void log_backtrace(log_t* log, unwindstack::Unwinder* unwinder, const char* prefix) {
  if (unwinder->elf_from_memory_not_file()) {
    _LOG(log, logtype::BACKTRACE,
         "%sNOTE: Function names and BuildId information is missing for some frames due\n", prefix);
    _LOG(log, logtype::BACKTRACE,
         "%sNOTE: to unreadable libraries. For unwinds of apps, only shared libraries\n", prefix);
    _LOG(log, logtype::BACKTRACE, "%sNOTE: found under the lib/ directory are readable.\n", prefix);
#if defined(ROOT_POSSIBLE)
    _LOG(log, logtype::BACKTRACE,
         "%sNOTE: On this device, run setenforce 0 to make the libraries readable.\n", prefix);
#endif
  }

  unwinder->SetDisplayBuildID(true);
  for (size_t i = 0; i < unwinder->NumFrames(); i++) {
    _LOG(log, logtype::BACKTRACE, "%s%s\n", prefix, unwinder->FormatFrame(i).c_str());
  }
}
Loading