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   struct iovec iov[112];
00061   size_t nr = 0;
00062 
00063 #define ADD_STRING(str) \
00064   iov[nr].iov_base = (char *) str;                                   \
00065   iov[nr].iov_len = strlen (str);                                    \
00066   ++nr
00067 #define ADD_MEM(str, len) \
00068   iov[nr].iov_base = str;                                            \
00069   iov[nr].iov_len = len;                                             \
00070   ++nr
00071 
00072   /* Generate strings of register contents.  */
00073   hexvalue (ctx->sc_regs[0], regs[0], 8);
00074   hexvalue (ctx->sc_regs[1], regs[1], 8);
00075   hexvalue (ctx->sc_regs[2], regs[2], 8);
00076   hexvalue (ctx->sc_regs[3], regs[3], 8);
00077   hexvalue (ctx->sc_regs[4], regs[4], 8);
00078   hexvalue (ctx->sc_regs[5], regs[5], 8);
00079   hexvalue (ctx->sc_regs[6], regs[6], 8);
00080   hexvalue (ctx->sc_regs[7], regs[7], 8);
00081   hexvalue (ctx->sc_regs[8], regs[8], 8);
00082   hexvalue (ctx->sc_regs[9], regs[9], 8);
00083   hexvalue (ctx->sc_regs[10], regs[10], 8);
00084   hexvalue (ctx->sc_regs[11], regs[11], 8);
00085   hexvalue (ctx->sc_regs[12], regs[12], 8);
00086   hexvalue (ctx->sc_regs[13], regs[13], 8);
00087   hexvalue (ctx->sc_regs[14], regs[14], 8);
00088   hexvalue (ctx->sc_regs[15], regs[15], 8);
00089   hexvalue (ctx->sc_macl, regs[16], 8);
00090   hexvalue (ctx->sc_mach, regs[17], 8);
00091   hexvalue (ctx->sc_pc, regs[18], 8);
00092   hexvalue (ctx->sc_pr, regs[19], 8);
00093   hexvalue (ctx->sc_gbr, regs[20], 8);
00094   hexvalue (ctx->sc_sr, regs[21], 8);
00095 
00096   /* Generate the output.  */
00097   ADD_STRING ("Register dump:\n\n  R0: ");
00098   ADD_MEM (regs[0], 8);
00099   ADD_STRING ("   R1: ");
00100   ADD_MEM (regs[1], 8);
00101   ADD_STRING ("   R2: ");
00102   ADD_MEM (regs[2], 8);
00103   ADD_STRING ("   R3: ");
00104   ADD_MEM (regs[3], 8);
00105   ADD_STRING ("\n  R4: ");
00106   ADD_MEM (regs[4], 8);
00107   ADD_STRING ("   R5: ");
00108   ADD_MEM (regs[5], 8);
00109   ADD_STRING ("   R6: ");
00110   ADD_MEM (regs[6], 8);
00111   ADD_STRING ("   R7: ");
00112   ADD_MEM (regs[7], 8);
00113   ADD_STRING ("\n  R8: ");
00114   ADD_MEM (regs[8], 8);
00115   ADD_STRING ("   R9: ");
00116   ADD_MEM (regs[9], 8);
00117   ADD_STRING ("  R10: ");
00118   ADD_MEM (regs[10], 8);
00119   ADD_STRING ("  R11: ");
00120   ADD_MEM (regs[11], 8);
00121   ADD_STRING ("\n R12: ");
00122   ADD_MEM (regs[12], 8);
00123   ADD_STRING ("  R13: ");
00124   ADD_MEM (regs[13], 8);
00125   ADD_STRING ("  R14: ");
00126   ADD_MEM (regs[14], 8);
00127   ADD_STRING ("  R15: ");
00128   ADD_MEM (regs[15], 8);
00129 
00130   ADD_STRING ("\n\nMACL: ");
00131   ADD_MEM (regs[16], 8);
00132   ADD_STRING (" MACH: ");
00133   ADD_MEM (regs[17], 8);
00134 
00135   ADD_STRING ("\n\n  PC: ");
00136   ADD_MEM (regs[18], 8);
00137   ADD_STRING ("   PR: ");
00138   ADD_MEM (regs[19], 8);
00139   ADD_STRING ("  GBR: ");
00140   ADD_MEM (regs[20], 8);
00141   ADD_STRING ("   SR: ");
00142   ADD_MEM (regs[21], 8);
00143 
00144   ADD_STRING ("\n");
00145 
00146   /* Write the stuff out.  */
00147   writev (fd, iov, nr);
00148 }
00149 
00150 
00151 #define REGISTER_DUMP register_dump (fd, &ctx)