am 6a8ed4b6: am d3e877f8: am ad571cdd: Merge "Add backtrace support for mips64."

* commit '6a8ed4b6c05fe471e2398a7be1c48695e4c49194':
  Add backtrace support for mips64.
This commit is contained in:
Elliott Hughes 2015-03-10 22:04:43 +00:00 committed by Android Git Automerger
commit f50fccb246
4 changed files with 153 additions and 3 deletions

View File

@ -12,7 +12,7 @@ LOCAL_SRC_FILES:= \
LOCAL_SRC_FILES_arm := arm/machine.cpp
LOCAL_SRC_FILES_arm64 := arm64/machine.cpp
LOCAL_SRC_FILES_mips := mips/machine.cpp
LOCAL_SRC_FILES_mips64 := mips/machine.cpp
LOCAL_SRC_FILES_mips64 := mips64/machine.cpp
LOCAL_SRC_FILES_x86 := x86/machine.cpp
LOCAL_SRC_FILES_x86_64 := x86_64/machine.cpp
@ -49,7 +49,7 @@ LOCAL_SRC_FILES := crasher.c
LOCAL_SRC_FILES_arm := arm/crashglue.S
LOCAL_SRC_FILES_arm64 := arm64/crashglue.S
LOCAL_SRC_FILES_mips := mips/crashglue.S
LOCAL_SRC_FILES_mips64 := mips/crashglue.S
LOCAL_SRC_FILES_mips64 := mips64/crashglue.S
LOCAL_SRC_FILES_x86 := x86/crashglue.S
LOCAL_SRC_FILES_x86_64 := x86_64/crashglue.S
LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES)

View File

@ -0,0 +1,48 @@
.set noat
.globl crash1
.globl crashnostack
crash1:
li $0,0xdead0000+0
li $1,0xdead0000+1
li $2,0xdead0000+2
li $3,0xdead0000+3
li $4,0xdead0000+4
li $5,0xdead0000+5
li $6,0xdead0000+6
li $7,0xdead0000+7
li $8,0xdead0000+8
li $9,0xdead0000+9
li $10,0xdead0000+10
li $11,0xdead0000+11
li $12,0xdead0000+12
li $13,0xdead0000+13
li $14,0xdead0000+14
li $15,0xdead0000+15
li $16,0xdead0000+16
li $17,0xdead0000+17
li $18,0xdead0000+18
li $19,0xdead0000+19
li $20,0xdead0000+20
li $21,0xdead0000+21
li $22,0xdead0000+22
li $23,0xdead0000+23
li $24,0xdead0000+24
li $25,0xdead0000+25
li $26,0xdead0000+26
li $27,0xdead0000+27
li $28,0xdead0000+28
# don't trash the stack otherwise the signal handler won't run
#li $29,0xdead0000+29
li $30,0xdead0000+30
li $31,0xdead0000+31
lw $zero,($0)
b .
crashnostack:
li $sp, 0
lw $zero,($0)
b .

View File

@ -0,0 +1,100 @@
/*
* Copyright 2014, The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/ptrace.h>
#include <sys/user.h>
#include "../utility.h"
#include "../machine.h"
#define R(x) (static_cast<unsigned long>(x))
// If configured to do so, dump memory around *all* registers
// for the crashing thread.
void dump_memory_and_code(log_t* log, pid_t tid) {
pt_regs r;
if (ptrace(PTRACE_GETREGS, tid, 0, &r)) {
return;
}
static const char REG_NAMES[] = "$0atv0v1a0a1a2a3a4a5a6a7t0t1t2t3s0s1s2s3s4s5s6s7t8t9k0k1gpsps8ra";
for (int reg = 0; reg < 32; reg++) {
// skip uninteresting registers
if (reg == 0 // $0
|| reg == 26 // $k0
|| reg == 27 // $k1
|| reg == 31 // $ra (done below)
)
continue;
uintptr_t addr = R(r.regs[reg]);
// Don't bother if it looks like a small int or ~= null, or if
// it's in the kernel area.
if (addr < 4096 || addr >= 0x4000000000000000) {
continue;
}
_LOG(log, logtype::MEMORY, "\nmemory near %.2s:\n", &REG_NAMES[reg * 2]);
dump_memory(log, tid, addr);
}
unsigned long pc = R(r.cp0_epc);
unsigned long ra = R(r.regs[31]);
_LOG(log, logtype::MEMORY, "\ncode around pc:\n");
dump_memory(log, tid, (uintptr_t)pc);
if (pc != ra) {
_LOG(log, logtype::MEMORY, "\ncode around ra:\n");
dump_memory(log, tid, (uintptr_t)ra);
}
}
void dump_registers(log_t* log, pid_t tid) {
pt_regs r;
if(ptrace(PTRACE_GETREGS, tid, 0, &r)) {
_LOG(log, logtype::ERROR, "cannot get registers: %s\n", strerror(errno));
return;
}
_LOG(log, logtype::REGISTERS, " zr %016lx at %016lx v0 %016lx v1 %016lx\n",
R(r.regs[0]), R(r.regs[1]), R(r.regs[2]), R(r.regs[3]));
_LOG(log, logtype::REGISTERS, " a0 %016lx a1 %016lx a2 %016lx a3 %016lx\n",
R(r.regs[4]), R(r.regs[5]), R(r.regs[6]), R(r.regs[7]));
_LOG(log, logtype::REGISTERS, " a4 %016lx a5 %016lx a6 %016lx a7 %016lx\n",
R(r.regs[8]), R(r.regs[9]), R(r.regs[10]), R(r.regs[11]));
_LOG(log, logtype::REGISTERS, " t0 %016lx t1 %016lx t2 %016lx t3 %016lx\n",
R(r.regs[12]), R(r.regs[13]), R(r.regs[14]), R(r.regs[15]));
_LOG(log, logtype::REGISTERS, " s0 %016lx s1 %016lx s2 %016lx s3 %016lx\n",
R(r.regs[16]), R(r.regs[17]), R(r.regs[18]), R(r.regs[19]));
_LOG(log, logtype::REGISTERS, " s4 %016lx s5 %016lx s6 %016lx s7 %016lx\n",
R(r.regs[20]), R(r.regs[21]), R(r.regs[22]), R(r.regs[23]));
_LOG(log, logtype::REGISTERS, " t8 %016lx t9 %016lx k0 %016lx k1 %016lx\n",
R(r.regs[24]), R(r.regs[25]), R(r.regs[26]), R(r.regs[27]));
_LOG(log, logtype::REGISTERS, " gp %016lx sp %016lx s8 %016lx ra %016lx\n",
R(r.regs[28]), R(r.regs[29]), R(r.regs[30]), R(r.regs[31]));
_LOG(log, logtype::REGISTERS, " hi %016lx lo %016lx bva %016lx epc %016lx\n",
R(r.hi), R(r.lo), R(r.cp0_badvaddr), R(r.cp0_epc));
}

View File

@ -26,8 +26,10 @@
#define ABI_STRING "arm"
#elif defined(__aarch64__)
#define ABI_STRING "arm64"
#elif defined(__mips__)
#elif defined(__mips__) && !defined(__LP64__)
#define ABI_STRING "mips"
#elif defined(__mips__) && defined(__LP64__)
#define ABI_STRING "mips64"
#elif defined(__i386__)
#define ABI_STRING "x86"
#elif defined(__x86_64__)