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

Commit 96644962 authored by Christopher Ferris's avatar Christopher Ferris Committed by Charlie Boutier
Browse files

Move from libbacktrace libunwindstack.

libbacktrace is deprecated, so use the new unwindstack object
that replaces this.

Bug: 120606663

Tag: #refactor

Test: Manual - Ran bluetooth_stack_with_facade sent SIGSEGV and
Test: observed valid backtrace (on host and device).
Test: Ran root-canal on host and sent SIGSEGV and observed valid
Test: backtrace (host only executable).
Change-Id: I5c95627b3f674495e0d9d022d2efff1da5ccefc
(cherry picked from commit ae29ca0c)
Merged-In: I5c95627b3f674495e0d9d022d2efff1da5ccefc5

Ignore-AOSP-First: Cherry-picked from AOSP
Merged-In: I690e23c4eadd7a9e3f33eb246f4458d23eb03df0
Change-Id: I690e23c4eadd7a9e3f33eb246f4458d23eb03df0
parent 8826a400
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -280,12 +280,12 @@ cc_binary {
        "libbt_shim_ffi",
        "libbt_shim_ffi",
    ],
    ],
    shared_libs: [
    shared_libs: [
        "libbacktrace",
        "libcrypto",
        "libcrypto",
        "libgrpc++",
        "libgrpc++",
        "libgrpc++_unsecure",
        "libgrpc++_unsecure",
        "libgrpc_wrap",
        "libgrpc_wrap",
        "libprotobuf-cpp-full",
        "libprotobuf-cpp-full",
        "libunwindstack",
    ],
    ],
    target: {
    target: {
        android: {
        android: {
+10 −13
Original line number Original line Diff line number Diff line
@@ -20,6 +20,7 @@
#include <csignal>
#include <csignal>
#include <cstring>
#include <cstring>
#include <memory>
#include <memory>
#include <optional>
#include <string>
#include <string>
#include <thread>
#include <thread>


@@ -27,8 +28,7 @@


// clang-format off
// clang-format off
#include <client/linux/handler/exception_handler.h>
#include <client/linux/handler/exception_handler.h>
#include <backtrace/Backtrace.h>
#include <unwindstack/AndroidUnwinder.h>
#include <backtrace/backtrace_constants.h>
// clang-format on
// clang-format on


#include "common/init_flags.h"
#include "common/init_flags.h"
@@ -71,27 +71,24 @@ void interrupt_handler(int signal_number) {
struct sigaction new_act = {.sa_handler = interrupt_handler};
struct sigaction new_act = {.sa_handler = interrupt_handler};


bool crash_callback(const void* crash_context, size_t crash_context_size, void* context) {
bool crash_callback(const void* crash_context, size_t crash_context_size, void* context) {
  pid_t tid = BACKTRACE_CURRENT_THREAD;
  std::optional<pid_t> tid;
  if (crash_context_size >= sizeof(google_breakpad::ExceptionHandler::CrashContext)) {
  if (crash_context_size >= sizeof(google_breakpad::ExceptionHandler::CrashContext)) {
    auto* ctx = static_cast<const google_breakpad::ExceptionHandler::CrashContext*>(crash_context);
    auto* ctx = static_cast<const google_breakpad::ExceptionHandler::CrashContext*>(crash_context);
    tid = ctx->tid;
    *tid = ctx->tid;
    int signal_number = ctx->siginfo.si_signo;
    int signal_number = ctx->siginfo.si_signo;
    LOG_ERROR("Process crashed, signal: %s[%d], tid: %d", strsignal(signal_number), signal_number, ctx->tid);
    LOG_ERROR("Process crashed, signal: %s[%d], tid: %d", strsignal(signal_number), signal_number, ctx->tid);
  } else {
  } else {
    LOG_ERROR("Process crashed, signal: unknown, tid: unknown");
    LOG_ERROR("Process crashed, signal: unknown, tid: unknown");
  }
  }
  std::unique_ptr<Backtrace> backtrace(Backtrace::Create(BACKTRACE_CURRENT_PROCESS, tid));
  unwindstack::AndroidLocalUnwinder unwinder;
  if (backtrace == nullptr) {
  unwindstack::AndroidUnwinderData data;
    LOG_ERROR("Failed to create backtrace object");
  if (!unwinder.Unwind(tid, data)) {
    return false;
    LOG_ERROR("Unwind failed");
  }
  if (!backtrace->Unwind(0)) {
    LOG_ERROR("backtrace->Unwind failed");
    return false;
    return false;
  }
  }
  LOG_ERROR("Backtrace:");
  LOG_ERROR("Backtrace:");
  for (size_t i = 0; i < backtrace->NumFrames(); i++) {
  for (const auto& frame : data.frames) {
    LOG_ERROR("%s", backtrace->FormatFrameData(i).c_str());
    LOG_ERROR("%s", unwinder.FormatFrame(frame).c_str());
  }
  }
  return true;
  return true;
}
}
+1 −1
Original line number Original line Diff line number Diff line
@@ -175,7 +175,7 @@ cc_binary_host {
    ],
    ],
    shared_libs: [
    shared_libs: [
        "liblog",
        "liblog",
        "libbacktrace",
        "libunwindstack",
    ],
    ],
    whole_static_libs: [
    whole_static_libs: [
        "libbt-rootcanal",
        "libbt-rootcanal",
+10 −14
Original line number Original line Diff line number Diff line
@@ -13,12 +13,12 @@
// See the License for the specific language governing permissions and
// See the License for the specific language governing permissions and
// limitations under the License.
// limitations under the License.
//
//
#include <backtrace/Backtrace.h>
#include <backtrace/backtrace_constants.h>
#include <client/linux/handler/exception_handler.h>
#include <client/linux/handler/exception_handler.h>
#include <gflags/gflags.h>
#include <gflags/gflags.h>
#include <unwindstack/AndroidUnwinder.h>


#include <future>
#include <future>
#include <optional>


#include "model/setup/async_manager.h"
#include "model/setup/async_manager.h"
#include "net/posix/posix_async_socket_connector.h"
#include "net/posix/posix_async_socket_connector.h"
@@ -48,32 +48,28 @@ extern "C" const char* __asan_default_options() {


bool crash_callback(const void* crash_context, size_t crash_context_size,
bool crash_callback(const void* crash_context, size_t crash_context_size,
                    void* /* context */) {
                    void* /* context */) {
  pid_t tid = BACKTRACE_CURRENT_THREAD;
  std::optional<pid_t> tid;
  if (crash_context_size >=
  if (crash_context_size >=
      sizeof(google_breakpad::ExceptionHandler::CrashContext)) {
      sizeof(google_breakpad::ExceptionHandler::CrashContext)) {
    auto* ctx =
    auto* ctx =
        static_cast<const google_breakpad::ExceptionHandler::CrashContext*>(
        static_cast<const google_breakpad::ExceptionHandler::CrashContext*>(
            crash_context);
            crash_context);
    tid = ctx->tid;
    *tid = ctx->tid;
    int signal_number = ctx->siginfo.si_signo;
    int signal_number = ctx->siginfo.si_signo;
    LOG_ERROR("Process crashed, signal: %s[%d], tid: %d",
    LOG_ERROR("Process crashed, signal: %s[%d], tid: %d",
              strsignal(signal_number), signal_number, ctx->tid);
              strsignal(signal_number), signal_number, ctx->tid);
  } else {
  } else {
    LOG_ERROR("Process crashed, signal: unknown, tid: unknown");
    LOG_ERROR("Process crashed, signal: unknown, tid: unknown");
  }
  }
  std::unique_ptr<Backtrace> backtrace(
  unwindstack::AndroidLocalUnwinder unwinder;
      Backtrace::Create(BACKTRACE_CURRENT_PROCESS, tid));
  unwindstack::AndroidUnwinderData data;
  if (backtrace == nullptr) {
  if (!unwinder.Unwind(tid, data)) {
    LOG_ERROR("Failed to create backtrace object");
    LOG_ERROR("Unwind failed");
    return false;
  }
  if (!backtrace->Unwind(0)) {
    LOG_ERROR("backtrace->Unwind failed");
    return false;
    return false;
  }
  }
  LOG_ERROR("Backtrace:");
  LOG_ERROR("Backtrace:");
  for (size_t i = 0; i < backtrace->NumFrames(); i++) {
  for (const auto& frame : data.frames) {
    LOG_ERROR("%s", backtrace->FormatFrameData(i).c_str());
    LOG_ERROR("%s", unwinder.FormatFrame(frame).c_str());
  }
  }
  return true;
  return true;
}
}