Back to index

glibc  2.9
register-dump.h
Go to the documentation of this file.
00001 /* Dump registers.
00002    Copyright (C) 1999 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by Jakub Jelinek <jj@ultra.linux.cz>, 1999.
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  TSTATE: XXXXXXXXXXXXXXXX TPC: XXXXXXXXXXXXXXXX TNPC: XXXXXXXXXXXXXXXX
00027  Y: XXXXXXXX
00028  g0: 0000000000000000  g1: XXXXXXXXXXXXXXXX  g2: XXXXXXXXXXXXXXXX
00029  g3: XXXXXXXXXXXXXXXX  g4: XXXXXXXXXXXXXXXX  g5: XXXXXXXXXXXXXXXX
00030  g6: XXXXXXXXXXXXXXXX  g7: XXXXXXXXXXXXXXXX
00031  o0: XXXXXXXXXXXXXXXX  o1: XXXXXXXXXXXXXXXX  o2: XXXXXXXXXXXXXXXX
00032  o3: XXXXXXXXXXXXXXXX  o4: XXXXXXXXXXXXXXXX  o5: XXXXXXXXXXXXXXXX
00033  sp: XXXXXXXXXXXXXXXX  o7: XXXXXXXXXXXXXXXX
00034  l0: XXXXXXXXXXXXXXXX  l1: XXXXXXXXXXXXXXXX  l2: XXXXXXXXXXXXXXXX
00035  l3: XXXXXXXXXXXXXXXX  l4: XXXXXXXXXXXXXXXX  l5: XXXXXXXXXXXXXXXX
00036  l6: XXXXXXXXXXXXXXXX  l7: XXXXXXXXXXXXXXXX
00037  i0: XXXXXXXXXXXXXXXX  i1: XXXXXXXXXXXXXXXX  i2: XXXXXXXXXXXXXXXX
00038  i3: XXXXXXXXXXXXXXXX  i4: XXXXXXXXXXXXXXXX  i5: XXXXXXXXXXXXXXXX
00039  fp: XXXXXXXXXXXXXXXX  i7: XXXXXXXXXXXXXXXX
00040 
00041  Mask: XXXXXXXXXXXXXXXX XFSR: XXXXXXXXXXXXXXXX GSR: XX FPRS: X
00042   f0: XXXXXXXXXXXXXXXX   f2: XXXXXXXXXXXXXXXX   f4: XXXXXXXXXXXXXXXX
00043   f6: XXXXXXXXXXXXXXXX   f8: XXXXXXXXXXXXXXXX  f10: XXXXXXXXXXXXXXXX
00044  f12: XXXXXXXXXXXXXXXX  f14: XXXXXXXXXXXXXXXX  f16: XXXXXXXXXXXXXXXX
00045  f18: XXXXXXXXXXXXXXXX  f20: XXXXXXXXXXXXXXXX  f22: XXXXXXXXXXXXXXXX
00046  f24: XXXXXXXXXXXXXXXX  f26: XXXXXXXXXXXXXXXX  f28: XXXXXXXXXXXXXXXX
00047  f30: XXXXXXXXXXXXXXXX  f32: XXXXXXXXXXXXXXXX  f34: XXXXXXXXXXXXXXXX
00048  f36: XXXXXXXXXXXXXXXX  f38: XXXXXXXXXXXXXXXX  f40: XXXXXXXXXXXXXXXX
00049  f42: XXXXXXXXXXXXXXXX  f44: XXXXXXXXXXXXXXXX  f46: XXXXXXXXXXXXXXXX
00050  f48: XXXXXXXXXXXXXXXX  f50: XXXXXXXXXXXXXXXX  f52: XXXXXXXXXXXXXXXX
00051  f54: XXXXXXXXXXXXXXXX  f56: XXXXXXXXXXXXXXXX  f58: XXXXXXXXXXXXXXXX
00052  f60: XXXXXXXXXXXXXXXX  f62: XXXXXXXXXXXXXXXX
00053 
00054  */
00055 
00056 static void
00057 hexvalue (unsigned long int value, char *buf, size_t len)
00058 {
00059   char *cp = _itoa_word (value, buf + len, 16, 0);
00060   while (cp > buf)
00061     *--cp = '0';
00062 }
00063 
00064 static void
00065 register_dump (int fd, SIGCONTEXT ctx)
00066 {
00067   char regs[36][16];
00068   char fregs[68][8];
00069   struct iovec iov[150];
00070   size_t nr = 0;
00071   int i;
00072   unsigned long *r = (unsigned long *)
00073     (ctx->sigc_regs.u_regs[14] + STACK_BIAS);
00074   __siginfo_fpu_t *f;
00075 
00076 #define ADD_STRING(str) \
00077   iov[nr].iov_base = (char *) str;                                   \
00078   iov[nr].iov_len = strlen (str);                                    \
00079   ++nr
00080 #define ADD_MEM(str, len) \
00081   iov[nr].iov_base = str;                                            \
00082   iov[nr].iov_len = len;                                             \
00083   ++nr
00084 
00085   /* Generate strings of register contents.  */
00086   hexvalue (ctx->sigc_regs.tstate, regs[0], 16);
00087   hexvalue (ctx->sigc_regs.tpc,           regs[1], 16);
00088   hexvalue (ctx->sigc_regs.tnpc,   regs[2], 16);
00089   hexvalue (ctx->sigc_regs.y,             regs[3], 8);
00090   for (i = 1; i <= 15; i++)
00091     hexvalue (ctx->sigc_regs.u_regs[i], regs[3+i], 16);
00092   for (i = 0; i <= 15; i++)
00093     hexvalue (r[i],                regs[19+i], 16);
00094   hexvalue (ctx->sigc_mask,        regs[35], 16);
00095 
00096   /* Generate the output.  */
00097   ADD_STRING ("Register dump:\n\n TSTATE: ");
00098   ADD_MEM (regs[0], 16);
00099   ADD_STRING (" TPC: ");
00100   ADD_MEM (regs[1], 16);
00101   ADD_STRING (" TNPC: ");
00102   ADD_MEM (regs[2], 16);
00103   ADD_STRING ("\n Y: ");
00104   ADD_MEM (regs[3], 8);
00105   ADD_STRING ("\n  g0: 0000000000000000   g1: ");
00106   ADD_MEM (regs[4], 16);
00107   ADD_STRING ("  g2: ");
00108   ADD_MEM (regs[5], 16);
00109   ADD_STRING ("\n g3: ");
00110   ADD_MEM (regs[6], 16);
00111   ADD_STRING ("  g4: ");
00112   ADD_MEM (regs[7], 16);
00113   ADD_STRING ("  g5: ");
00114   ADD_MEM (regs[8], 16);
00115   ADD_STRING ("\n g6: ");
00116   ADD_MEM (regs[9], 16);
00117   ADD_STRING ("  g7: ");
00118   ADD_MEM (regs[10], 16);
00119   ADD_STRING ("\n o0: ");
00120   ADD_MEM (regs[11], 16);
00121   ADD_STRING ("  o1: ");
00122   ADD_MEM (regs[12], 16);
00123   ADD_STRING ("  o2: ");
00124   ADD_MEM (regs[13], 16);
00125   ADD_STRING ("\n o3: ");
00126   ADD_MEM (regs[14], 16);
00127   ADD_STRING ("  o4: ");
00128   ADD_MEM (regs[15], 16);
00129   ADD_STRING ("  o5: ");
00130   ADD_MEM (regs[16], 16);
00131   ADD_STRING ("\n sp: ");
00132   ADD_MEM (regs[17], 16);
00133   ADD_STRING ("  o7: ");
00134   ADD_MEM (regs[18], 16);
00135   ADD_STRING ("\n l0: ");
00136   ADD_MEM (regs[19], 16);
00137   ADD_STRING ("  l1: ");
00138   ADD_MEM (regs[20], 16);
00139   ADD_STRING ("  l2: ");
00140   ADD_MEM (regs[21], 16);
00141   ADD_STRING ("\n l3: ");
00142   ADD_MEM (regs[22], 16);
00143   ADD_STRING ("  l4: ");
00144   ADD_MEM (regs[23], 16);
00145   ADD_STRING ("  l5: ");
00146   ADD_MEM (regs[24], 16);
00147   ADD_STRING ("\n l6: ");
00148   ADD_MEM (regs[25], 16);
00149   ADD_STRING ("  l7: ");
00150   ADD_MEM (regs[26], 16);
00151   ADD_STRING ("\n i0: ");
00152   ADD_MEM (regs[27], 16);
00153   ADD_STRING ("  i1: ");
00154   ADD_MEM (regs[28], 16);
00155   ADD_STRING ("  i2: ");
00156   ADD_MEM (regs[29], 16);
00157   ADD_STRING ("\n i3: ");
00158   ADD_MEM (regs[30], 16);
00159   ADD_STRING ("  i4: ");
00160   ADD_MEM (regs[31], 16);
00161   ADD_STRING ("  i5: ");
00162   ADD_MEM (regs[32], 16);
00163   ADD_STRING ("\n fp: ");
00164   ADD_MEM (regs[33], 16);
00165   ADD_STRING ("  i7: ");
00166   ADD_MEM (regs[34], 16);
00167   ADD_STRING ("\n\n Mask: ");
00168   ADD_MEM (regs[35], 16);
00169 
00170   f = ctx->sigc_fpu_save;
00171   if (f != NULL)
00172     {
00173       for (i = 0; i < 64; i++)
00174        hexvalue (f->si_float_regs[i], fregs[i], 8);
00175       hexvalue (f->si_fsr, fregs[64], 16);
00176       hexvalue (f->si_gsr, fregs[66], 2);
00177       hexvalue (f->si_fprs, fregs[67], 1);
00178       ADD_STRING (" XFSR: ");
00179       ADD_MEM (fregs[64], 16);
00180       ADD_STRING (" GSR: ");
00181       ADD_MEM (fregs[66], 2);
00182       ADD_STRING (" FPRS: ");
00183       ADD_MEM (fregs[67], 1);
00184       ADD_STRING ("\n  f0: ");
00185       ADD_MEM (fregs[0], 16);
00186       ADD_STRING ("   f2: ");
00187       ADD_MEM (fregs[2], 16);
00188       ADD_STRING ("   f4: ");
00189       ADD_MEM (fregs[4], 16);
00190       ADD_STRING ("\n  f6: ");
00191       ADD_MEM (fregs[6], 16);
00192       ADD_STRING ("   f8: ");
00193       ADD_MEM (fregs[8], 16);
00194       ADD_STRING ("  f10: ");
00195       ADD_MEM (fregs[10], 16);
00196       ADD_STRING ("\n f12: ");
00197       ADD_MEM (fregs[12], 16);
00198       ADD_STRING ("  f14: ");
00199       ADD_MEM (fregs[14], 16);
00200       ADD_STRING ("  f16: ");
00201       ADD_MEM (fregs[16], 16);
00202       ADD_STRING ("\n f18: ");
00203       ADD_MEM (fregs[18], 16);
00204       ADD_STRING ("  f20: ");
00205       ADD_MEM (fregs[20], 16);
00206       ADD_STRING ("  f22: ");
00207       ADD_MEM (fregs[22], 16);
00208       ADD_STRING ("\n f24: ");
00209       ADD_MEM (fregs[24], 16);
00210       ADD_STRING ("  f26: ");
00211       ADD_MEM (fregs[26], 16);
00212       ADD_STRING ("  f28: ");
00213       ADD_MEM (fregs[28], 16);
00214       ADD_STRING ("\n f30: ");
00215       ADD_MEM (fregs[30], 16);
00216       ADD_STRING ("  f32: ");
00217       ADD_MEM (fregs[32], 16);
00218       ADD_STRING ("  f34: ");
00219       ADD_MEM (fregs[34], 16);
00220       ADD_STRING ("\n f36: ");
00221       ADD_MEM (fregs[36], 16);
00222       ADD_STRING ("  f38: ");
00223       ADD_MEM (fregs[38], 16);
00224       ADD_STRING ("  f40: ");
00225       ADD_MEM (fregs[40], 16);
00226       ADD_STRING ("\n f42: ");
00227       ADD_MEM (fregs[42], 16);
00228       ADD_STRING ("  f44: ");
00229       ADD_MEM (fregs[44], 16);
00230       ADD_STRING ("  f46: ");
00231       ADD_MEM (fregs[46], 16);
00232       ADD_STRING ("\n f48: ");
00233       ADD_MEM (fregs[48], 16);
00234       ADD_STRING ("  f50: ");
00235       ADD_MEM (fregs[50], 16);
00236       ADD_STRING ("  f52: ");
00237       ADD_MEM (fregs[52], 16);
00238       ADD_STRING ("\n f54: ");
00239       ADD_MEM (fregs[54], 16);
00240       ADD_STRING ("  f56: ");
00241       ADD_MEM (fregs[56], 16);
00242       ADD_STRING ("  f58: ");
00243       ADD_MEM (fregs[58], 16);
00244       ADD_STRING ("\n f60: ");
00245       ADD_MEM (fregs[60], 16);
00246       ADD_STRING ("  f62: ");
00247       ADD_MEM (fregs[62], 16);
00248     }
00249 
00250   ADD_STRING ("\n");
00251 
00252   /* Write the stuff out.  */
00253   writev (fd, iov, nr);
00254 }
00255 
00256 
00257 #define REGISTER_DUMP register_dump (fd, ctx)