Back to index

glibc  2.9
register-dump.h
Go to the documentation of this file.
00001 /* Dump registers.
00002    Copyright (C) 1999, 2000 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <sys/uio.h>
00021 #include <stdio-common/_itoa.h>
00022 
00023 /* We will print the register dump in this format:
00024 
00025   R0: XXXXXXXX   R1: XXXXXXXX   R2: XXXXXXXX   R3: XXXXXXXX
00026   R4: XXXXXXXX   R5: XXXXXXXX   R6: XXXXXXXX   R7: XXXXXXXX
00027   R8: XXXXXXXX   R9: XXXXXXXX  R10: XXXXXXXX  R11: XXXXXXXX
00028  R12: XXXXXXXX  R13: XXXXXXXX  R14: XXXXXXXX  R15: XXXXXXXX
00029 
00030 MACL: XXXXXXXX MACH: XXXXXXXX
00031 
00032   PC: XXXXXXXX   PR: XXXXXXXX  GBR: XXXXXXXX   SR: XXXXXXXX
00033 
00034  FR0: XXXXXXXX  FR1: XXXXXXXX  FR2: XXXXXXXX  FR3: XXXXXXXX 
00035  FR4: XXXXXXXX  FR5: XXXXXXXX  FR6: XXXXXXXX  FR7: XXXXXXXX 
00036  FR8: XXXXXXXX  FR9: XXXXXXXX FR10: XXXXXXXX FR11: XXXXXXXX 
00037 FR12: XXXXXXXX FR13: XXXXXXXX FR14: XXXXXXXX FR15: XXXXXXXX 
00038 
00039  XR0: XXXXXXXX  XR1: XXXXXXXX  XR2: XXXXXXXX  XR3: XXXXXXXX 
00040  XR4: XXXXXXXX  XR5: XXXXXXXX  XR6: XXXXXXXX  XR7: XXXXXXXX 
00041  XR8: XXXXXXXX  XR9: XXXXXXXX XR10: XXXXXXXX XR11: XXXXXXXX 
00042 XR12: XXXXXXXX XR13: XXXXXXXX XR14: XXXXXXXX XR15: XXXXXXXX 
00043 
00044 FPSCR: XXXXXXXX FPUL: XXXXXXXX
00045 
00046  */
00047 
00048 static void
00049 hexvalue (unsigned long int value, char *buf, size_t len)
00050 {
00051   char *cp = _itoa_word (value, buf + len, 16, 0);
00052   while (cp > buf)
00053     *--cp = '0';
00054 }
00055 
00056 static void
00057 register_dump (int fd, struct sigcontext *ctx)
00058 {
00059   char regs[22][8];
00060   char fpregs[34][8];
00061   struct iovec iov[112];
00062   size_t nr = 0;
00063 
00064 #define ADD_STRING(str) \
00065   iov[nr].iov_base = (char *) str;                                   \
00066   iov[nr].iov_len = strlen (str);                                    \
00067   ++nr
00068 #define ADD_MEM(str, len) \
00069   iov[nr].iov_base = str;                                            \
00070   iov[nr].iov_len = len;                                             \
00071   ++nr
00072 
00073   /* Generate strings of register contents.  */
00074   hexvalue (ctx->sc_regs[0], regs[0], 8);
00075   hexvalue (ctx->sc_regs[1], regs[1], 8);
00076   hexvalue (ctx->sc_regs[2], regs[2], 8);
00077   hexvalue (ctx->sc_regs[3], regs[3], 8);
00078   hexvalue (ctx->sc_regs[4], regs[4], 8);
00079   hexvalue (ctx->sc_regs[5], regs[5], 8);
00080   hexvalue (ctx->sc_regs[6], regs[6], 8);
00081   hexvalue (ctx->sc_regs[7], regs[7], 8);
00082   hexvalue (ctx->sc_regs[8], regs[8], 8);
00083   hexvalue (ctx->sc_regs[9], regs[9], 8);
00084   hexvalue (ctx->sc_regs[10], regs[10], 8);
00085   hexvalue (ctx->sc_regs[11], regs[11], 8);
00086   hexvalue (ctx->sc_regs[12], regs[12], 8);
00087   hexvalue (ctx->sc_regs[13], regs[13], 8);
00088   hexvalue (ctx->sc_regs[14], regs[14], 8);
00089   hexvalue (ctx->sc_regs[15], regs[15], 8);
00090   hexvalue (ctx->sc_macl, regs[16], 8);
00091   hexvalue (ctx->sc_mach, regs[17], 8);
00092   hexvalue (ctx->sc_pc, regs[18], 8);
00093   hexvalue (ctx->sc_pr, regs[19], 8);
00094   hexvalue (ctx->sc_gbr, regs[20], 8);
00095   hexvalue (ctx->sc_sr, regs[21], 8);
00096 
00097   /* Generate the output.  */
00098   ADD_STRING ("Register dump:\n\n  R0: ");
00099   ADD_MEM (regs[0], 8);
00100   ADD_STRING ("   R1: ");
00101   ADD_MEM (regs[1], 8);
00102   ADD_STRING ("   R2: ");
00103   ADD_MEM (regs[2], 8);
00104   ADD_STRING ("   R3: ");
00105   ADD_MEM (regs[3], 8);
00106   ADD_STRING ("\n  R4: ");
00107   ADD_MEM (regs[4], 8);
00108   ADD_STRING ("   R5: ");
00109   ADD_MEM (regs[5], 8);
00110   ADD_STRING ("   R6: ");
00111   ADD_MEM (regs[6], 8);
00112   ADD_STRING ("   R7: ");
00113   ADD_MEM (regs[7], 8);
00114   ADD_STRING ("\n  R8: ");
00115   ADD_MEM (regs[8], 8);
00116   ADD_STRING ("   R9: ");
00117   ADD_MEM (regs[9], 8);
00118   ADD_STRING ("  R10: ");
00119   ADD_MEM (regs[10], 8);
00120   ADD_STRING ("  R11: ");
00121   ADD_MEM (regs[11], 8);
00122   ADD_STRING ("\n R12: ");
00123   ADD_MEM (regs[12], 8);
00124   ADD_STRING ("  R13: ");
00125   ADD_MEM (regs[13], 8);
00126   ADD_STRING ("  R14: ");
00127   ADD_MEM (regs[14], 8);
00128   ADD_STRING ("  R15: ");
00129   ADD_MEM (regs[15], 8);
00130 
00131   ADD_STRING ("\n\nMACL: ");
00132   ADD_MEM (regs[16], 8);
00133   ADD_STRING (" MACH: ");
00134   ADD_MEM (regs[17], 8);
00135 
00136   ADD_STRING ("\n\n  PC: ");
00137   ADD_MEM (regs[18], 8);
00138   ADD_STRING ("   PR: ");
00139   ADD_MEM (regs[19], 8);
00140   ADD_STRING ("  GBR: ");
00141   ADD_MEM (regs[20], 8);
00142   ADD_STRING ("   SR: ");
00143   ADD_MEM (regs[21], 8);
00144 
00145   ADD_STRING ("\n");
00146 
00147   if (ctx->sc_ownedfp != NULL)
00148     {
00149       hexvalue (ctx->sc_fpregs[0], fpregs[0], 8);
00150       hexvalue (ctx->sc_fpregs[1], fpregs[1], 8);
00151       hexvalue (ctx->sc_fpregs[2], fpregs[2], 8);
00152       hexvalue (ctx->sc_fpregs[3], fpregs[3], 8);
00153       hexvalue (ctx->sc_fpregs[4], fpregs[4], 8);
00154       hexvalue (ctx->sc_fpregs[5], fpregs[5], 8);
00155       hexvalue (ctx->sc_fpregs[6], fpregs[6], 8);
00156       hexvalue (ctx->sc_fpregs[7], fpregs[7], 8);
00157       hexvalue (ctx->sc_fpregs[8], fpregs[8], 8);
00158       hexvalue (ctx->sc_fpregs[9], fpregs[9], 8);
00159       hexvalue (ctx->sc_fpregs[10], fpregs[10], 8);
00160       hexvalue (ctx->sc_fpregs[11], fpregs[11], 8);
00161       hexvalue (ctx->sc_fpregs[12], fpregs[12], 8);
00162       hexvalue (ctx->sc_fpregs[13], fpregs[13], 8);
00163       hexvalue (ctx->sc_fpregs[14], fpregs[14], 8);
00164       hexvalue (ctx->sc_fpregs[15], fpregs[15], 8);
00165       hexvalue (ctx->sc_xfpregs[0], fpregs[16], 8);
00166       hexvalue (ctx->sc_xfpregs[1], fpregs[17], 8);
00167       hexvalue (ctx->sc_xfpregs[2], fpregs[18], 8);
00168       hexvalue (ctx->sc_xfpregs[3], fpregs[19], 8);
00169       hexvalue (ctx->sc_xfpregs[4], fpregs[20], 8);
00170       hexvalue (ctx->sc_xfpregs[5], fpregs[21], 8);
00171       hexvalue (ctx->sc_xfpregs[6], fpregs[22], 8);
00172       hexvalue (ctx->sc_xfpregs[7], fpregs[23], 8);
00173       hexvalue (ctx->sc_xfpregs[8], fpregs[24], 8);
00174       hexvalue (ctx->sc_xfpregs[9], fpregs[25], 8);
00175       hexvalue (ctx->sc_xfpregs[10], fpregs[26], 8);
00176       hexvalue (ctx->sc_xfpregs[11], fpregs[27], 8);
00177       hexvalue (ctx->sc_xfpregs[12], fpregs[28], 8);
00178       hexvalue (ctx->sc_xfpregs[13], fpregs[29], 8);
00179       hexvalue (ctx->sc_xfpregs[14], fpregs[30], 8);
00180       hexvalue (ctx->sc_xfpregs[15], fpregs[31], 8);
00181       hexvalue (ctx->sc_fpscr, fpregs[32], 8);
00182       hexvalue (ctx->sc_fpul, fpregs[33], 8);
00183 
00184       ADD_STRING ("\n\n FR0: ");
00185       ADD_MEM (fpregs[0], 8);
00186       ADD_STRING ("  FR1: ");
00187       ADD_MEM (fpregs[1], 8);
00188       ADD_STRING ("  FR2: ");
00189       ADD_MEM (fpregs[2], 8);
00190       ADD_STRING ("  FR3: ");
00191       ADD_MEM (fpregs[3], 8);
00192       ADD_STRING ("\n FR4: ");
00193       ADD_MEM (fpregs[4], 8);
00194       ADD_STRING ("  FR5: ");
00195       ADD_MEM (fpregs[5], 8);
00196       ADD_STRING ("  FR6: ");
00197       ADD_MEM (fpregs[6], 8);
00198       ADD_STRING ("  FR7: ");
00199       ADD_MEM (fpregs[7], 8);
00200       ADD_STRING ("\n FR8: ");
00201       ADD_MEM (fpregs[8], 8);
00202       ADD_STRING ("  FR9: ");
00203       ADD_MEM (fpregs[9], 8);
00204       ADD_STRING (" FR10: ");
00205       ADD_MEM (fpregs[10], 8);
00206       ADD_STRING (" FR11: ");
00207       ADD_MEM (fpregs[11], 8);
00208       ADD_STRING ("\nFR12: ");
00209       ADD_MEM (fpregs[12], 8);
00210       ADD_STRING (" FR13: ");
00211       ADD_MEM (fpregs[13], 8);
00212       ADD_STRING (" FR14: ");
00213       ADD_MEM (fpregs[14], 8);
00214       ADD_STRING (" FR15: ");
00215       ADD_MEM (fpregs[15], 8);
00216       ADD_STRING ("\n\n XR0: ");
00217       ADD_MEM (fpregs[16], 8);
00218       ADD_STRING ("  XR1: ");
00219       ADD_MEM (fpregs[17], 8);
00220       ADD_STRING ("  XR2: ");
00221       ADD_MEM (fpregs[18], 8);
00222       ADD_STRING ("  XR3: ");
00223       ADD_MEM (fpregs[19], 8);
00224       ADD_STRING ("\n XR4: ");
00225       ADD_MEM (fpregs[20], 8);
00226       ADD_STRING ("  XR5: ");
00227       ADD_MEM (fpregs[21], 8);
00228       ADD_STRING ("  XR6: ");
00229       ADD_MEM (fpregs[22], 8);
00230       ADD_STRING ("  XR7: ");
00231       ADD_MEM (fpregs[23], 8);
00232       ADD_STRING ("\n XR8: ");
00233       ADD_MEM (fpregs[24], 8);
00234       ADD_STRING ("  XR9: ");
00235       ADD_MEM (fpregs[25], 8);
00236       ADD_STRING (" XR10: ");
00237       ADD_MEM (fpregs[26], 8);
00238       ADD_STRING (" XR11: ");
00239       ADD_MEM (fpregs[27], 8);
00240       ADD_STRING ("\nXR12: ");
00241       ADD_MEM (fpregs[28], 8);
00242       ADD_STRING (" XR13: ");
00243       ADD_MEM (fpregs[29], 8);
00244       ADD_STRING (" XR14: ");
00245       ADD_MEM (fpregs[30], 8);
00246       ADD_STRING (" XR15: ");
00247       ADD_MEM (fpregs[31], 8);
00248 
00249       ADD_STRING ("\n\nFPSCR: ");
00250       ADD_MEM (fpregs[32], 8);
00251       ADD_STRING (" FPUL: ");
00252       ADD_MEM (fpregs[33], 8);
00253 
00254       ADD_STRING ("\n");
00255     }
00256 
00257   /* Write the stuff out.  */
00258   writev (fd, iov, nr);
00259 }
00260 
00261 
00262 #define REGISTER_DUMP register_dump (fd, &ctx)