Back to index

glibc  2.9
register-dump.h
Go to the documentation of this file.
00001 /* Dump registers.
00002    Copyright (C) 2004 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 <string.h>
00022 
00023 /* We will print the register dump in this format:
00024 
00025     V0: XXXXXXXXXXXXXXXX    T0: XXXXXXXXXXXXXXXX    T1: XXXXXXXXXXXXXXXX
00026     T2: XXXXXXXXXXXXXXXX    T3: XXXXXXXXXXXXXXXX    T4: XXXXXXXXXXXXXXXX
00027     T5: XXXXXXXXXXXXXXXX    T6: XXXXXXXXXXXXXXXX    T7: XXXXXXXXXXXXXXXX
00028     S0: XXXXXXXXXXXXXXXX    S1: XXXXXXXXXXXXXXXX    S2: XXXXXXXXXXXXXXXX
00029     S3: XXXXXXXXXXXXXXXX    S4: XXXXXXXXXXXXXXXX    S5: XXXXXXXXXXXXXXXX
00030     S6: XXXXXXXXXXXXXXXX    A0: XXXXXXXXXXXXXXXX    A1: XXXXXXXXXXXXXXXX
00031     A2: XXXXXXXXXXXXXXXX    A3: XXXXXXXXXXXXXXXX    A4: XXXXXXXXXXXXXXXX
00032     A5: XXXXXXXXXXXXXXXX    T8: XXXXXXXXXXXXXXXX    T9: XXXXXXXXXXXXXXXX
00033    T10: XXXXXXXXXXXXXXXX   T11: XXXXXXXXXXXXXXXX    RA: XXXXXXXXXXXXXXXX
00034    T12: XXXXXXXXXXXXXXXX    AT: XXXXXXXXXXXXXXXX    GP: XXXXXXXXXXXXXXXX
00035     SP: XXXXXXXXXXXXXXXX    PC: XXXXXXXXXXXXXXXX
00036   
00037    FP0: XXXXXXXXXXXXXXXX   FP1: XXXXXXXXXXXXXXXX   FP2: XXXXXXXXXXXXXXXX
00038    FP3: XXXXXXXXXXXXXXXX   FP4: XXXXXXXXXXXXXXXX   FP5: XXXXXXXXXXXXXXXX
00039    FP6: XXXXXXXXXXXXXXXX   FP7: XXXXXXXXXXXXXXXX   FP8: XXXXXXXXXXXXXXXX
00040    FP9: XXXXXXXXXXXXXXXX  FP10: XXXXXXXXXXXXXXXX  FP11: XXXXXXXXXXXXXXXX
00041   FP12: XXXXXXXXXXXXXXXX  FP13: XXXXXXXXXXXXXXXX  FP14: XXXXXXXXXXXXXXXX
00042   FP15: XXXXXXXXXXXXXXXX  FP16: XXXXXXXXXXXXXXXX  FP17: XXXXXXXXXXXXXXXX
00043   FP18: XXXXXXXXXXXXXXXX  FP19: XXXXXXXXXXXXXXXX  FP20: XXXXXXXXXXXXXXXX
00044   FP21: XXXXXXXXXXXXXXXX  FP22: XXXXXXXXXXXXXXXX  FP23: XXXXXXXXXXXXXXXX
00045   FP24: XXXXXXXXXXXXXXXX  FP25: XXXXXXXXXXXXXXXX  FP26: XXXXXXXXXXXXXXXX
00046   FP27: XXXXXXXXXXXXXXXX  FP28: XXXXXXXXXXXXXXXX  FP29: XXXXXXXXXXXXXXXX
00047   FP30: XXXXXXXXXXXXXXXX  FPCR: XXXXXXXXXXXXXXXX
00048   
00049    TA0: XXXXXXXXXXXXXXXX   TA1: XXXXXXXXXXXXXXXX   TA2: XXXXXXXXXXXXXXXX
00050 */
00051 
00052 #define NREGS (32+32+3)
00053 
00054 static const char __attribute__((aligned(8))) regnames[NREGS][8] = 
00055 {
00056   "    V0: ", "    T0: ", "    T1: ",
00057   "    T2: ", "    T3: ", "    T4: ",
00058   "    T5: ", "    T6: ", "    T7: ",
00059   "    S0: ", "    S1: ", "    S2: ",
00060   "    S3: ", "    S4: ", "    S5: ",
00061   "    S6: ", "    A0: ", "    A1: ",
00062   "    A2: ", "    A3: ", "    A4: ",
00063   "    A5: ", "    T8: ", "    T9: ",
00064   "   T10: ", "   T11: ", "    RA: ",
00065   "   T12: ", "    AT: ", "    GP: ",
00066   "    SP: ", "    PC: ",
00067 
00068   "   FP0: ", "   FP1: ", "   FP2: ",
00069   "   FP3: ", "   FP4: ", "   FP5: ",
00070   "   FP6: ", "   FP7: ", "   FP8: ",
00071   "   FP9: ", "  FP10: ", "  FP11: ",
00072   "  FP12: ", "  FP13: ", "  FP14: ",
00073   "  FP15: ", "  FP16: ", "  FP17: ",
00074   "  FP18: ", "  FP19: ", "  FP20: ",
00075   "  FP21: ", "  FP22: ", "  FP23: ",
00076   "  FP24: ", "  FP25: ", "  FP26: ",
00077   "  FP27: ", "  FP28: ", "  FP29: ",
00078   "  FP30: ", "  FPCR: ",
00079 
00080   "   TA0: ", "   TA1: ", "   TA2: "
00081 };
00082 
00083 #define O(FIELD, LF)  offsetof(struct sigcontext, FIELD) + LF
00084 
00085 static const int offsets[NREGS] = 
00086 {
00087   O(sc_regs[0], 0),  O(sc_regs[1], 0),  O(sc_regs[2], 1),
00088   O(sc_regs[3], 0),  O(sc_regs[4], 0),  O(sc_regs[5], 1),
00089   O(sc_regs[6], 0),  O(sc_regs[7], 0),  O(sc_regs[8], 1),
00090   O(sc_regs[9], 0),  O(sc_regs[10], 0), O(sc_regs[11], 1),
00091   O(sc_regs[12], 0), O(sc_regs[13], 0), O(sc_regs[14], 1),
00092   O(sc_regs[15], 0), O(sc_regs[16], 0), O(sc_regs[17], 1),
00093   O(sc_regs[18], 0), O(sc_regs[19], 0), O(sc_regs[20], 1),
00094   O(sc_regs[21], 0), O(sc_regs[22], 0), O(sc_regs[23], 1),
00095   O(sc_regs[24], 0), O(sc_regs[25], 0), O(sc_regs[26], 1),
00096   O(sc_regs[27], 0), O(sc_regs[28], 0), O(sc_regs[29], 1),
00097   O(sc_regs[30], 0), O(sc_pc, 2),
00098 
00099   O(sc_fpregs[0], 0),  O(sc_fpregs[1], 0),  O(sc_fpregs[2], 1),
00100   O(sc_fpregs[3], 0),  O(sc_fpregs[4], 0),  O(sc_fpregs[5], 1),
00101   O(sc_fpregs[6], 0),  O(sc_fpregs[7], 0),  O(sc_fpregs[8], 1),
00102   O(sc_fpregs[9], 0),  O(sc_fpregs[10], 0), O(sc_fpregs[11], 1),
00103   O(sc_fpregs[12], 0), O(sc_fpregs[13], 0), O(sc_fpregs[14], 1),
00104   O(sc_fpregs[15], 0), O(sc_fpregs[16], 0), O(sc_fpregs[17], 1),
00105   O(sc_fpregs[18], 0), O(sc_fpregs[19], 0), O(sc_fpregs[20], 1),
00106   O(sc_fpregs[21], 0), O(sc_fpregs[22], 0), O(sc_fpregs[23], 1),
00107   O(sc_fpregs[24], 0), O(sc_fpregs[25], 0), O(sc_fpregs[26], 1),
00108   O(sc_fpregs[27], 0), O(sc_fpregs[28], 0), O(sc_fpregs[29], 1),
00109   O(sc_fpregs[30], 0), O(sc_fpcr, 2),
00110 
00111   O(sc_traparg_a0, 0),  O(sc_traparg_a1, 0),  O(sc_traparg_a2, 1)
00112 };
00113 
00114 #undef O
00115 
00116 static void
00117 register_dump (int fd, struct sigcontext *ctx)
00118 {
00119   char buf[NREGS*(8+16) + 25 + 80];
00120   char *p = buf;
00121   size_t i;
00122   
00123   p = stpcpy (p, "Register dump:\n\n");
00124 
00125   for (i = 0; i < NREGS; ++i)
00126     {
00127       int this_offset, this_lf;
00128       unsigned long val;
00129       signed long j;
00130       
00131       this_offset = offsets[i];
00132       this_lf = this_offset & 7;
00133 
00134       val = *(unsigned long *)(((size_t)ctx + this_offset) & -8);
00135 
00136       memcpy (p, regnames[i], 8);
00137       p += 8;
00138 
00139       for (j = 60; j >= 0; j -= 4)
00140        {
00141          unsigned long x = (val >> j) & 15;
00142          x += x < 10 ? '0' : 'a' - 10;
00143          *p++ = x;
00144        }
00145 
00146       if (this_lf > 0)
00147        {
00148          if (this_lf > 1)
00149            *p++ = '\n';
00150          *p++ = '\n';
00151        }
00152     }
00153 
00154   write (fd, buf, p - buf);
00155 }
00156 
00157 #define REGISTER_DUMP register_dump (fd, ctx)