|
Packit |
6c4009 |
/* Dump registers.
|
|
Packit |
6c4009 |
Copyright (C) 1998-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
This file is part of the GNU C Library.
|
|
Packit |
6c4009 |
Contributed by Philip Blundell <pb@nexus.co.uk>, 1998.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit |
6c4009 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License as published by the Free Software Foundation; either
|
|
Packit |
6c4009 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit |
6c4009 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6c4009 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6c4009 |
Lesser General Public License for more details.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License along with the GNU C Library. If not, see
|
|
Packit |
6c4009 |
<http://www.gnu.org/licenses/>. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <sys/uio.h>
|
|
Packit |
6c4009 |
#include <_itoa.h>
|
|
Packit |
6c4009 |
#include <sys/ucontext.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* We will print the register dump in this format:
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
R0: XXXXXXXX R1: XXXXXXXX R2: XXXXXXXX R3: XXXXXXXX
|
|
Packit |
6c4009 |
R4: XXXXXXXX R5: XXXXXXXX R6: XXXXXXXX R7: XXXXXXXX
|
|
Packit |
6c4009 |
R8: XXXXXXXX R9: XXXXXXXX SL: XXXXXXXX FP: XXXXXXXX
|
|
Packit |
6c4009 |
IP: XXXXXXXX SP: XXXXXXXX LR: XXXXXXXX PC: XXXXXXXX
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
CPSR: XXXXXXXX
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
Trap: XXXXXXXX Error: XXXXXXXX OldMask: XXXXXXXX
|
|
Packit |
6c4009 |
Addr: XXXXXXXX
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
*/
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static void
|
|
Packit |
6c4009 |
hexvalue (unsigned long int value, char *buf, size_t len)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
char *cp = _itoa_word (value, buf + len, 16, 0);
|
|
Packit |
6c4009 |
while (cp > buf)
|
|
Packit |
6c4009 |
*--cp = '0';
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static void
|
|
Packit |
6c4009 |
register_dump (int fd, const ucontext_t *ctx)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
char regs[21][8];
|
|
Packit |
6c4009 |
struct iovec iov[97];
|
|
Packit |
6c4009 |
size_t nr = 0;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#define ADD_STRING(str) \
|
|
Packit |
6c4009 |
iov[nr].iov_base = (char *) str; \
|
|
Packit |
6c4009 |
iov[nr].iov_len = strlen (str); \
|
|
Packit |
6c4009 |
++nr
|
|
Packit |
6c4009 |
#define ADD_MEM(str, len) \
|
|
Packit |
6c4009 |
iov[nr].iov_base = str; \
|
|
Packit |
6c4009 |
iov[nr].iov_len = len; \
|
|
Packit |
6c4009 |
++nr
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Generate strings of register contents. */
|
|
Packit |
6c4009 |
hexvalue (ctx->uc_mcontext.arm_r0, regs[0], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->uc_mcontext.arm_r1, regs[1], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->uc_mcontext.arm_r2, regs[2], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->uc_mcontext.arm_r3, regs[3], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->uc_mcontext.arm_r4, regs[4], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->uc_mcontext.arm_r5, regs[5], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->uc_mcontext.arm_r6, regs[6], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->uc_mcontext.arm_r7, regs[7], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->uc_mcontext.arm_r8, regs[8], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->uc_mcontext.arm_r9, regs[9], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->uc_mcontext.arm_r10, regs[10], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->uc_mcontext.arm_fp, regs[11], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->uc_mcontext.arm_ip, regs[12], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->uc_mcontext.arm_sp, regs[13], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->uc_mcontext.arm_lr, regs[14], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->uc_mcontext.arm_pc, regs[15], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->uc_mcontext.arm_cpsr, regs[16], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->uc_mcontext.trap_no, regs[17], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->uc_mcontext.error_code, regs[18], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->uc_mcontext.oldmask, regs[19], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->uc_mcontext.fault_address, regs[20], 8);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Generate the output. */
|
|
Packit |
6c4009 |
ADD_STRING ("Register dump:\n\n R0: ");
|
|
Packit |
6c4009 |
ADD_MEM (regs[0], 8);
|
|
Packit |
6c4009 |
ADD_STRING (" R1: ");
|
|
Packit |
6c4009 |
ADD_MEM (regs[1], 8);
|
|
Packit |
6c4009 |
ADD_STRING (" R2: ");
|
|
Packit |
6c4009 |
ADD_MEM (regs[2], 8);
|
|
Packit |
6c4009 |
ADD_STRING (" R3: ");
|
|
Packit |
6c4009 |
ADD_MEM (regs[3], 8);
|
|
Packit |
6c4009 |
ADD_STRING ("\n R4: ");
|
|
Packit |
6c4009 |
ADD_MEM (regs[4], 8);
|
|
Packit |
6c4009 |
ADD_STRING (" R5: ");
|
|
Packit |
6c4009 |
ADD_MEM (regs[5], 8);
|
|
Packit |
6c4009 |
ADD_STRING (" R6: ");
|
|
Packit |
6c4009 |
ADD_MEM (regs[6], 8);
|
|
Packit |
6c4009 |
ADD_STRING (" R7: ");
|
|
Packit |
6c4009 |
ADD_MEM (regs[7], 8);
|
|
Packit |
6c4009 |
ADD_STRING ("\n R8: ");
|
|
Packit |
6c4009 |
ADD_MEM (regs[8], 8);
|
|
Packit |
6c4009 |
ADD_STRING (" R9: ");
|
|
Packit |
6c4009 |
ADD_MEM (regs[9], 8);
|
|
Packit |
6c4009 |
ADD_STRING (" SL: ");
|
|
Packit |
6c4009 |
ADD_MEM (regs[10], 8);
|
|
Packit |
6c4009 |
ADD_STRING (" FP: ");
|
|
Packit |
6c4009 |
ADD_MEM (regs[11], 8);
|
|
Packit |
6c4009 |
ADD_STRING ("\n IP: ");
|
|
Packit |
6c4009 |
ADD_MEM (regs[12], 8);
|
|
Packit |
6c4009 |
ADD_STRING (" SP: ");
|
|
Packit |
6c4009 |
ADD_MEM (regs[13], 8);
|
|
Packit |
6c4009 |
ADD_STRING (" LR: ");
|
|
Packit |
6c4009 |
ADD_MEM (regs[14], 8);
|
|
Packit |
6c4009 |
ADD_STRING (" PC: ");
|
|
Packit |
6c4009 |
ADD_MEM (regs[15], 8);
|
|
Packit |
6c4009 |
ADD_STRING ("\n\n CPSR: ");
|
|
Packit |
6c4009 |
ADD_MEM (regs[16], 8);
|
|
Packit |
6c4009 |
ADD_STRING ("\n\n Trap: ");
|
|
Packit |
6c4009 |
ADD_MEM (regs[17], 8);
|
|
Packit |
6c4009 |
ADD_STRING (" Error: ");
|
|
Packit |
6c4009 |
ADD_MEM (regs[18], 8);
|
|
Packit |
6c4009 |
ADD_STRING (" OldMask: ");
|
|
Packit |
6c4009 |
ADD_MEM (regs[19], 8);
|
|
Packit |
6c4009 |
ADD_STRING ("\n Addr: ");
|
|
Packit |
6c4009 |
ADD_MEM (regs[20], 8);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
ADD_STRING ("\n");
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Write the stuff out. */
|
|
Packit |
6c4009 |
writev (fd, iov, nr);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#define REGISTER_DUMP register_dump (fd, ctx)
|