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

Commit 5434bf66 authored by Elliott Hughes's avatar Elliott Hughes Committed by Gerrit Code Review
Browse files

Merge "LP64: Enable debuggerd/libbacktrace/libunwind."

parents 469f1533 c6c194ce
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
# Copyright 2005 The Android Open Source Project

ifneq ($(filter arm mips x86,$(TARGET_ARCH)),)
ifneq ($(filter arm mips x86 x86_64,$(TARGET_ARCH)),)

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
@@ -19,6 +19,7 @@ LOCAL_CFLAGS := \
	-Wall \
	-Wno-array-bounds \
	-Werror \
	-Wno-unused-parameter \

LOCAL_MODULE := debuggerd

debuggerd/tombstone.cpp

100644 → 100755
+18 −27
Original line number Diff line number Diff line
@@ -179,9 +179,9 @@ static void dump_fault_addr(log_t* log, pid_t tid, int sig) {
  if (ptrace(PTRACE_GETSIGINFO, tid, 0, &si)){
    _LOG(log, SCOPE_AT_FAULT, "cannot get siginfo: %s\n", strerror(errno));
  } else if (signal_has_address(sig)) {
    _LOG(log, SCOPE_AT_FAULT, "signal %d (%s), code %d (%s), fault addr %0*" PRIxPTR "\n",
    _LOG(log, SCOPE_AT_FAULT, "signal %d (%s), code %d (%s), fault addr %" PRIPTR "\n",
         sig, get_signame(sig), si.si_code, get_sigcode(sig, si.si_code),
         sizeof(uintptr_t)*2, reinterpret_cast<uintptr_t>(si.si_addr));
         reinterpret_cast<uintptr_t>(si.si_addr));
  } else {
    _LOG(log, SCOPE_AT_FAULT, "signal %d (%s), code %d (%s), fault addr --------\n",
         sig, get_signame(sig), si.si_code, get_sigcode(sig, si.si_code));
@@ -226,7 +226,7 @@ static void dump_thread_info(log_t* log, pid_t pid, pid_t tid, int scope_flags)
static void dump_stack_segment(
    Backtrace* backtrace, log_t* log, int scope_flags, uintptr_t* sp, size_t words, int label) {
  for (size_t i = 0; i < words; i++) {
    uint32_t stack_content;
    word_t stack_content;
    if (!backtrace->ReadWord(*sp, &stack_content)) {
      break;
    }
@@ -243,32 +243,32 @@ static void dump_stack_segment(
    if (!func_name.empty()) {
      if (!i && label >= 0) {
        if (offset) {
          _LOG(log, scope_flags, "    #%02d  %08x  %08x  %s (%s+%u)\n",
          _LOG(log, scope_flags, "    #%02d  %" PRIPTR "  %" PRIPTR "  %s (%s+%" PRIxPTR "u)\n",
               label, *sp, stack_content, map_name, func_name.c_str(), offset);
        } else {
          _LOG(log, scope_flags, "    #%02d  %08x  %08x  %s (%s)\n",
          _LOG(log, scope_flags, "    #%02d  %" PRIPTR "  %" PRIPTR "  %s (%s)\n",
               label, *sp, stack_content, map_name, func_name.c_str());
        }
      } else {
        if (offset) {
          _LOG(log, scope_flags, "         %08x  %08x  %s (%s+%u)\n",
          _LOG(log, scope_flags, "         %" PRIPTR "  %" PRIPTR "  %s (%s+%" PRIxPTR "u)\n",
               *sp, stack_content, map_name, func_name.c_str(), offset);
        } else {
          _LOG(log, scope_flags, "         %08x  %08x  %s (%s)\n",
          _LOG(log, scope_flags, "         %" PRIPTR "  %" PRIPTR "  %s (%s)\n",
               *sp, stack_content, map_name, func_name.c_str());
        }
      }
    } else {
      if (!i && label >= 0) {
        _LOG(log, scope_flags, "    #%02d  %08x  %08x  %s\n",
        _LOG(log, scope_flags, "    #%02d  %" PRIPTR "  %" PRIPTR "  %s\n",
             label, *sp, stack_content, map_name);
      } else {
        _LOG(log, scope_flags, "         %08x  %08x  %s\n",
        _LOG(log, scope_flags, "         %" PRIPTR "  %" PRIPTR "  %s\n",
             *sp, stack_content, map_name);
      }
    }

    *sp += sizeof(uint32_t);
    *sp += sizeof(word_t);
  }
}

@@ -291,7 +291,7 @@ static void dump_stack(Backtrace* backtrace, log_t* log, int scope_flags) {
  scope_flags |= SCOPE_SENSITIVE;

  // Dump a few words before the first frame.
  uintptr_t sp = backtrace->GetFrame(first)->sp - STACK_WORDS * sizeof(uint32_t);
  word_t sp = backtrace->GetFrame(first)->sp - STACK_WORDS * sizeof(word_t);
  dump_stack_segment(backtrace, log, scope_flags, &sp, STACK_WORDS, -1);

  // Dump a few words from all successive frames.
@@ -311,7 +311,7 @@ static void dump_stack(Backtrace* backtrace, log_t* log, int scope_flags) {
        _LOG(log, scope_flags, "         ........  ........\n");
      }
    } else {
      size_t words = frame->stack_size / sizeof(uint32_t);
      size_t words = frame->stack_size / sizeof(word_t);
      if (words == 0) {
        words = 1;
      } else if (words > STACK_WORDS) {
@@ -334,7 +334,7 @@ static void dump_backtrace_and_stack(Backtrace* backtrace, log_t* log, int scope

static void dump_map(log_t* log, const backtrace_map_t* map, const char* what, int scope_flags) {
  if (map != NULL) {
    _LOG(log, scope_flags, "    %08x-%08x %c%c%c %s\n", map->start, map->end,
    _LOG(log, scope_flags, "    %" PRIPTR "-%" PRIPTR " %c%c%c %s\n", map->start, map->end,
         (map->flags & PROT_READ) ? 'r' : '-', (map->flags & PROT_WRITE) ? 'w' : '-',
         (map->flags & PROT_EXEC) ? 'x' : '-', map->name.c_str());
  } else {
@@ -573,24 +573,15 @@ static void dump_abort_message(Backtrace* backtrace, log_t* log, uintptr_t addre
  memset(msg, 0, sizeof(msg));
  char* p = &msg[0];
  while (p < &msg[sizeof(msg)]) {
    uint32_t data;
    word_t data;
    size_t len = sizeof(word_t);
    if (!backtrace->ReadWord(address, &data)) {
      break;
    }
    address += sizeof(uint32_t);
    address += sizeof(word_t);

    if ((*p++ = (data >>  0) & 0xff) == 0) {
      break;
    }
    if ((*p++ = (data >>  8) & 0xff) == 0) {
      break;
    }
    if ((*p++ = (data >> 16) & 0xff) == 0) {
      break;
    }
    if ((*p++ = (data >> 24) & 0xff) == 0) {
      break;
    }
    while (len > 0 && (*p++ = (data >> (sizeof(word_t) - len) * 8) & 0xff) != 0)
       len--;
  }
  msg[sizeof(msg) - 1] = '\0';

+19 −28
Original line number Diff line number Diff line
@@ -14,19 +14,17 @@
 * limitations under the License.
 */

#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include "utility.h"

#include <errno.h>
#include <unistd.h>
#include <signal.h>
#include <log/logd.h>
#include <string.h>
#include <unistd.h>
#include <sys/ptrace.h>
#include <sys/wait.h>
#include <arpa/inet.h>
#include <assert.h>

#include "utility.h"
#include <backtrace/Backtrace.h>
#include <log/logd.h>

const int sleep_time_usec = 50000;         // 0.05 seconds
const int max_total_sleep_usec = 10000000; // 10 seconds
@@ -46,34 +44,28 @@ static int write_to_am(int fd, const char* buf, int len) {
}

void _LOG(log_t* log, int scopeFlags, const char* fmt, ...) {
  char buf[512];
  bool want_tfd_write;
  bool want_log_write;
  bool want_amfd_write;
  int len = 0;
  bool want_tfd_write = log && log->tfd >= 0;
  bool want_log_write = IS_AT_FAULT(scopeFlags) && (!log || !log->quiet);
  bool want_amfd_write = IS_AT_FAULT(scopeFlags) && !IS_SENSITIVE(scopeFlags) && log && log->amfd >= 0;

  char buf[512];
  va_list ap;
  va_start(ap, fmt);

  // where is the information going to go?
  want_tfd_write = log && log->tfd >= 0;
  want_log_write = IS_AT_FAULT(scopeFlags) && (!log || !log->quiet);
  want_amfd_write = IS_AT_FAULT(scopeFlags) && !IS_SENSITIVE(scopeFlags) && log && log->amfd >= 0;

  // if we're going to need the literal string, generate it once here
  if (want_tfd_write || want_amfd_write) {
  vsnprintf(buf, sizeof(buf), fmt, ap);
    len = strlen(buf);
  va_end(ap);

  size_t len = strlen(buf);
  if (len <= 0) {
    return;
  }

  if (want_tfd_write) {
    write(log->tfd, buf, len);
    TEMP_FAILURE_RETRY(write(log->tfd, buf, len));
  }

  if (want_log_write) {
    // whatever goes to logcat also goes to the Activity Manager
    __android_log_vprint(ANDROID_LOG_INFO, "DEBUG", fmt, ap);
    if (want_amfd_write && len > 0) {
    __android_log_write(ANDROID_LOG_INFO, "DEBUG", buf);
    if (want_amfd_write) {
      int written = write_to_am(log->amfd, buf, len);
      if (written <= 0) {
        // timeout or other failure on write; stop informing the activity manager
@@ -81,7 +73,6 @@ void _LOG(log_t* log, int scopeFlags, const char* fmt, ...) {
      }
    }
  }
  va_end(ap);
}

int wait_for_signal(pid_t tid, int* total_sleep_time_usec) {
+1 −10
Original line number Diff line number Diff line
@@ -18,9 +18,8 @@
#ifndef _DEBUGGERD_UTILITY_H
#define _DEBUGGERD_UTILITY_H

#include <inttypes.h>
#include <stdbool.h>
#include <stddef.h>
#include <sys/types.h>

typedef struct {
    /* tombstone file descriptor */
@@ -61,14 +60,6 @@ void _LOG(log_t* log, int scopeFlags, const char *fmt, ...)
#define XLOG2(fmt...) do {} while(0)
#endif

#if __LP64__
#define PRIPTR "016" PRIxPTR
typedef uint64_t word_t;
#else
#define PRIPTR "08" PRIxPTR
typedef uint32_t word_t;
#endif

int wait_for_signal(pid_t tid, int* total_sleep_time_usec);
void wait_for_stop(pid_t tid, int* total_sleep_time_usec);

+15 −0
Original line number Diff line number Diff line
.globl crash1
.globl crashnostack

crash1:
	movl $0xa5a50000, %eax
	movl $0xa5a50001, %ebx
	movl $0xa5a50002, %ecx

	movl $0, %edx
	jmp *%rdx


crashnostack:
	movl $0, %ebp
	jmp *%rbp
Loading