Back to index

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