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    Contributed by Jakub Jelinek <jakub@redhat.com>, 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  PSR: XXXXXXXX PC: XXXXXXXX NPC: XXXXXXXX   Y: XXXXXXXX
00027  g0: 00000000  g1: XXXXXXXX  g2: XXXXXXXX  g3: XXXXXXXX
00028  g4: XXXXXXXX  g5: XXXXXXXX  g6: XXXXXXXX  g7: XXXXXXXX
00029  o0: XXXXXXXX  o1: XXXXXXXX  o2: XXXXXXXX  o3: XXXXXXXX
00030  o4: XXXXXXXX  o5: XXXXXXXX  sp: XXXXXXXX  o7: XXXXXXXX
00031  l0: XXXXXXXX  l1: XXXXXXXX  l2: XXXXXXXX  l3: XXXXXXXX
00032  l4: XXXXXXXX  l5: XXXXXXXX  l6: XXXXXXXX  l7: XXXXXXXX
00033  i0: XXXXXXXX  i1: XXXXXXXX  i2: XXXXXXXX  i3: XXXXXXXX
00034  i4: XXXXXXXX  i5: XXXXXXXX  fp: XXXXXXXX  i7: XXXXXXXX
00035 
00036  followed on sun4, sun4c, sun4d, sun4m by:
00037 
00038  Old mask: XXXXXXXX FSR: XXXXXXXX FPQ: XXXXXXXX
00039   f0: XXXXXXXXXXXXXXXX   f2: XXXXXXXXXXXXXXXX   f4: XXXXXXXXXXXXXXXX
00040   f6: XXXXXXXXXXXXXXXX   f8: XXXXXXXXXXXXXXXX  f10: XXXXXXXXXXXXXXXX
00041  f12: XXXXXXXXXXXXXXXX  f14: XXXXXXXXXXXXXXXX  f16: XXXXXXXXXXXXXXXX
00042  f18: XXXXXXXXXXXXXXXX  f20: XXXXXXXXXXXXXXXX  f22: XXXXXXXXXXXXXXXX
00043  f24: XXXXXXXXXXXXXXXX  f26: XXXXXXXXXXXXXXXX  f28: XXXXXXXXXXXXXXXX
00044  f30: XXXXXXXXXXXXXXXX
00045 
00046  and on sun4u by:
00047 
00048  Old mask: XXXXXXXX XFSR: XXXXXXXXXXXXXXXX GSR: XX FPRS: X
00049   f0: XXXXXXXXXXXXXXXX   f2: XXXXXXXXXXXXXXXX   f4: XXXXXXXXXXXXXXXX
00050   f6: XXXXXXXXXXXXXXXX   f8: XXXXXXXXXXXXXXXX  f10: XXXXXXXXXXXXXXXX
00051  f12: XXXXXXXXXXXXXXXX  f14: XXXXXXXXXXXXXXXX  f16: XXXXXXXXXXXXXXXX
00052  f18: XXXXXXXXXXXXXXXX  f20: XXXXXXXXXXXXXXXX  f22: XXXXXXXXXXXXXXXX
00053  f24: XXXXXXXXXXXXXXXX  f26: XXXXXXXXXXXXXXXX  f28: XXXXXXXXXXXXXXXX
00054  f30: XXXXXXXXXXXXXXXX  f32: XXXXXXXXXXXXXXXX  f34: XXXXXXXXXXXXXXXX
00055  f36: XXXXXXXXXXXXXXXX  f38: XXXXXXXXXXXXXXXX  f40: XXXXXXXXXXXXXXXX
00056  f42: XXXXXXXXXXXXXXXX  f44: XXXXXXXXXXXXXXXX  f46: XXXXXXXXXXXXXXXX
00057  f48: XXXXXXXXXXXXXXXX  f50: XXXXXXXXXXXXXXXX  f52: XXXXXXXXXXXXXXXX
00058  f54: XXXXXXXXXXXXXXXX  f56: XXXXXXXXXXXXXXXX  f58: XXXXXXXXXXXXXXXX
00059  f60: XXXXXXXXXXXXXXXX  f62: XXXXXXXXXXXXXXXX
00060 
00061  */
00062 
00063 static void
00064 hexvalue (unsigned long int value, char *buf, size_t len)
00065 {
00066   char *cp = _itoa_word (value, buf + len, 16, 0);
00067   while (cp > buf)
00068     *--cp = '0';
00069 }
00070 
00071 struct __siginfo_sparc32_fpu
00072 {
00073   unsigned int si_float_regs[32];
00074   unsigned int si_fsr;
00075   unsigned int si_fpq;
00076 };
00077 struct __siginfo_sparc64_fpu
00078 {
00079   unsigned int si_float_regs[64];
00080   unsigned int si_xfsr;
00081   unsigned int si_fsr;
00082   unsigned int _pad1;
00083   unsigned int si_gsr;
00084   unsigned int _pad2;
00085   unsigned int si_fprs;
00086 };
00087 
00088 static void
00089 register_dump (int fd, SIGCONTEXT ctx)
00090 {
00091   char regs[36][8];
00092   char fregs[68][8];
00093   struct iovec iov[150];
00094   size_t nr = 0;
00095   int i;
00096   unsigned int *r = (unsigned int *)
00097     ctx->si_regs.u_regs[14];
00098 
00099 #define ADD_STRING(str) \
00100   iov[nr].iov_base = (char *) str;                                   \
00101   iov[nr].iov_len = strlen (str);                                    \
00102   ++nr
00103 #define ADD_MEM(str, len) \
00104   iov[nr].iov_base = str;                                            \
00105   iov[nr].iov_len = len;                                             \
00106   ++nr
00107 
00108   /* Generate strings of register contents.  */
00109   hexvalue (ctx->si_regs.psr, regs[0], 8);
00110   hexvalue (ctx->si_regs.pc, regs[1], 8);
00111   hexvalue (ctx->si_regs.npc, regs[2], 8);
00112   hexvalue (ctx->si_regs.y, regs[3], 8);
00113   for (i = 1; i <= 15; i++)
00114     hexvalue (ctx->si_regs.u_regs[i], regs[3+i], 8);
00115   for (i = 0; i <= 15; i++)
00116     hexvalue (r[i], regs[19+i], 8);
00117   hexvalue (ctx->si_mask, regs[35], 8);
00118 
00119   /* Generate the output.  */
00120   ADD_STRING ("Register dump:\n\n PSR: ");
00121   ADD_MEM (regs[0], 8);
00122   ADD_STRING (" PC: ");
00123   ADD_MEM (regs[1], 8);
00124   ADD_STRING (" NPC: ");
00125   ADD_MEM (regs[2], 8);
00126   ADD_STRING ("   Y: ");
00127   ADD_MEM (regs[3], 8);
00128   ADD_STRING ("\n g0: 00000000 g1: ");
00129   ADD_MEM (regs[4], 8);
00130   ADD_STRING ("  g2: ");
00131   ADD_MEM (regs[5], 8);
00132   ADD_STRING ("  g3: ");
00133   ADD_MEM (regs[6], 8);
00134   ADD_STRING ("\n g4: ");
00135   ADD_MEM (regs[7], 8);
00136   ADD_STRING ("  g5: ");
00137   ADD_MEM (regs[8], 8);
00138   ADD_STRING ("  g6: ");
00139   ADD_MEM (regs[9], 8);
00140   ADD_STRING ("  g7: ");
00141   ADD_MEM (regs[10], 8);
00142   ADD_STRING ("\n o0: ");
00143   ADD_MEM (regs[11], 8);
00144   ADD_STRING ("  o1: ");
00145   ADD_MEM (regs[12], 8);
00146   ADD_STRING ("  o2: ");
00147   ADD_MEM (regs[13], 8);
00148   ADD_STRING ("  o3: ");
00149   ADD_MEM (regs[14], 8);
00150   ADD_STRING ("\n o4: ");
00151   ADD_MEM (regs[15], 8);
00152   ADD_STRING ("  o5: ");
00153   ADD_MEM (regs[16], 8);
00154   ADD_STRING ("  sp: ");
00155   ADD_MEM (regs[17], 8);
00156   ADD_STRING ("  o7: ");
00157   ADD_MEM (regs[18], 8);
00158   ADD_STRING ("\n l0: ");
00159   ADD_MEM (regs[19], 8);
00160   ADD_STRING ("  l1: ");
00161   ADD_MEM (regs[20], 8);
00162   ADD_STRING ("  l2: ");
00163   ADD_MEM (regs[21], 8);
00164   ADD_STRING ("  l3: ");
00165   ADD_MEM (regs[22], 8);
00166   ADD_STRING ("\n l4: ");
00167   ADD_MEM (regs[23], 8);
00168   ADD_STRING ("  l5: ");
00169   ADD_MEM (regs[24], 8);
00170   ADD_STRING ("  l6: ");
00171   ADD_MEM (regs[25], 8);
00172   ADD_STRING ("  l7: ");
00173   ADD_MEM (regs[26], 8);
00174   ADD_STRING ("\n i0: ");
00175   ADD_MEM (regs[27], 8);
00176   ADD_STRING ("  i1: ");
00177   ADD_MEM (regs[28], 8);
00178   ADD_STRING ("  i2: ");
00179   ADD_MEM (regs[29], 8);
00180   ADD_STRING ("  i3: ");
00181   ADD_MEM (regs[30], 8);
00182   ADD_STRING ("\n i4: ");
00183   ADD_MEM (regs[31], 8);
00184   ADD_STRING ("  i5: ");
00185   ADD_MEM (regs[32], 8);
00186   ADD_STRING ("  fp: ");
00187   ADD_MEM (regs[33], 8);
00188   ADD_STRING ("  i7: ");
00189   ADD_MEM (regs[34], 8);
00190   ADD_STRING ("\n\n Old mask: ");
00191   ADD_MEM (regs[35], 8);
00192 
00193   if ((ctx->si_regs.psr & 0xff000000) == 0xff000000)
00194     {
00195       struct __siginfo_sparc64_fpu *f;
00196 
00197       f = *(struct __siginfo_sparc64_fpu **) (ctx + 1);
00198       if (f != NULL)
00199        {
00200          for (i = 0; i < 64; i++)
00201            hexvalue (f->si_float_regs[i], fregs[i], 8);
00202          hexvalue (f->si_xfsr, fregs[64], 8);
00203          hexvalue (f->si_fsr, fregs[65], 8);
00204          hexvalue (f->si_gsr, fregs[66], 2);
00205          hexvalue (f->si_fprs, fregs[67], 1);
00206          ADD_STRING (" XFSR: ");
00207          ADD_MEM (fregs[64], 8);
00208          ADD_MEM (fregs[65], 8);
00209          ADD_STRING (" GSR: ");
00210          ADD_MEM (fregs[66], 2);
00211          ADD_STRING (" FPRS: ");
00212          ADD_MEM (fregs[67], 1);
00213          ADD_STRING ("\n  f0: ");
00214          ADD_MEM (fregs[0], 16);
00215          ADD_STRING ("   f2: ");
00216          ADD_MEM (fregs[2], 16);
00217          ADD_STRING ("   f4: ");
00218          ADD_MEM (fregs[4], 16);
00219          ADD_STRING ("\n  f6: ");
00220          ADD_MEM (fregs[6], 16);
00221          ADD_STRING ("   f8: ");
00222          ADD_MEM (fregs[8], 16);
00223          ADD_STRING ("  f10: ");
00224          ADD_MEM (fregs[10], 16);
00225          ADD_STRING ("\n f12: ");
00226          ADD_MEM (fregs[12], 16);
00227          ADD_STRING ("  f14: ");
00228          ADD_MEM (fregs[14], 16);
00229          ADD_STRING ("  f16: ");
00230          ADD_MEM (fregs[16], 16);
00231          ADD_STRING ("\n f18: ");
00232          ADD_MEM (fregs[18], 16);
00233          ADD_STRING ("  f20: ");
00234          ADD_MEM (fregs[20], 16);
00235          ADD_STRING ("  f22: ");
00236          ADD_MEM (fregs[22], 16);
00237          ADD_STRING ("\n f24: ");
00238          ADD_MEM (fregs[24], 16);
00239          ADD_STRING ("  f26: ");
00240          ADD_MEM (fregs[26], 16);
00241          ADD_STRING ("  f28: ");
00242          ADD_MEM (fregs[28], 16);
00243          ADD_STRING ("\n f30: ");
00244          ADD_MEM (fregs[30], 16);
00245          ADD_STRING ("  f32: ");
00246          ADD_MEM (fregs[32], 16);
00247          ADD_STRING ("  f34: ");
00248          ADD_MEM (fregs[34], 16);
00249          ADD_STRING ("\n f36: ");
00250          ADD_MEM (fregs[36], 16);
00251          ADD_STRING ("  f38: ");
00252          ADD_MEM (fregs[38], 16);
00253          ADD_STRING ("  f40: ");
00254          ADD_MEM (fregs[40], 16);
00255          ADD_STRING ("\n f42: ");
00256          ADD_MEM (fregs[42], 16);
00257          ADD_STRING ("  f44: ");
00258          ADD_MEM (fregs[44], 16);
00259          ADD_STRING ("  f46: ");
00260          ADD_MEM (fregs[46], 16);
00261          ADD_STRING ("\n f48: ");
00262          ADD_MEM (fregs[48], 16);
00263          ADD_STRING ("  f50: ");
00264          ADD_MEM (fregs[50], 16);
00265          ADD_STRING ("  f52: ");
00266          ADD_MEM (fregs[52], 16);
00267          ADD_STRING ("\n f54: ");
00268          ADD_MEM (fregs[54], 16);
00269          ADD_STRING ("  f56: ");
00270          ADD_MEM (fregs[56], 16);
00271          ADD_STRING ("  f58: ");
00272          ADD_MEM (fregs[58], 16);
00273          ADD_STRING ("\n f60: ");
00274          ADD_MEM (fregs[60], 16);
00275          ADD_STRING ("  f62: ");
00276          ADD_MEM (fregs[62], 16);
00277        }
00278     }
00279   else
00280     {
00281       struct __siginfo_sparc32_fpu *f;
00282 
00283       f = *(struct __siginfo_sparc32_fpu **) (ctx + 1);
00284       if (f != NULL)
00285        {
00286          for (i = 0; i < 32; i++)
00287            hexvalue (f->si_float_regs[i], fregs[i], 8);
00288          hexvalue (f->si_fsr, fregs[64], 8);
00289          hexvalue (f->si_fpq, fregs[65], 8);
00290          ADD_STRING (" FSR: ");
00291          ADD_MEM (fregs[64], 8);
00292          ADD_STRING (" FPQ: ");
00293          ADD_MEM (fregs[65], 8);
00294          ADD_STRING ("\n  f0: ");
00295          ADD_MEM (fregs[0], 16);
00296          ADD_STRING ("  f2: ");
00297          ADD_MEM (fregs[2], 16);
00298          ADD_STRING ("  f4: ");
00299          ADD_MEM (fregs[4], 16);
00300          ADD_STRING ("\n  f6: ");
00301          ADD_MEM (fregs[6], 16);
00302          ADD_STRING ("   f8: ");
00303          ADD_MEM (fregs[8], 16);
00304          ADD_STRING ("  f10: ");
00305          ADD_MEM (fregs[10], 16);
00306          ADD_STRING ("\n  f12: ");
00307          ADD_MEM (fregs[12], 16);
00308          ADD_STRING ("  f14: ");
00309          ADD_MEM (fregs[14], 16);
00310          ADD_STRING ("  f16: ");
00311          ADD_MEM (fregs[16], 16);
00312          ADD_STRING ("\n f18: ");
00313          ADD_MEM (fregs[18], 16);
00314          ADD_STRING ("  f20: ");
00315          ADD_MEM (fregs[20], 16);
00316          ADD_STRING ("  f22: ");
00317          ADD_MEM (fregs[22], 16);
00318          ADD_STRING ("\n f24: ");
00319          ADD_MEM (fregs[24], 16);
00320          ADD_STRING ("  f26: ");
00321          ADD_MEM (fregs[26], 16);
00322          ADD_STRING ("  f28: ");
00323          ADD_MEM (fregs[28], 16);
00324          ADD_STRING ("\n f30: ");
00325          ADD_MEM (fregs[30], 16);
00326        }
00327     }
00328 
00329   ADD_STRING ("\n");
00330 
00331   /* Write the stuff out.  */
00332   writev (fd, iov, nr);
00333 }
00334 
00335 
00336 #define REGISTER_DUMP register_dump (fd, ctx)