|
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 Ulrich Drepper <drepper@cygnus.com>, 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 |
|
|
Packit |
6c4009 |
/* We will print the register dump in this format:
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
EAX: XXXXXXXX EBX: XXXXXXXX ECX: XXXXXXXX EDX: XXXXXXXX
|
|
Packit |
6c4009 |
ESI: XXXXXXXX EDI: XXXXXXXX EBP: XXXXXXXX ESP: XXXXXXXX
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
EIP: XXXXXXXX EFLAGS: XXXXXXXX
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
CS: XXXX DS: XXXX ES: XXXX FS: XXXX GS: XXXX SS: XXXX
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
Trap: XXXXXXXX Error: XXXXXXXX OldMask: XXXXXXXX
|
|
Packit |
6c4009 |
ESP/SIGNAL: XXXXXXXX CR2: XXXXXXXX
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
FPUCW: XXXXXXXX FPUSW: XXXXXXXX TAG: XXXXXXXX
|
|
Packit |
6c4009 |
IPOFF: XXXXXXXX CSSEL: XXXX DATAOFF: XXXXXXXX DATASEL: XXXX
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
ST(0) XXXX XXXXXXXXXXXXXXXX ST(1) XXXX XXXXXXXXXXXXXXXX
|
|
Packit |
6c4009 |
ST(2) XXXX XXXXXXXXXXXXXXXX ST(3) XXXX XXXXXXXXXXXXXXXX
|
|
Packit |
6c4009 |
ST(4) XXXX XXXXXXXXXXXXXXXX ST(5) XXXX XXXXXXXXXXXXXXXX
|
|
Packit |
6c4009 |
ST(6) XXXX XXXXXXXXXXXXXXXX ST(7) XXXX XXXXXXXXXXXXXXXX
|
|
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, struct sigcontext *ctx)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
char regs[21][8];
|
|
Packit |
6c4009 |
char fpregs[31][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->eax, regs[0], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->ebx, regs[1], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->ecx, regs[2], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->edx, regs[3], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->esi, regs[4], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->edi, regs[5], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->ebp, regs[6], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->esp, regs[7], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->eip, regs[8], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->eflags, regs[9], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->cs, regs[10], 4);
|
|
Packit |
6c4009 |
hexvalue (ctx->ds, regs[11], 4);
|
|
Packit |
6c4009 |
hexvalue (ctx->es, regs[12], 4);
|
|
Packit |
6c4009 |
hexvalue (ctx->fs, regs[13], 4);
|
|
Packit |
6c4009 |
hexvalue (ctx->gs, regs[14], 4);
|
|
Packit |
6c4009 |
hexvalue (ctx->ss, regs[15], 4);
|
|
Packit |
6c4009 |
hexvalue (ctx->trapno, regs[16], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->err, regs[17], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->oldmask, regs[18], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->esp_at_signal, regs[19], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->cr2, regs[20], 8);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Generate the output. */
|
|
Packit |
6c4009 |
ADD_STRING ("Register dump:\n\n EAX: ");
|
|
Packit |
6c4009 |
ADD_MEM (regs[0], 8);
|
|
Packit |
6c4009 |
ADD_STRING (" EBX: ");
|
|
Packit |
6c4009 |
ADD_MEM (regs[1], 8);
|
|
Packit |
6c4009 |
ADD_STRING (" ECX: ");
|
|
Packit |
6c4009 |
ADD_MEM (regs[2], 8);
|
|
Packit |
6c4009 |
ADD_STRING (" EDX: ");
|
|
Packit |
6c4009 |
ADD_MEM (regs[3], 8);
|
|
Packit |
6c4009 |
ADD_STRING ("\n ESI: ");
|
|
Packit |
6c4009 |
ADD_MEM (regs[4], 8);
|
|
Packit |
6c4009 |
ADD_STRING (" EDI: ");
|
|
Packit |
6c4009 |
ADD_MEM (regs[5], 8);
|
|
Packit |
6c4009 |
ADD_STRING (" EBP: ");
|
|
Packit |
6c4009 |
ADD_MEM (regs[6], 8);
|
|
Packit |
6c4009 |
ADD_STRING (" ESP: ");
|
|
Packit |
6c4009 |
ADD_MEM (regs[7], 8);
|
|
Packit |
6c4009 |
ADD_STRING ("\n\n EIP: ");
|
|
Packit |
6c4009 |
ADD_MEM (regs[8], 8);
|
|
Packit |
6c4009 |
ADD_STRING (" EFLAGS: ");
|
|
Packit |
6c4009 |
ADD_MEM (regs[9], 8);
|
|
Packit |
6c4009 |
ADD_STRING ("\n\n CS: ");
|
|
Packit |
6c4009 |
ADD_MEM (regs[10], 4);
|
|
Packit |
6c4009 |
ADD_STRING (" DS: ");
|
|
Packit |
6c4009 |
ADD_MEM (regs[11], 4);
|
|
Packit |
6c4009 |
ADD_STRING (" ES: ");
|
|
Packit |
6c4009 |
ADD_MEM (regs[12], 4);
|
|
Packit |
6c4009 |
ADD_STRING (" FS: ");
|
|
Packit |
6c4009 |
ADD_MEM (regs[13], 4);
|
|
Packit |
6c4009 |
ADD_STRING (" GS: ");
|
|
Packit |
6c4009 |
ADD_MEM (regs[14], 4);
|
|
Packit |
6c4009 |
ADD_STRING (" SS: ");
|
|
Packit |
6c4009 |
ADD_MEM (regs[15], 4);
|
|
Packit |
6c4009 |
ADD_STRING ("\n\n Trap: ");
|
|
Packit |
6c4009 |
ADD_MEM (regs[16], 8);
|
|
Packit |
6c4009 |
ADD_STRING (" Error: ");
|
|
Packit |
6c4009 |
ADD_MEM (regs[17], 8);
|
|
Packit |
6c4009 |
ADD_STRING (" OldMask: ");
|
|
Packit |
6c4009 |
ADD_MEM (regs[18], 8);
|
|
Packit |
6c4009 |
ADD_STRING ("\n ESP/signal: ");
|
|
Packit |
6c4009 |
ADD_MEM (regs[19], 8);
|
|
Packit |
6c4009 |
ADD_STRING (" CR2: ");
|
|
Packit |
6c4009 |
ADD_MEM (regs[20], 8);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (ctx->fpstate != NULL)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Generate output for the FPU control/status registers. */
|
|
Packit |
6c4009 |
hexvalue (ctx->fpstate->cw, fpregs[0], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->fpstate->sw, fpregs[1], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->fpstate->tag, fpregs[2], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->fpstate->ipoff, fpregs[3], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->fpstate->cssel, fpregs[4], 4);
|
|
Packit |
6c4009 |
hexvalue (ctx->fpstate->dataoff, fpregs[5], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->fpstate->datasel, fpregs[6], 4);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
ADD_STRING ("\n\n FPUCW: ");
|
|
Packit |
6c4009 |
ADD_MEM (fpregs[0], 8);
|
|
Packit |
6c4009 |
ADD_STRING (" FPUSW: ");
|
|
Packit |
6c4009 |
ADD_MEM (fpregs[1], 8);
|
|
Packit |
6c4009 |
ADD_STRING (" TAG: ");
|
|
Packit |
6c4009 |
ADD_MEM (fpregs[2], 8);
|
|
Packit |
6c4009 |
ADD_STRING ("\n IPOFF: ");
|
|
Packit |
6c4009 |
ADD_MEM (fpregs[3], 8);
|
|
Packit |
6c4009 |
ADD_STRING (" CSSEL: ");
|
|
Packit |
6c4009 |
ADD_MEM (fpregs[4], 4);
|
|
Packit |
6c4009 |
ADD_STRING (" DATAOFF: ");
|
|
Packit |
6c4009 |
ADD_MEM (fpregs[5], 8);
|
|
Packit |
6c4009 |
ADD_STRING (" DATASEL: ");
|
|
Packit |
6c4009 |
ADD_MEM (fpregs[6], 4);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Now the real FPU registers. */
|
|
Packit |
6c4009 |
hexvalue (ctx->fpstate->_st[0].exponent, fpregs[7], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->fpstate->_st[0].significand[3] << 16
|
|
Packit |
6c4009 |
| ctx->fpstate->_st[0].significand[2], fpregs[8], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->fpstate->_st[0].significand[1] << 16
|
|
Packit |
6c4009 |
| ctx->fpstate->_st[0].significand[0], fpregs[9], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->fpstate->_st[1].exponent, fpregs[10], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->fpstate->_st[1].significand[3] << 16
|
|
Packit |
6c4009 |
| ctx->fpstate->_st[1].significand[2], fpregs[11], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->fpstate->_st[1].significand[1] << 16
|
|
Packit |
6c4009 |
| ctx->fpstate->_st[1].significand[0], fpregs[12], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->fpstate->_st[2].exponent, fpregs[13], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->fpstate->_st[2].significand[3] << 16
|
|
Packit |
6c4009 |
| ctx->fpstate->_st[2].significand[2], fpregs[14], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->fpstate->_st[2].significand[1] << 16
|
|
Packit |
6c4009 |
| ctx->fpstate->_st[2].significand[0], fpregs[15], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->fpstate->_st[3].exponent, fpregs[16], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->fpstate->_st[3].significand[3] << 16
|
|
Packit |
6c4009 |
| ctx->fpstate->_st[3].significand[2], fpregs[17], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->fpstate->_st[3].significand[1] << 16
|
|
Packit |
6c4009 |
| ctx->fpstate->_st[3].significand[0], fpregs[18], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->fpstate->_st[4].exponent, fpregs[19], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->fpstate->_st[4].significand[3] << 16
|
|
Packit |
6c4009 |
| ctx->fpstate->_st[4].significand[2], fpregs[20], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->fpstate->_st[4].significand[1] << 16
|
|
Packit |
6c4009 |
| ctx->fpstate->_st[4].significand[0], fpregs[21], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->fpstate->_st[5].exponent, fpregs[22], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->fpstate->_st[5].significand[3] << 16
|
|
Packit |
6c4009 |
| ctx->fpstate->_st[5].significand[2], fpregs[23], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->fpstate->_st[5].significand[1] << 16
|
|
Packit |
6c4009 |
| ctx->fpstate->_st[5].significand[0], fpregs[24], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->fpstate->_st[6].exponent, fpregs[25], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->fpstate->_st[6].significand[3] << 16
|
|
Packit |
6c4009 |
| ctx->fpstate->_st[6].significand[2], fpregs[26], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->fpstate->_st[6].significand[1] << 16
|
|
Packit |
6c4009 |
| ctx->fpstate->_st[6].significand[0], fpregs[27], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->fpstate->_st[7].exponent, fpregs[28], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->fpstate->_st[7].significand[3] << 16
|
|
Packit |
6c4009 |
| ctx->fpstate->_st[7].significand[2], fpregs[29], 8);
|
|
Packit |
6c4009 |
hexvalue (ctx->fpstate->_st[7].significand[1] << 16
|
|
Packit |
6c4009 |
| ctx->fpstate->_st[7].significand[0], fpregs[30], 8);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
ADD_STRING ("\n\n ST(0) ");
|
|
Packit |
6c4009 |
ADD_MEM (fpregs[7], 4);
|
|
Packit |
6c4009 |
ADD_STRING (" ");
|
|
Packit |
6c4009 |
ADD_MEM (fpregs[8], 8);
|
|
Packit |
6c4009 |
ADD_MEM (fpregs[9], 8);
|
|
Packit |
6c4009 |
ADD_STRING (" ST(1) ");
|
|
Packit |
6c4009 |
ADD_MEM (fpregs[10], 4);
|
|
Packit |
6c4009 |
ADD_STRING (" ");
|
|
Packit |
6c4009 |
ADD_MEM (fpregs[11], 8);
|
|
Packit |
6c4009 |
ADD_MEM (fpregs[12], 8);
|
|
Packit |
6c4009 |
ADD_STRING ("\n ST(2) ");
|
|
Packit |
6c4009 |
ADD_MEM (fpregs[13], 4);
|
|
Packit |
6c4009 |
ADD_STRING (" ");
|
|
Packit |
6c4009 |
ADD_MEM (fpregs[14], 8);
|
|
Packit |
6c4009 |
ADD_MEM (fpregs[15], 8);
|
|
Packit |
6c4009 |
ADD_STRING (" ST(3) ");
|
|
Packit |
6c4009 |
ADD_MEM (fpregs[16], 4);
|
|
Packit |
6c4009 |
ADD_STRING (" ");
|
|
Packit |
6c4009 |
ADD_MEM (fpregs[17], 8);
|
|
Packit |
6c4009 |
ADD_MEM (fpregs[18], 8);
|
|
Packit |
6c4009 |
ADD_STRING ("\n ST(4) ");
|
|
Packit |
6c4009 |
ADD_MEM (fpregs[19], 4);
|
|
Packit |
6c4009 |
ADD_STRING (" ");
|
|
Packit |
6c4009 |
ADD_MEM (fpregs[20], 8);
|
|
Packit |
6c4009 |
ADD_MEM (fpregs[21], 8);
|
|
Packit |
6c4009 |
ADD_STRING (" ST(5) ");
|
|
Packit |
6c4009 |
ADD_MEM (fpregs[22], 4);
|
|
Packit |
6c4009 |
ADD_STRING (" ");
|
|
Packit |
6c4009 |
ADD_MEM (fpregs[23], 8);
|
|
Packit |
6c4009 |
ADD_MEM (fpregs[24], 8);
|
|
Packit |
6c4009 |
ADD_STRING ("\n ST(6) ");
|
|
Packit |
6c4009 |
ADD_MEM (fpregs[25], 4);
|
|
Packit |
6c4009 |
ADD_STRING (" ");
|
|
Packit |
6c4009 |
ADD_MEM (fpregs[26], 8);
|
|
Packit |
6c4009 |
ADD_MEM (fpregs[27], 8);
|
|
Packit |
6c4009 |
ADD_STRING (" ST(7) ");
|
|
Packit |
6c4009 |
ADD_MEM (fpregs[28], 4);
|
|
Packit |
6c4009 |
ADD_STRING (" ");
|
|
Packit |
6c4009 |
ADD_MEM (fpregs[29], 8);
|
|
Packit |
6c4009 |
ADD_MEM (fpregs[30], 8);
|
|
Packit |
6c4009 |
}
|
|
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)
|