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

Commit 3091f136 authored by Christopher Ferris's avatar Christopher Ferris Committed by Automerger Merge Worker
Browse files

Merge "Move from libbacktrace libunwindstack." am: 635050b8

parents 9c2ecce1 635050b8
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -270,13 +270,13 @@ cc_binary {
        "libbluetooth_rust_interop",
    ],
    shared_libs: [
        "libbacktrace",
        "libchrome",
        "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;
}