Back to index

glibc  2.9
register-dump.h
Go to the documentation of this file.
00001 /* Dump registers.
00002    Copyright (C) 1998 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #include <sys/uio.h>
00022 #include <stdio-common/_itoa.h>
00023 
00024 /* We will print the register dump in this format:
00025 
00026  EAX: XXXXXXXX   EBX: XXXXXXXX   ECX: XXXXXXXX   EDX: XXXXXXXX
00027  ESI: XXXXXXXX   EDI: XXXXXXXX   EBP: XXXXXXXX   ESP: XXXXXXXX
00028 
00029  EIP: XXXXXXXX   EFLAGS: XXXXXXXX
00030 
00031  CS:  XXXX   DS: XXXX   ES: XXXX   FS: XXXX   GS: XXXX   SS: XXXX
00032 
00033  Trap:  XXXXXXXX   Error: XXXXXXXX   OldMask: XXXXXXXX
00034  ESP/SIGNAL: XXXXXXXX   CR2: XXXXXXXX
00035 
00036  FPUCW: XXXXXXXX   FPUSW: XXXXXXXX   TAG: XXXXXXXX
00037  IPOFF: XXXXXXXX   CSSEL: XXXX   DATAOFF: XXXXXXXX   DATASEL: XXXX
00038 
00039  ST(0) XXXX XXXXXXXXXXXXXXXX   ST(1) XXXX XXXXXXXXXXXXXXXX
00040  ST(2) XXXX XXXXXXXXXXXXXXXX   ST(3) XXXX XXXXXXXXXXXXXXXX
00041  ST(4) XXXX XXXXXXXXXXXXXXXX   ST(5) XXXX XXXXXXXXXXXXXXXX
00042  ST(6) XXXX XXXXXXXXXXXXXXXX   ST(7) XXXX XXXXXXXXXXXXXXXX
00043 
00044  */
00045 
00046 static void
00047 hexvalue (unsigned long int value, char *buf, size_t len)
00048 {
00049   char *cp = _itoa_word (value, buf + len, 16, 0);
00050   while (cp > buf)
00051     *--cp = '0';
00052 }
00053 
00054 static void
00055 register_dump (int fd, struct sigcontext *ctx)
00056 {
00057   char regs[21][8];
00058   char fpregs[31][8];
00059   struct iovec iov[97];
00060   size_t nr = 0;
00061 
00062 #define ADD_STRING(str) \
00063   iov[nr].iov_base = (char *) str;                                   \
00064   iov[nr].iov_len = strlen (str);                                    \
00065   ++nr
00066 #define ADD_MEM(str, len) \
00067   iov[nr].iov_base = str;                                            \
00068   iov[nr].iov_len = len;                                             \
00069   ++nr
00070 
00071   /* Generate strings of register contents.  */
00072   hexvalue (ctx->eax, regs[0], 8);
00073   hexvalue (ctx->ebx, regs[1], 8);
00074   hexvalue (ctx->ecx, regs[2], 8);
00075   hexvalue (ctx->edx, regs[3], 8);
00076   hexvalue (ctx->esi, regs[4], 8);
00077   hexvalue (ctx->edi, regs[5], 8);
00078   hexvalue (ctx->ebp, regs[6], 8);
00079   hexvalue (ctx->esp, regs[7], 8);
00080   hexvalue (ctx->eip, regs[8], 8);
00081   hexvalue (ctx->eflags, regs[9], 8);
00082   hexvalue (ctx->cs, regs[10], 4);
00083   hexvalue (ctx->ds, regs[11], 4);
00084   hexvalue (ctx->es, regs[12], 4);
00085   hexvalue (ctx->fs, regs[13], 4);
00086   hexvalue (ctx->gs, regs[14], 4);
00087   hexvalue (ctx->ss, regs[15], 4);
00088   hexvalue (ctx->trapno, regs[16], 8);
00089   hexvalue (ctx->err, regs[17], 8);
00090   hexvalue (ctx->oldmask, regs[18], 8);
00091   hexvalue (ctx->esp_at_signal, regs[19], 8);
00092   hexvalue (ctx->cr2, regs[20], 8);
00093 
00094   /* Generate the output.  */
00095   ADD_STRING ("Register dump:\n\n EAX: ");
00096   ADD_MEM (regs[0], 8);
00097   ADD_STRING ("   EBX: ");
00098   ADD_MEM (regs[1], 8);
00099   ADD_STRING ("   ECX: ");
00100   ADD_MEM (regs[2], 8);
00101   ADD_STRING ("   EDX: ");
00102   ADD_MEM (regs[3], 8);
00103   ADD_STRING ("\n ESI: ");
00104   ADD_MEM (regs[4], 8);
00105   ADD_STRING ("   EDI: ");
00106   ADD_MEM (regs[5], 8);
00107   ADD_STRING ("   EBP: ");
00108   ADD_MEM (regs[6], 8);
00109   ADD_STRING ("   ESP: ");
00110   ADD_MEM (regs[7], 8);
00111   ADD_STRING ("\n\n EIP: ");
00112   ADD_MEM (regs[8], 8);
00113   ADD_STRING ("   EFLAGS: ");
00114   ADD_MEM (regs[9], 8);
00115   ADD_STRING ("\n\n CS: ");
00116   ADD_MEM (regs[10], 4);
00117   ADD_STRING ("   DS: ");
00118   ADD_MEM (regs[11], 4);
00119   ADD_STRING ("   ES: ");
00120   ADD_MEM (regs[12], 4);
00121   ADD_STRING ("   FS: ");
00122   ADD_MEM (regs[13], 4);
00123   ADD_STRING ("   GS: ");
00124   ADD_MEM (regs[14], 4);
00125   ADD_STRING ("   SS: ");
00126   ADD_MEM (regs[15], 4);
00127   ADD_STRING ("\n\n Trap: ");
00128   ADD_MEM (regs[16], 8);
00129   ADD_STRING ("   Error: ");
00130   ADD_MEM (regs[17], 8);
00131   ADD_STRING ("   OldMask: ");
00132   ADD_MEM (regs[18], 8);
00133   ADD_STRING ("\n ESP/signal: ");
00134   ADD_MEM (regs[19], 8);
00135   ADD_STRING ("   CR2: ");
00136   ADD_MEM (regs[20], 8);
00137 
00138   if (ctx->fpstate != NULL)
00139     {
00140 
00141       /* Generate output for the FPU control/status registers.  */
00142       hexvalue (ctx->fpstate->cw, fpregs[0], 8);
00143       hexvalue (ctx->fpstate->sw, fpregs[1], 8);
00144       hexvalue (ctx->fpstate->tag, fpregs[2], 8);
00145       hexvalue (ctx->fpstate->ipoff, fpregs[3], 8);
00146       hexvalue (ctx->fpstate->cssel, fpregs[4], 4);
00147       hexvalue (ctx->fpstate->dataoff, fpregs[5], 8);
00148       hexvalue (ctx->fpstate->datasel, fpregs[6], 4);
00149 
00150       ADD_STRING ("\n\n FPUCW: ");
00151       ADD_MEM (fpregs[0], 8);
00152       ADD_STRING ("   FPUSW: ");
00153       ADD_MEM (fpregs[1], 8);
00154       ADD_STRING ("   TAG: ");
00155       ADD_MEM (fpregs[2], 8);
00156       ADD_STRING ("\n IPOFF: ");
00157       ADD_MEM (fpregs[3], 8);
00158       ADD_STRING ("   CSSEL: ");
00159       ADD_MEM (fpregs[4], 4);
00160       ADD_STRING ("   DATAOFF: ");
00161       ADD_MEM (fpregs[5], 8);
00162       ADD_STRING ("   DATASEL: ");
00163       ADD_MEM (fpregs[6], 4);
00164 
00165       /* Now the real FPU registers.  */
00166       hexvalue (ctx->fpstate->_st[0].exponent, fpregs[7], 8);
00167       hexvalue (ctx->fpstate->_st[0].significand[3] << 16
00168               | ctx->fpstate->_st[0].significand[2], fpregs[8], 8);
00169       hexvalue (ctx->fpstate->_st[0].significand[1] << 16
00170               | ctx->fpstate->_st[0].significand[0], fpregs[9], 8);
00171       hexvalue (ctx->fpstate->_st[1].exponent, fpregs[10], 8);
00172       hexvalue (ctx->fpstate->_st[1].significand[3] << 16
00173               | ctx->fpstate->_st[1].significand[2], fpregs[11], 8);
00174       hexvalue (ctx->fpstate->_st[1].significand[1] << 16
00175               | ctx->fpstate->_st[1].significand[0], fpregs[12], 8);
00176       hexvalue (ctx->fpstate->_st[2].exponent, fpregs[13], 8);
00177       hexvalue (ctx->fpstate->_st[2].significand[3] << 16
00178               | ctx->fpstate->_st[2].significand[2], fpregs[14], 8);
00179       hexvalue (ctx->fpstate->_st[2].significand[1] << 16
00180               | ctx->fpstate->_st[2].significand[0], fpregs[15], 8);
00181       hexvalue (ctx->fpstate->_st[3].exponent, fpregs[16], 8);
00182       hexvalue (ctx->fpstate->_st[3].significand[3] << 16
00183               | ctx->fpstate->_st[3].significand[2], fpregs[17], 8);
00184       hexvalue (ctx->fpstate->_st[3].significand[1] << 16
00185               | ctx->fpstate->_st[3].significand[0], fpregs[18], 8);
00186       hexvalue (ctx->fpstate->_st[4].exponent, fpregs[19], 8);
00187       hexvalue (ctx->fpstate->_st[4].significand[3] << 16
00188               | ctx->fpstate->_st[4].significand[2], fpregs[20], 8);
00189       hexvalue (ctx->fpstate->_st[4].significand[1] << 16
00190               | ctx->fpstate->_st[4].significand[0], fpregs[21], 8);
00191       hexvalue (ctx->fpstate->_st[5].exponent, fpregs[22], 8);
00192       hexvalue (ctx->fpstate->_st[5].significand[3] << 16
00193               | ctx->fpstate->_st[5].significand[2], fpregs[23], 8);
00194       hexvalue (ctx->fpstate->_st[5].significand[1] << 16
00195               | ctx->fpstate->_st[5].significand[0], fpregs[24], 8);
00196       hexvalue (ctx->fpstate->_st[6].exponent, fpregs[25], 8);
00197       hexvalue (ctx->fpstate->_st[6].significand[3] << 16
00198               | ctx->fpstate->_st[6].significand[2], fpregs[26], 8);
00199       hexvalue (ctx->fpstate->_st[6].significand[1] << 16
00200               | ctx->fpstate->_st[6].significand[0], fpregs[27], 8);
00201       hexvalue (ctx->fpstate->_st[7].exponent, fpregs[28], 8);
00202       hexvalue (ctx->fpstate->_st[7].significand[3] << 16
00203               | ctx->fpstate->_st[7].significand[2], fpregs[29], 8);
00204       hexvalue (ctx->fpstate->_st[7].significand[1] << 16
00205               | ctx->fpstate->_st[7].significand[0], fpregs[30], 8);
00206 
00207       ADD_STRING ("\n\n ST(0) ");
00208       ADD_MEM (fpregs[7], 4);
00209       ADD_STRING (" ");
00210       ADD_MEM (fpregs[8], 8);
00211       ADD_MEM (fpregs[9], 8);
00212       ADD_STRING ("   ST(1) ");
00213       ADD_MEM (fpregs[10], 4);
00214       ADD_STRING (" ");
00215       ADD_MEM (fpregs[11], 8);
00216       ADD_MEM (fpregs[12], 8);
00217       ADD_STRING ("\n ST(2) ");
00218       ADD_MEM (fpregs[13], 4);
00219       ADD_STRING (" ");
00220       ADD_MEM (fpregs[14], 8);
00221       ADD_MEM (fpregs[15], 8);
00222       ADD_STRING ("   ST(3) ");
00223       ADD_MEM (fpregs[16], 4);
00224       ADD_STRING (" ");
00225       ADD_MEM (fpregs[17], 8);
00226       ADD_MEM (fpregs[18], 8);
00227       ADD_STRING ("\n ST(4) ");
00228       ADD_MEM (fpregs[19], 4);
00229       ADD_STRING (" ");
00230       ADD_MEM (fpregs[20], 8);
00231       ADD_MEM (fpregs[21], 8);
00232       ADD_STRING ("   ST(5) ");
00233       ADD_MEM (fpregs[22], 4);
00234       ADD_STRING (" ");
00235       ADD_MEM (fpregs[23], 8);
00236       ADD_MEM (fpregs[24], 8);
00237       ADD_STRING ("\n ST(6) ");
00238       ADD_MEM (fpregs[25], 4);
00239       ADD_STRING (" ");
00240       ADD_MEM (fpregs[26], 8);
00241       ADD_MEM (fpregs[27], 8);
00242       ADD_STRING ("   ST(7) ");
00243       ADD_MEM (fpregs[28], 4);
00244       ADD_STRING (" ");
00245       ADD_MEM (fpregs[29], 8);
00246       ADD_MEM (fpregs[30], 8);
00247     }
00248 
00249   ADD_STRING ("\n");
00250 
00251   /* Write the stuff out.  */
00252   writev (fd, iov, nr);
00253 }
00254 
00255 
00256 #define REGISTER_DUMP register_dump (fd, &ctx)