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

Commit 64be1dcc authored by Christopher Ferris's avatar Christopher Ferris Committed by Cherrypicker Worker
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

Change-Id: I690e23c4eadd7a9e3f33eb246f4458d23eb03df0
parent dff56dce
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -277,12 +277,12 @@ cc_binary {
        "libbt_shim_ffi",
    ],
    shared_libs: [
        "libbacktrace",
        "libcrypto",
        "libgrpc++",
        "libgrpc++_unsecure",
        "libgrpc_wrap",
        "libprotobuf-cpp-full",
        "libunwindstack",
    ],
    target: {
        android: {
+10 −13
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include <csignal>
#include <cstring>
#include <memory>
#include <optional>
#include <string>
#include <thread>

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

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

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

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

#include <future>
#include <optional>

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