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 
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 #include <sys/ucontext.h>
00023 
00024 /* We will print the register dump in this format:
00025 
00026 Register dump:
00027 fp0-3:   0000000000000000 0000000000000000 0000000000000000 0000000000000000
00028 fp4-7:   0000000000000000 0000000000000000 0000000000000000 0000000000000000
00029 fp8-11:  0000000000000000 0000000000000000 0000000000000000 0000000000000000
00030 fp12-15: 0000000000000000 0000000000000000 0000000000000000 0000000000000000
00031 fp16-19: 0000000000000000 0000000000000000 0000000000000000 0000000000000000
00032 fp20-23: 0000000000000000 0000000000000000 0000000000000000 0000000000000000
00033 fp24-27: 0000000000000000 0000000000000000 0000000000000000 0000000000000000
00034 fp28-31: 0000000000000000 0000000000000000 0000000000000000 0000000000000000
00035 
00036 r00-07 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
00037 r08-15 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
00038 r16-23 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
00039 r24-31 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
00040 
00041   trap 00000000   iar 00000000 msr 00000000 cr 00000000
00042     lr 00000000   ctr 00000000 xer 00000000 mq 00000000
00043    tid 00000000 fpscr 00000000
00044 
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 
00057 static void
00058 register_dump (int fd, struct sigcontext *ctx)
00059 {
00060   char regs[108][8];
00061   struct iovec iov[38];
00062   struct __mstsafe  *reg_state;
00063   int i;
00064   int ii;
00065   size_t nr = 0;
00066 
00067 #define ADD_STRING(str) \
00068   iov[nr].iov_base = (char *) str;                                            \
00069   iov[nr].iov_len = strlen (str);                                             \
00070   ++nr
00071 #define ADD_MEM(str, len) \
00072   iov[nr].iov_base = str;                                                     \
00073   iov[nr].iov_len = len;                                                      \
00074   ++nr
00075 
00076   reg_state = (struct __mstsafe  *)&ctx->sc_jmpbuf.__jmp_context;
00077 
00078   hexvalue (reg_state->__excp_type, regs[0], 8);
00079   hexvalue (reg_state->__iar, regs[1], 8);
00080   hexvalue (reg_state->__msr, regs[2], 8);
00081   hexvalue (reg_state->__cr, regs[3], 8);
00082   hexvalue (reg_state->__lr, regs[4], 8);
00083   hexvalue (reg_state->__ctr, regs[5], 8);
00084   hexvalue (reg_state->__xer, regs[6], 8);
00085   hexvalue (reg_state->__mq, regs[7], 8);
00086   hexvalue (reg_state->__tid, regs[8], 8);
00087   hexvalue (reg_state->__fpscr, regs[9], 8);
00088 
00089   ii=10;
00090   for (i = 0; i <= 96; i++,ii++)
00091     hexvalue (reg_state->__gpr[i], regs[ii], 8);
00092 
00093   /* Generate the output.  */
00094   ADD_STRING ("Register dump:\n\nfp0-3:   ");
00095   ADD_MEM (regs[42], 8);
00096   ADD_MEM (regs[43], 8);
00097   ADD_STRING (" ");
00098   ADD_MEM (regs[44], 8);
00099   ADD_MEM (regs[45], 8);
00100   ADD_STRING (" ");
00101   ADD_MEM (regs[46], 8);
00102   ADD_MEM (regs[47], 8);
00103   ADD_STRING (" ");
00104   ADD_MEM (regs[48], 8);
00105   ADD_MEM (regs[49], 8);
00106   ADD_STRING ("\nfp4-7:   ");
00107   ADD_MEM (regs[50], 8);
00108   ADD_MEM (regs[51], 8);
00109   ADD_STRING (" ");
00110   ADD_MEM (regs[52], 8);
00111   ADD_MEM (regs[53], 8);
00112   ADD_STRING (" ");
00113   ADD_MEM (regs[54], 8);
00114   ADD_MEM (regs[55], 8);
00115   ADD_STRING (" ");
00116   ADD_MEM (regs[56], 8);
00117   ADD_MEM (regs[57], 8);
00118   ADD_STRING ("\nfp8-11:  ");
00119   ADD_MEM (regs[58], 8);
00120   ADD_MEM (regs[59], 8);
00121   ADD_STRING (" ");
00122   ADD_MEM (regs[60], 8);
00123   ADD_MEM (regs[61], 8);
00124   ADD_STRING (" ");
00125   ADD_MEM (regs[62], 8);
00126   ADD_MEM (regs[63], 8);
00127   ADD_STRING (" ");
00128   ADD_MEM (regs[64], 8);
00129   ADD_MEM (regs[65], 8);
00130   ADD_STRING ("\nfp12-15: ");
00131   ADD_MEM (regs[66], 8);
00132   ADD_MEM (regs[67], 8);
00133   ADD_STRING (" ");
00134   ADD_MEM (regs[68], 8);
00135   ADD_MEM (regs[69], 8);
00136   ADD_STRING (" ");
00137   ADD_MEM (regs[70], 8);
00138   ADD_MEM (regs[71], 8);
00139   ADD_STRING (" ");
00140   ADD_MEM (regs[72], 8);
00141   ADD_MEM (regs[73], 8);
00142   ADD_STRING ("\nfp16-19: ");
00143   ADD_MEM (regs[74], 8);
00144   ADD_MEM (regs[75], 8);
00145   ADD_STRING (" ");
00146   ADD_MEM (regs[76], 8);
00147   ADD_MEM (regs[78], 8);
00148   ADD_STRING (" ");
00149   ADD_MEM (regs[79], 8);
00150   ADD_MEM (regs[80], 8);
00151   ADD_STRING (" ");
00152   ADD_MEM (regs[81], 8);
00153   ADD_MEM (regs[82], 8);
00154   ADD_STRING ("\nfp20-23: ");
00155   ADD_MEM (regs[83], 8);
00156   ADD_MEM (regs[84], 8);
00157   ADD_STRING (" ");
00158   ADD_MEM (regs[85], 8);
00159   ADD_MEM (regs[86], 8);
00160   ADD_STRING (" ");
00161   ADD_MEM (regs[87], 8);
00162   ADD_MEM (regs[88], 8);
00163   ADD_STRING (" ");
00164   ADD_MEM (regs[89], 8);
00165   ADD_MEM (regs[90], 8);
00166   ADD_STRING ("\nfp24-27: ");
00167   ADD_MEM (regs[91], 8);
00168   ADD_MEM (regs[92], 8);
00169   ADD_STRING (" ");
00170   ADD_MEM (regs[93], 8);
00171   ADD_MEM (regs[94], 8);
00172   ADD_STRING (" ");
00173   ADD_MEM (regs[95], 8);
00174   ADD_MEM (regs[96], 8);
00175   ADD_STRING (" ");
00176   ADD_MEM (regs[97], 8);
00177   ADD_MEM (regs[98], 8);
00178   ADD_STRING ("\nfp28-31: ");
00179   ADD_MEM (regs[99], 8);
00180   ADD_MEM (regs[100], 8);
00181   ADD_STRING (" ");
00182   ADD_MEM (regs[101], 8);
00183   ADD_MEM (regs[102], 8);
00184   ADD_STRING (" ");
00185   ADD_MEM (regs[103], 8);
00186   ADD_MEM (regs[104], 8);
00187   ADD_STRING (" ");
00188   ADD_MEM (regs[105], 8);
00189   ADD_MEM (regs[106], 8);
00190   ADD_STRING ("\n\nr00-07 ");
00191   ADD_MEM (regs[10], 8);
00192   ADD_STRING (" ");
00193   ADD_MEM (regs[11], 8);
00194   ADD_STRING (" ");
00195   ADD_MEM (regs[12], 8);
00196   ADD_STRING (" ");
00197   ADD_MEM (regs[13], 8);
00198   ADD_STRING (" ");
00199   ADD_MEM (regs[14], 8);
00200   ADD_STRING (" ");
00201   ADD_MEM (regs[15], 8);
00202   ADD_STRING (" ");
00203   ADD_MEM (regs[16], 8);
00204   ADD_STRING (" ");
00205   ADD_MEM (regs[17], 8);
00206   ADD_STRING ("\nr08-15 ");
00207   ADD_MEM (regs[18], 8);
00208   ADD_STRING (" ");
00209   ADD_MEM (regs[19], 8);
00210   ADD_STRING (" ");
00211   ADD_MEM (regs[20], 8);
00212   ADD_STRING (" ");
00213   ADD_MEM (regs[21], 8);
00214   ADD_STRING (" ");
00215   ADD_MEM (regs[22], 8);
00216   ADD_STRING (" ");
00217   ADD_MEM (regs[23], 8);
00218   ADD_STRING (" ");
00219   ADD_MEM (regs[24], 8);
00220   ADD_STRING (" ");
00221   ADD_MEM (regs[25], 8);
00222   ADD_STRING ("\nr16-23 ");
00223   ADD_MEM (regs[26], 8);
00224   ADD_STRING (" ");
00225   ADD_MEM (regs[27], 8);
00226   ADD_STRING (" ");
00227   ADD_MEM (regs[28], 8);
00228   ADD_STRING (" ");
00229   ADD_MEM (regs[29], 8);
00230   ADD_STRING (" ");
00231   ADD_MEM (regs[30], 8);
00232   ADD_STRING (" ");
00233   ADD_MEM (regs[31], 8);
00234   ADD_STRING (" ");
00235   ADD_MEM (regs[32], 8);
00236   ADD_STRING (" ");
00237   ADD_MEM (regs[33], 8);
00238   ADD_STRING ("\nr24-31 ");
00239   ADD_MEM (regs[34], 8);
00240   ADD_STRING (" ");
00241   ADD_MEM (regs[35], 8);
00242   ADD_STRING (" ");
00243   ADD_MEM (regs[36], 8);
00244   ADD_STRING (" ");
00245   ADD_MEM (regs[37], 8);
00246   ADD_STRING (" ");
00247   ADD_MEM (regs[38], 8);
00248   ADD_STRING (" ");
00249   ADD_MEM (regs[39], 8);
00250   ADD_STRING (" ");
00251   ADD_MEM (regs[40], 8);
00252   ADD_STRING (" ");
00253   ADD_MEM (regs[41], 8);
00254   ADD_STRING ("\n\n  trap ");
00255   ADD_MEM (regs[0], 8);
00256   ADD_STRING ("   iar ");
00257   ADD_MEM (regs[1], 8);
00258   ADD_STRING (" msr ");
00259   ADD_MEM (regs[2], 8);
00260   ADD_STRING (" cr ");
00261   ADD_MEM (regs[3], 8);
00262   ADD_STRING ("\n    lr ");
00263   ADD_MEM (regs[4], 8);
00264   ADD_STRING ("   ctr ");
00265   ADD_MEM (regs[5], 8);
00266   ADD_STRING (" xer ");
00267   ADD_MEM (regs[6], 8);
00268   ADD_STRING (" mq ");
00269   ADD_MEM (regs[7], 8);
00270   ADD_STRING ("\n   tid ");
00271   ADD_MEM (regs[8], 8);
00272   ADD_STRING (" fpscr ");
00273   ADD_MEM (regs[9], 8);
00274   ADD_STRING ("\n");
00275 
00276   /* Write the stuff out.  */
00277   writev (fd, iov, nr);
00278 }
00279 
00280 #define REGISTER_DUMP register_dump (fd, ctx)
00281