#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "client/linux/dump_writer_common/thread_info.h"
#include <string.h>
#include <assert.h>
#include "common/linux/linux_libc_support.h"
#include "google_breakpad/common/minidump_format.h"
namespace {
#if defined(__i386__)
void U16(void* out, uint16_t v) {
my_memcpy(out, &v, sizeof(v));
}
void U32(void* out, uint32_t v) {
my_memcpy(out, &v, sizeof(v));
}
#endif
}
namespace google_breakpad {
#if defined(__i386__)
uintptr_t ThreadInfo::GetInstructionPointer() const {
return regs.eip;
}
void ThreadInfo::FillCPUContext(RawContextCPU* out) const {
out->context_flags = MD_CONTEXT_X86_ALL;
out->dr0 = dregs[0];
out->dr1 = dregs[1];
out->dr2 = dregs[2];
out->dr3 = dregs[3];
out->dr6 = dregs[6];
out->dr7 = dregs[7];
out->gs = regs.xgs;
out->fs = regs.xfs;
out->es = regs.xes;
out->ds = regs.xds;
out->edi = regs.edi;
out->esi = regs.esi;
out->ebx = regs.ebx;
out->edx = regs.edx;
out->ecx = regs.ecx;
out->eax = regs.eax;
out->ebp = regs.ebp;
out->eip = regs.eip;
out->cs = regs.xcs;
out->eflags = regs.eflags;
out->esp = regs.esp;
out->ss = regs.xss;
out->float_save.control_word = fpregs.cwd;
out->float_save.status_word = fpregs.swd;
out->float_save.tag_word = fpregs.twd;
out->float_save.error_offset = fpregs.fip;
out->float_save.error_selector = fpregs.fcs;
out->float_save.data_offset = fpregs.foo;
out->float_save.data_selector = fpregs.fos;
my_memcpy(out->float_save.register_area, fpregs.st_space, 10 * 8);
U16(out->extended_registers + 0, fpregs.cwd);
U16(out->extended_registers + 2, fpregs.swd);
U16(out->extended_registers + 4, fpregs.twd);
U16(out->extended_registers + 6, fpxregs.fop);
U32(out->extended_registers + 8, fpxregs.fip);
U16(out->extended_registers + 12, fpxregs.fcs);
U32(out->extended_registers + 16, fpregs.foo);
U16(out->extended_registers + 20, fpregs.fos);
U32(out->extended_registers + 24, fpxregs.mxcsr);
my_memcpy(out->extended_registers + 32, &fpxregs.st_space, 128);
my_memcpy(out->extended_registers + 160, &fpxregs.xmm_space, 128);
}
#elif defined(__x86_64)
uintptr_t ThreadInfo::GetInstructionPointer() const { … }
void ThreadInfo::FillCPUContext(RawContextCPU* out) const { … }
#elif defined(__ARM_EABI__)
uintptr_t ThreadInfo::GetInstructionPointer() const {
return regs.uregs[15];
}
void ThreadInfo::FillCPUContext(RawContextCPU* out) const {
out->context_flags = MD_CONTEXT_ARM_FULL;
for (int i = 0; i < MD_CONTEXT_ARM_GPR_COUNT; ++i)
out->iregs[i] = regs.uregs[i];
out->cpsr = 0;
#if !defined(__ANDROID__)
out->float_save.fpscr = fpregs.fpsr |
(static_cast<uint64_t>(fpregs.fpcr) << 32);
my_memset(&out->float_save.regs, 0, sizeof(out->float_save.regs));
my_memset(&out->float_save.extra, 0, sizeof(out->float_save.extra));
#endif
}
#elif defined(__aarch64__)
uintptr_t ThreadInfo::GetInstructionPointer() const {
return regs.pc;
}
void ThreadInfo::FillCPUContext(RawContextCPU* out) const {
out->context_flags = MD_CONTEXT_ARM64_FULL_OLD;
out->cpsr = static_cast<uint32_t>(regs.pstate);
for (int i = 0; i < MD_CONTEXT_ARM64_REG_SP; ++i)
out->iregs[i] = regs.regs[i];
out->iregs[MD_CONTEXT_ARM64_REG_SP] = regs.sp;
out->iregs[MD_CONTEXT_ARM64_REG_PC] = regs.pc;
out->float_save.fpsr = fpregs.fpsr;
out->float_save.fpcr = fpregs.fpcr;
my_memcpy(&out->float_save.regs, &fpregs.vregs,
MD_FLOATINGSAVEAREA_ARM64_FPR_COUNT * 16);
}
#elif defined(__mips__)
uintptr_t ThreadInfo::GetInstructionPointer() const {
return mcontext.pc;
}
void ThreadInfo::FillCPUContext(RawContextCPU* out) const {
#if _MIPS_SIM == _ABI64
out->context_flags = MD_CONTEXT_MIPS64_FULL;
#elif _MIPS_SIM == _ABIO32
out->context_flags = MD_CONTEXT_MIPS_FULL;
#else
# error "This mips ABI is currently not supported (n32)"
#endif
for (int i = 0; i < MD_CONTEXT_MIPS_GPR_COUNT; ++i)
out->iregs[i] = mcontext.gregs[i];
out->mdhi = mcontext.mdhi;
out->mdlo = mcontext.mdlo;
out->dsp_control = mcontext.dsp;
out->hi[0] = mcontext.hi1;
out->lo[0] = mcontext.lo1;
out->hi[1] = mcontext.hi2;
out->lo[1] = mcontext.lo2;
out->hi[2] = mcontext.hi3;
out->lo[2] = mcontext.lo3;
out->epc = mcontext.pc;
out->badvaddr = 0;
out->status = 0;
out->cause = 0;
for (int i = 0; i < MD_FLOATINGSAVEAREA_MIPS_FPR_COUNT; ++i)
out->float_save.regs[i] = mcontext.fpregs.fp_r.fp_fregs[i]._fp_fregs;
out->float_save.fpcsr = mcontext.fpc_csr;
#if _MIPS_SIM == _ABIO32
out->float_save.fir = mcontext.fpc_eir;
#endif
}
#elif defined(__riscv)
uintptr_t ThreadInfo::GetInstructionPointer() const {
return mcontext.__gregs[0];
}
void ThreadInfo::FillCPUContext(RawContextCPU* out) const {
# if __riscv__xlen == 32
out->context_flags = MD_CONTEXT_RISCV_FULL;
# elif __riscv_xlen == 64
out->context_flags = MD_CONTEXT_RISCV64_FULL;
# else
# error "Unexpected __riscv_xlen"
# endif
out->pc = mcontext.__gregs[0];
out->ra = mcontext.__gregs[1];
out->sp = mcontext.__gregs[2];
out->gp = mcontext.__gregs[3];
out->tp = mcontext.__gregs[4];
out->t0 = mcontext.__gregs[5];
out->t1 = mcontext.__gregs[6];
out->t2 = mcontext.__gregs[7];
out->s0 = mcontext.__gregs[8];
out->s1 = mcontext.__gregs[9];
out->a0 = mcontext.__gregs[10];
out->a1 = mcontext.__gregs[11];
out->a2 = mcontext.__gregs[12];
out->a3 = mcontext.__gregs[13];
out->a4 = mcontext.__gregs[14];
out->a5 = mcontext.__gregs[15];
out->a6 = mcontext.__gregs[16];
out->a7 = mcontext.__gregs[17];
out->s2 = mcontext.__gregs[18];
out->s3 = mcontext.__gregs[19];
out->s4 = mcontext.__gregs[20];
out->s5 = mcontext.__gregs[21];
out->s6 = mcontext.__gregs[22];
out->s7 = mcontext.__gregs[23];
out->s8 = mcontext.__gregs[24];
out->s9 = mcontext.__gregs[25];
out->s10 = mcontext.__gregs[26];
out->s11 = mcontext.__gregs[27];
out->t3 = mcontext.__gregs[28];
out->t4 = mcontext.__gregs[29];
out->t5 = mcontext.__gregs[30];
out->t6 = mcontext.__gregs[31];
#if __riscv_xlen == 32
for (int i = 0; i < MD_CONTEXT_RISCV_FPR_COUNT; i++)
out->fpregs[i] = mcontext.__fpregs.__f.__f[i];
out->fcsr = mcontext.__fpregs.__f.__fcsr;
#elif __riscv_xlen == 64
for (int i = 0; i < MD_CONTEXT_RISCV_FPR_COUNT; i++)
out->fpregs[i] = mcontext.__fpregs.__d.__f[i];
out->fcsr = mcontext.__fpregs.__d.__fcsr;
#else
#error "Unexpected __riscv_xlen"
#endif
}
#endif
void ThreadInfo::GetGeneralPurposeRegisters(void** gp_regs, size_t* size) { … }
void ThreadInfo::GetFloatingPointRegisters(void** fp_regs, size_t* size) { … }
}