Back to index

glibc  2.9
register-dump.h
Go to the documentation of this file.
00001 /* Dump registers.
00002    Copyright (C) 1998, 1999, 2001 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by Philip Blundell <pb@nexus.co.uk>, 1998.
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 #include <sys/ucontext.h>
00024 
00025 /* We will print the register dump in this format:
00026 
00027  R0: XXXXXXXX   R1: XXXXXXXX   R2: XXXXXXXX   R3: XXXXXXXX
00028  R4: XXXXXXXX   R5: XXXXXXXX   R6: XXXXXXXX   R7: XXXXXXXX
00029  R8: XXXXXXXX   R9: XXXXXXXX   SL: XXXXXXXX   FP: XXXXXXXX
00030  IP: XXXXXXXX   SP: XXXXXXXX   LR: XXXXXXXX   PC: XXXXXXXX
00031 
00032  CPSR: XXXXXXXX
00033 
00034  Trap: XXXXXXXX   Error: XXXXXXXX   OldMask: XXXXXXXX
00035  Addr: XXXXXXXX
00036 
00037  */
00038 
00039 static void
00040 hexvalue (unsigned long int value, char *buf, size_t len)
00041 {
00042   char *cp = _itoa_word (value, buf + len, 16, 0);
00043   while (cp > buf)
00044     *--cp = '0';
00045 }
00046 
00047 static void
00048 register_dump (int fd, const struct ucontext *ctx)
00049 {
00050   char regs[21][8];
00051   struct iovec iov[97];
00052   size_t nr = 0;
00053 
00054 #define ADD_STRING(str) \
00055   iov[nr].iov_base = (char *) str;                                   \
00056   iov[nr].iov_len = strlen (str);                                    \
00057   ++nr
00058 #define ADD_MEM(str, len) \
00059   iov[nr].iov_base = str;                                            \
00060   iov[nr].iov_len = len;                                             \
00061   ++nr
00062 
00063   /* Generate strings of register contents.  */
00064   hexvalue (ctx->uc_mcontext.arm_r0, regs[0], 8);
00065   hexvalue (ctx->uc_mcontext.arm_r1, regs[1], 8);
00066   hexvalue (ctx->uc_mcontext.arm_r2, regs[2], 8);
00067   hexvalue (ctx->uc_mcontext.arm_r3, regs[3], 8);
00068   hexvalue (ctx->uc_mcontext.arm_r4, regs[4], 8);
00069   hexvalue (ctx->uc_mcontext.arm_r5, regs[5], 8);
00070   hexvalue (ctx->uc_mcontext.arm_r6, regs[6], 8);
00071   hexvalue (ctx->uc_mcontext.arm_r7, regs[7], 8);
00072   hexvalue (ctx->uc_mcontext.arm_r8, regs[8], 8);
00073   hexvalue (ctx->uc_mcontext.arm_r9, regs[9], 8);
00074   hexvalue (ctx->uc_mcontext.arm_r10, regs[10], 8);
00075   hexvalue (ctx->uc_mcontext.arm_fp, regs[11], 8);
00076   hexvalue (ctx->uc_mcontext.arm_ip, regs[12], 8);
00077   hexvalue (ctx->uc_mcontext.arm_sp, regs[13], 8);
00078   hexvalue (ctx->uc_mcontext.arm_lr, regs[14], 8);
00079   hexvalue (ctx->uc_mcontext.arm_pc, regs[15], 8);
00080   hexvalue (ctx->uc_mcontext.arm_cpsr, regs[16], 8);
00081   hexvalue (ctx->uc_mcontext.trap_no, regs[17], 8);
00082   hexvalue (ctx->uc_mcontext.error_code, regs[18], 8);
00083   hexvalue (ctx->uc_mcontext.oldmask, regs[19], 8);
00084   hexvalue (ctx->uc_mcontext.fault_address, regs[20], 8);
00085 
00086   /* Generate the output.  */
00087   ADD_STRING ("Register dump:\n\n R0: ");
00088   ADD_MEM (regs[0], 8);
00089   ADD_STRING ("   R1: ");
00090   ADD_MEM (regs[1], 8);
00091   ADD_STRING ("   R2: ");
00092   ADD_MEM (regs[2], 8);
00093   ADD_STRING ("   R3: ");
00094   ADD_MEM (regs[3], 8);
00095   ADD_STRING ("\n R4: ");
00096   ADD_MEM (regs[4], 8);
00097   ADD_STRING ("   R5: ");
00098   ADD_MEM (regs[5], 8);
00099   ADD_STRING ("   R6: ");
00100   ADD_MEM (regs[6], 8);
00101   ADD_STRING ("   R7: ");
00102   ADD_MEM (regs[7], 8);
00103   ADD_STRING ("\n R8: ");
00104   ADD_MEM (regs[8], 8);
00105   ADD_STRING ("   R9: ");
00106   ADD_MEM (regs[9], 8);
00107   ADD_STRING ("   SL: ");
00108   ADD_MEM (regs[10], 8);
00109   ADD_STRING ("   FP: ");
00110   ADD_MEM (regs[11], 8);
00111   ADD_STRING ("\n IP: ");
00112   ADD_MEM (regs[12], 8);
00113   ADD_STRING ("   SP: ");
00114   ADD_MEM (regs[13], 8);
00115   ADD_STRING ("   LR: ");
00116   ADD_MEM (regs[14], 8);
00117   ADD_STRING ("   PC: ");
00118   ADD_MEM (regs[15], 8);
00119   ADD_STRING ("\n\n CPSR: ");
00120   ADD_MEM (regs[16], 8);
00121   ADD_STRING ("\n\n Trap: ");
00122   ADD_MEM (regs[17], 8);
00123   ADD_STRING ("   Error: ");
00124   ADD_MEM (regs[18], 8);
00125   ADD_STRING ("   OldMask: ");
00126   ADD_MEM (regs[19], 8);
00127   ADD_STRING ("\n Addr: ");
00128   ADD_MEM (regs[20], 8);
00129 
00130   ADD_STRING ("\n");
00131 
00132   /* Write the stuff out.  */
00133   writev (fd, iov, nr);
00134 }
00135 
00136 
00137 #define REGISTER_DUMP register_dump (fd, ctx)