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

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

Use new unwinder for offline in libbacktrace.

libbbacktrace changes:
- Completely rewrite the BacktraceOffline class to use the new unwinder.
- Modify the test data to save ucontext_t data instead of unw_context data.
- Convert the previous tests from unw_context data to ucontext_t data.

Bug: 65682279

Test: New unit tests pass in libunwindstack.
Test: All offline tests continue to pass.
Change-Id: I540345c304b20199d46deeb0349a0638a0f3ab2f
parent 8abe4e26
Loading
Loading
Loading
Loading
+2 −53
Original line number Diff line number Diff line
@@ -128,39 +128,8 @@ cc_library_shared {
    cflags: ["-O0"],
    srcs: ["backtrace_testlib.cpp"],

    target: {
        linux: {
    shared_libs: [
                "libunwind",
                "libunwindstack",
            ],
        },
    }
}

//-------------------------------------------------------------------------
// The libbacktrace_offline static library.
//-------------------------------------------------------------------------
cc_library_static {
    name: "libbacktrace_offline",
    defaults: ["libbacktrace_common"],
    host_supported: true,
    srcs: ["BacktraceOffline.cpp"],

    cflags: [
        "-D__STDC_CONSTANT_MACROS",
        "-D__STDC_LIMIT_MACROS",
        "-D__STDC_FORMAT_MACROS",
    ],

    header_libs: ["llvm-headers"],

    // Use shared libraries so their headers get included during build.
    shared_libs = [
        "libbase",
        "libunwind",
      "libunwindstack",
        "libziparchive",
    ],
}

@@ -193,28 +162,11 @@ cc_test {
        "libbase",
        "libcutils",
        "liblog",
        "libunwind",
        "libunwindstack",
    ],

    group_static_libs: true,

    // Statically link LLVMlibraries to remove dependency on llvm shared library.
    static_libs = [
        "libbacktrace_offline",
        "libLLVMObject",
        "libLLVMBitReader",
        "libLLVMMC",
        "libLLVMMCParser",
        "libLLVMCore",
        "libLLVMSupport",

        "libziparchive",
        "libz",
    ],

    header_libs: ["llvm-headers"],

    target: {
        android: {
            cflags: ["-DENABLE_PSS_TESTS"],
@@ -223,9 +175,6 @@ cc_test {
            ],
        },
        linux_glibc: {
            host_ldlibs: [
                "-lncurses",
            ],
            static_libs: ["libutils"],
        },
    },
+4 −0
Original line number Diff line number Diff line
@@ -168,5 +168,9 @@ std::string Backtrace::GetErrorString(BacktraceUnwindError error) {
      return "Failed to find a function in debug sections";
    case BACKTRACE_UNWIND_ERROR_EXECUTE_DWARF_INSTRUCTION_FAILED:
      return "Failed to execute dwarf instructions in debug sections";
    case BACKTRACE_UNWIND_ERROR_UNWIND_INFO:
      return "Failed to unwind due to invalid unwind information";
    case BACKTRACE_UNWIND_ERROR_REPEATED_FRAME:
      return "Failed to unwind due to same sp/pc repeating";
  }
}
+1 −1
Original line number Diff line number Diff line
@@ -64,7 +64,7 @@ size_t BacktraceCurrent::Read(uint64_t addr, uint8_t* buffer, size_t bytes) {
  return bytes;
}

bool BacktraceCurrent::Unwind(size_t num_ignore_frames, ucontext_t* ucontext) {
bool BacktraceCurrent::Unwind(size_t num_ignore_frames, void* ucontext) {
  if (GetMap() == nullptr) {
    // Without a map object, we can't do anything.
    error_.error_code = BACKTRACE_UNWIND_ERROR_MAP_MISSING;
+2 −3
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@

#include <stdint.h>
#include <sys/types.h>
#include <ucontext.h>

#include <backtrace/Backtrace.h>

@@ -44,7 +43,7 @@ class BacktraceCurrent : public Backtrace {

  bool ReadWord(uint64_t ptr, word_t* out_value) override;

  bool Unwind(size_t num_ignore_frames, ucontext_t* ucontext) override;
  bool Unwind(size_t num_ignore_frames, void* ucontext) override;

 protected:
  bool DiscardFrame(const backtrace_frame_data_t& frame);
@@ -52,7 +51,7 @@ class BacktraceCurrent : public Backtrace {
 private:
  bool UnwindThread(size_t num_ignore_frames);

  virtual bool UnwindFromContext(size_t num_ignore_frames, ucontext_t* ucontext) = 0;
  virtual bool UnwindFromContext(size_t num_ignore_frames, void* ucontext) = 0;
};

#endif // _LIBBACKTRACE_BACKTRACE_CURRENT_H
+0 −10
Original line number Diff line number Diff line
@@ -146,13 +146,3 @@ BacktraceMap* BacktraceMap::Create(pid_t pid, bool /*uncached*/) {
  return map;
}
#endif

BacktraceMap* BacktraceMap::Create(pid_t pid, const std::vector<backtrace_map_t>& maps) {
    BacktraceMap* backtrace_map = new BacktraceMap(pid);
    backtrace_map->maps_.insert(backtrace_map->maps_.begin(), maps.begin(), maps.end());
    std::sort(backtrace_map->maps_.begin(), backtrace_map->maps_.end(),
            [](const backtrace_map_t& map1, const backtrace_map_t& map2) {
              return map1.start < map2.start;
            });
    return backtrace_map;
}
Loading