Back to index

glibc  2.9
register-dump.h
Go to the documentation of this file.
00001 /* Dump registers.
00002    Copyright (C) 2000, 2001, 2002, 2006 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by Andreas Jaeger <aj@suse.de>, 2000.
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  R0   XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
00027  R8   XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
00028  R16  XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
00029  R24  XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
00030             pc       lo       hi
00031       XXXXXXXX XXXXXXXX XXXXXXXX
00032  The FPU registers will not be printed.
00033 */
00034 
00035 static void
00036 hexvalue (unsigned long int value, char *buf, size_t len)
00037 {
00038   char *cp = _itoa_word (value, buf + len, 16, 0);
00039   while (cp > buf)
00040     *--cp = '0';
00041 }
00042 
00043 static void
00044 register_dump (int fd, struct sigcontext *ctx)
00045 {
00046   char regs[38][8];
00047   struct iovec iov[38 * 2 + 10];
00048   size_t nr = 0;
00049   int i;
00050 
00051 #define ADD_STRING(str) \
00052   iov[nr].iov_base = (char *) str;                                   \
00053   iov[nr].iov_len = strlen (str);                                    \
00054   ++nr
00055 #define ADD_MEM(str, len) \
00056   iov[nr].iov_base = str;                                            \
00057   iov[nr].iov_len = len;                                             \
00058   ++nr
00059 
00060   /* Generate strings of register contents.  */
00061   for (i = 0; i < 32; i++)
00062     hexvalue (ctx->sc_regs[i], regs[i], 8);
00063   hexvalue (ctx->sc_pc, regs[32], 8);
00064   hexvalue (ctx->sc_mdhi, regs[33], 8);
00065   hexvalue (ctx->sc_mdlo, regs[34], 8);
00066 
00067   /* Generate the output.  */
00068   ADD_STRING ("Register dump:\n\n R0   ");
00069   for (i = 0; i < 8; i++)
00070     {
00071       ADD_MEM (regs[i], 8);
00072       ADD_STRING (" ");
00073     }
00074   ADD_STRING ("\n R8   ");
00075   for (i = 8; i < 16; i++)
00076     {
00077       ADD_MEM (regs[i], 8);
00078       ADD_STRING (" ");
00079     }
00080   ADD_STRING ("\n R16  ");
00081   for (i = 16; i < 24; i++)
00082     {
00083       ADD_MEM (regs[i], 8);
00084       ADD_STRING (" ");
00085     }
00086   ADD_STRING ("\n R24  ");
00087   for (i = 24; i < 32; i++)
00088     {
00089       ADD_MEM (regs[i], 8);
00090       ADD_STRING (" ");
00091     }
00092   ADD_STRING ("\n            pc       lo       hi\n      ");
00093   for (i = 32; i < 35; i++)
00094     {
00095       ADD_MEM (regs[i], 8);
00096       ADD_STRING (" ");
00097     }
00098   ADD_STRING ("\n");
00099 
00100   /* Write the stuff out.  */
00101   writev (fd, iov, nr);
00102 }
00103 
00104 
00105 #define REGISTER_DUMP register_dump (fd, ctx)