Back to index

glibc  2.9
register-dump.h
Go to the documentation of this file.
00001 /* Dump registers.
00002    Copyright (C) 1998, 2001 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 <stddef.h>
00021 #include <sys/uio.h>
00022 #include <stdio-common/_itoa.h>
00023 
00024 /* We will print the register dump in this format:
00025 
00026   R0: XXXXXXXX   R1: XXXXXXXX   R2: XXXXXXXX   R3: XXXXXXXX
00027   R4: XXXXXXXX   R5: XXXXXXXX   R6: XXXXXXXX   R7: XXXXXXXX
00028   R8: XXXXXXXX   R9: XXXXXXXX  R10: XXXXXXXX  R11: XXXXXXXX
00029  R12: XXXXXXXX  R13: XXXXXXXX   SP: XXXXXXXX   PC: XXXXXXXX
00030 DCCR: XXXXXXXX  SRP: XXXXXXXX */
00031 
00032 static void
00033 hexvalue (unsigned long int value, char *buf, size_t len)
00034 {
00035   char *cp = _itoa_word (value, buf + len, 16, 0);
00036   while (cp > buf)
00037     *--cp = '0';
00038 }
00039 
00040 static void register_dump (int fd, struct sigcontext *ctx)
00041 {
00042   char regs[18][8];
00043   struct iovec iov[36], *next_iov = iov;
00044   struct pt_regs *rx = &ctx->regs;
00045 
00046 #define ADD_STRING(str) \
00047   next_iov->iov_base = (char *) (str); \
00048   next_iov->iov_len = strlen (str); \
00049   ++next_iov
00050 #define ADD_MEM(str, len) \
00051   next_iov->iov_base = (str); \
00052   next_iov->iov_len = (len); \
00053   ++next_iov
00054 
00055   /* Generate strings of register contents.  */
00056   hexvalue (rx->r0, regs[0], 8);
00057   hexvalue (rx->r1, regs[1], 8);
00058   hexvalue (rx->r2, regs[2], 8);
00059   hexvalue (rx->r3, regs[3], 8);
00060   hexvalue (rx->r4, regs[4], 8);
00061   hexvalue (rx->r5, regs[5], 8);
00062   hexvalue (rx->r6, regs[6], 8);
00063   hexvalue (rx->r7, regs[7], 8);
00064   hexvalue (rx->r8, regs[8], 8);
00065   hexvalue (rx->r9, regs[9], 8);
00066   hexvalue (rx->r10, regs[10], 8);
00067   hexvalue (rx->r11, regs[11], 8);
00068   hexvalue (rx->r12, regs[12], 8);
00069   hexvalue (rx->r13, regs[13], 8);
00070   hexvalue (ctx->usp, regs[14], 8);
00071   hexvalue (rx->irp, regs[17], 8);
00072   hexvalue (rx->dccr, regs[15], 8);
00073   hexvalue (rx->srp, regs[16], 8);
00074 
00075   /* Generate the output.  */
00076   ADD_STRING ("Register dump:\n\n  R0: ");
00077   ADD_MEM (regs[0], 8);
00078   ADD_STRING ("  R1: ");
00079   ADD_MEM (regs[1], 8);
00080   ADD_STRING ("  R2: ");
00081   ADD_MEM (regs[2], 8);
00082   ADD_STRING ("  R3: ");
00083   ADD_MEM (regs[3], 8);
00084   ADD_STRING ("\n  R4: ");
00085   ADD_MEM (regs[4], 8);
00086   ADD_STRING ("  R5: ");
00087   ADD_MEM (regs[5], 8);
00088   ADD_STRING ("  R6: ");
00089   ADD_MEM (regs[6], 8);
00090   ADD_STRING ("  R7: ");
00091   ADD_MEM (regs[7], 8);
00092   ADD_STRING ("\n  R8: ");
00093   ADD_MEM (regs[8], 8);
00094   ADD_STRING ("  R9: ");
00095   ADD_MEM (regs[9], 8);
00096   ADD_STRING (" R10: ");
00097   ADD_MEM (regs[10], 8);
00098   ADD_STRING (" R11: ");
00099   ADD_MEM (regs[11], 8);
00100   ADD_STRING ("\n R12: ");
00101   ADD_MEM (regs[12], 8);
00102   ADD_STRING (" R13: ");
00103   ADD_MEM (regs[13], 8);
00104   ADD_STRING ("  SP: ");
00105   ADD_MEM (regs[14], 8);
00106   ADD_STRING ("  PC: ");
00107   ADD_MEM (regs[17], 8);
00108   ADD_STRING ("\nDCCR: ");
00109   ADD_MEM (regs[15], 8);
00110   ADD_STRING (" SRP: ");
00111   ADD_MEM (regs[16], 4);
00112 
00113   /* Write the stuff out.  */
00114   writev (fd, iov, next_iov - iov);
00115 }
00116 
00117 #define REGISTER_DUMP register_dump (fd, ctx)