Back to index

glibc  2.9
register-dump.h
Go to the documentation of this file.
00001 /* Dump registers.  64 bit S/390 version.
00002    Copyright (C) 2001 Free Software Foundation, Inc.
00003    Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
00004    This file is part of the GNU C Library.
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  GPR0: XXXXXXXXXXXXXXXX  GPR1: XXXXXXXXXXXXXXXX
00027  GPR2: XXXXXXXXXXXXXXXX  GPR3: XXXXXXXXXXXXXXXX
00028  GPR4: XXXXXXXXXXXXXXXX  GPR5: XXXXXXXXXXXXXXXX
00029  GPR6: XXXXXXXXXXXXXXXX  GPR7: XXXXXXXXXXXXXXXX
00030  GPR8: XXXXXXXXXXXXXXXX  GPR9: XXXXXXXXXXXXXXXX
00031  GPRA: XXXXXXXXXXXXXXXX  GPRB: XXXXXXXXXXXXXXXX
00032  GPRC: XXXXXXXXXXXXXXXX  GPRD: XXXXXXXXXXXXXXXX
00033  GPRE: XXXXXXXXXXXXXXXX  GPRF: XXXXXXXXXXXXXXXX
00034 
00035  PSW.MASK: XXXXXXXXXXXXXXXX   PSW.ADDR: XXXXXXXXXXXXXXXX
00036 
00037  ST(0) XXXX XXXXXXXXXXXXXXXX   ST(1) XXXX XXXXXXXXXXXXXXXX
00038  ST(2) XXXX XXXXXXXXXXXXXXXX   ST(3) XXXX XXXXXXXXXXXXXXXX
00039  ST(4) XXXX XXXXXXXXXXXXXXXX   ST(5) XXXX XXXXXXXXXXXXXXXX
00040  ST(6) XXXX XXXXXXXXXXXXXXXX   ST(7) XXXX XXXXXXXXXXXXXXXX
00041  */
00042 
00043 static void
00044 hexvalue (unsigned long int value, char *buf, size_t len)
00045 {
00046   char *cp = _itoa_word (value, buf + len, 16, 0);
00047   while (cp > buf)
00048     *--cp = '0';
00049 }
00050 
00051 static void
00052 register_dump (int fd, struct sigcontext *ctx)
00053 {
00054   char regs[19][16];
00055   struct iovec iov[40];
00056   size_t nr = 0;
00057 
00058 #define ADD_STRING(str) \
00059   iov[nr].iov_base = (char *) str;                                   \
00060   iov[nr].iov_len = strlen (str);                                    \
00061   ++nr
00062 #define ADD_MEM(str, len) \
00063   iov[nr].iov_base = str;                                            \
00064   iov[nr].iov_len = len;                                             \
00065   ++nr
00066 
00067   /* Generate strings of register contents.  */
00068   hexvalue (ctx->sregs->regs.gprs[0], regs[0], 16);
00069   hexvalue (ctx->sregs->regs.gprs[1], regs[1], 16);
00070   hexvalue (ctx->sregs->regs.gprs[2], regs[2], 16);
00071   hexvalue (ctx->sregs->regs.gprs[3], regs[3], 16);
00072   hexvalue (ctx->sregs->regs.gprs[4], regs[4], 16);
00073   hexvalue (ctx->sregs->regs.gprs[5], regs[5], 16);
00074   hexvalue (ctx->sregs->regs.gprs[6], regs[6], 16);
00075   hexvalue (ctx->sregs->regs.gprs[7], regs[7], 16);
00076   hexvalue (ctx->sregs->regs.gprs[8], regs[8], 16);
00077   hexvalue (ctx->sregs->regs.gprs[9], regs[9], 16);
00078   hexvalue (ctx->sregs->regs.gprs[10], regs[10], 16);
00079   hexvalue (ctx->sregs->regs.gprs[11], regs[11], 16);
00080   hexvalue (ctx->sregs->regs.gprs[12], regs[12], 16);
00081   hexvalue (ctx->sregs->regs.gprs[13], regs[13], 16);
00082   hexvalue (ctx->sregs->regs.gprs[14], regs[14], 16);
00083   hexvalue (ctx->sregs->regs.gprs[15], regs[15], 16);
00084   hexvalue (ctx->sregs->regs.psw.mask, regs[16], 16);
00085   hexvalue (ctx->sregs->regs.psw.addr, regs[17], 16);
00086    
00087   /* Generate the output.  */
00088   ADD_STRING ("Register dump:\n\n GPR0: ");
00089   ADD_MEM (regs[0], 16);
00090   ADD_STRING ("  GPR1: ");
00091   ADD_MEM (regs[1], 16);
00092   ADD_STRING ("  GPR2: ");
00093   ADD_MEM (regs[2], 16);
00094   ADD_STRING ("  GPR3: ");
00095   ADD_MEM (regs[3], 16);
00096   ADD_STRING ("\n GPR4: ");
00097   ADD_MEM (regs[4], 16);
00098   ADD_STRING ("  GPR5: ");
00099   ADD_MEM (regs[5], 16);
00100   ADD_STRING ("  GPR6: ");
00101   ADD_MEM (regs[6], 16);
00102   ADD_STRING ("  GPR7: ");
00103   ADD_MEM (regs[7], 16);
00104   ADD_STRING ("\n GPR8: ");
00105   ADD_MEM (regs[8], 16);
00106   ADD_STRING ("  GPR9: ");
00107   ADD_MEM (regs[9], 16);
00108   ADD_STRING ("  GPRA: ");
00109   ADD_MEM (regs[10], 16);
00110   ADD_STRING ("  GPRB: ");
00111   ADD_MEM (regs[11], 16);
00112   ADD_STRING ("\n GPRC: ");
00113   ADD_MEM (regs[12], 16);
00114   ADD_STRING ("  GPRD: ");
00115   ADD_MEM (regs[13], 16);
00116   ADD_STRING ("  GPRE: ");
00117   ADD_MEM (regs[14], 16);
00118   ADD_STRING ("  GPRF: ");
00119   ADD_MEM (regs[15], 16);
00120   ADD_STRING ("\n\n PSW.MASK: ");
00121   ADD_MEM (regs[16], 16);
00122   ADD_STRING ("  PSW.ADDR: ");
00123   ADD_MEM (regs[17], 16);
00124   ADD_STRING ("  TRAP: ");
00125   ADD_MEM (regs[18], 4);
00126   ADD_STRING ("\n");
00127 
00128   /* Write the stuff out.  */
00129   writev (fd, iov, nr);
00130 }
00131 
00132 
00133 #define REGISTER_DUMP register_dump (fd, ctx)