]> git.ipfire.org Git - thirdparty/glibc.git/blame - ports/sysdeps/unix/sysv/linux/arm/register-dump.h
Update copyright notices with scripts/update-copyrights
[thirdparty/glibc.git] / ports / sysdeps / unix / sysv / linux / arm / register-dump.h
CommitLineData
e5432e28 1/* Dump registers.
d4697bc9 2 Copyright (C) 1998-2014 Free Software Foundation, Inc.
e5432e28
UD
3 This file is part of the GNU C Library.
4 Contributed by Philip Blundell <pb@nexus.co.uk>, 1998.
5
6 The GNU C Library is free software; you can redistribute it and/or
3214b89b
AJ
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
e5432e28
UD
10
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3214b89b 14 Lesser General Public License for more details.
e5432e28 15
3214b89b 16 You should have received a copy of the GNU Lesser General Public
ab84e3ff
PE
17 License along with the GNU C Library. If not, see
18 <http://www.gnu.org/licenses/>. */
e5432e28
UD
19
20#include <sys/uio.h>
bf98494a 21#include <_itoa.h>
c206ce7f 22#include <sys/ucontext.h>
e5432e28
UD
23
24/* We will print the register dump in this format:
25
26 R0: XXXXXXXX R1: XXXXXXXX R2: XXXXXXXX R3: XXXXXXXX
27 R4: XXXXXXXX R5: XXXXXXXX R6: XXXXXXXX R7: XXXXXXXX
28 R8: XXXXXXXX R9: XXXXXXXX SL: XXXXXXXX FP: XXXXXXXX
29 IP: XXXXXXXX SP: XXXXXXXX LR: XXXXXXXX PC: XXXXXXXX
30
31 CPSR: XXXXXXXX
32
33 Trap: XXXXXXXX Error: XXXXXXXX OldMask: XXXXXXXX
7ace52d0 34 Addr: XXXXXXXX
e5432e28
UD
35
36 */
37
38static void
39hexvalue (unsigned long int value, char *buf, size_t len)
40{
41 char *cp = _itoa_word (value, buf + len, 16, 0);
42 while (cp > buf)
43 *--cp = '0';
44}
45
46static void
c206ce7f 47register_dump (int fd, const struct ucontext *ctx)
e5432e28 48{
7ace52d0 49 char regs[21][8];
e5432e28
UD
50 struct iovec iov[97];
51 size_t nr = 0;
52
53#define ADD_STRING(str) \
54 iov[nr].iov_base = (char *) str; \
55 iov[nr].iov_len = strlen (str); \
56 ++nr
57#define ADD_MEM(str, len) \
58 iov[nr].iov_base = str; \
59 iov[nr].iov_len = len; \
60 ++nr
61
62 /* Generate strings of register contents. */
c206ce7f
DJ
63 hexvalue (ctx->uc_mcontext.arm_r0, regs[0], 8);
64 hexvalue (ctx->uc_mcontext.arm_r1, regs[1], 8);
65 hexvalue (ctx->uc_mcontext.arm_r2, regs[2], 8);
66 hexvalue (ctx->uc_mcontext.arm_r3, regs[3], 8);
67 hexvalue (ctx->uc_mcontext.arm_r4, regs[4], 8);
68 hexvalue (ctx->uc_mcontext.arm_r5, regs[5], 8);
69 hexvalue (ctx->uc_mcontext.arm_r6, regs[6], 8);
70 hexvalue (ctx->uc_mcontext.arm_r7, regs[7], 8);
71 hexvalue (ctx->uc_mcontext.arm_r8, regs[8], 8);
72 hexvalue (ctx->uc_mcontext.arm_r9, regs[9], 8);
73 hexvalue (ctx->uc_mcontext.arm_r10, regs[10], 8);
74 hexvalue (ctx->uc_mcontext.arm_fp, regs[11], 8);
75 hexvalue (ctx->uc_mcontext.arm_ip, regs[12], 8);
76 hexvalue (ctx->uc_mcontext.arm_sp, regs[13], 8);
77 hexvalue (ctx->uc_mcontext.arm_lr, regs[14], 8);
78 hexvalue (ctx->uc_mcontext.arm_pc, regs[15], 8);
79 hexvalue (ctx->uc_mcontext.arm_cpsr, regs[16], 8);
80 hexvalue (ctx->uc_mcontext.trap_no, regs[17], 8);
81 hexvalue (ctx->uc_mcontext.error_code, regs[18], 8);
82 hexvalue (ctx->uc_mcontext.oldmask, regs[19], 8);
83 hexvalue (ctx->uc_mcontext.fault_address, regs[20], 8);
e5432e28
UD
84
85 /* Generate the output. */
86 ADD_STRING ("Register dump:\n\n R0: ");
87 ADD_MEM (regs[0], 8);
88 ADD_STRING (" R1: ");
89 ADD_MEM (regs[1], 8);
90 ADD_STRING (" R2: ");
91 ADD_MEM (regs[2], 8);
92 ADD_STRING (" R3: ");
93 ADD_MEM (regs[3], 8);
94 ADD_STRING ("\n R4: ");
95 ADD_MEM (regs[4], 8);
96 ADD_STRING (" R5: ");
97 ADD_MEM (regs[5], 8);
98 ADD_STRING (" R6: ");
99 ADD_MEM (regs[6], 8);
100 ADD_STRING (" R7: ");
101 ADD_MEM (regs[7], 8);
102 ADD_STRING ("\n R8: ");
103 ADD_MEM (regs[8], 8);
104 ADD_STRING (" R9: ");
105 ADD_MEM (regs[9], 8);
106 ADD_STRING (" SL: ");
107 ADD_MEM (regs[10], 8);
108 ADD_STRING (" FP: ");
109 ADD_MEM (regs[11], 8);
110 ADD_STRING ("\n IP: ");
111 ADD_MEM (regs[12], 8);
112 ADD_STRING (" SP: ");
113 ADD_MEM (regs[13], 8);
114 ADD_STRING (" LR: ");
115 ADD_MEM (regs[14], 8);
116 ADD_STRING (" PC: ");
117 ADD_MEM (regs[15], 8);
118 ADD_STRING ("\n\n CPSR: ");
119 ADD_MEM (regs[16], 8);
120 ADD_STRING ("\n\n Trap: ");
121 ADD_MEM (regs[17], 8);
122 ADD_STRING (" Error: ");
123 ADD_MEM (regs[18], 8);
124 ADD_STRING (" OldMask: ");
125 ADD_MEM (regs[19], 8);
c206ce7f
DJ
126 ADD_STRING ("\n Addr: ");
127 ADD_MEM (regs[20], 8);
e5432e28
UD
128
129 ADD_STRING ("\n");
130
131 /* Write the stuff out. */
132 writev (fd, iov, nr);
133}
134
135
c206ce7f 136#define REGISTER_DUMP register_dump (fd, ctx)