2 Copyright (C) 1998-2022 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library. If not, see
17 <https://www.gnu.org/licenses/>. */
21 #include <sys/ucontext.h>
23 /* We will print the register dump in this format:
25 R0: XXXXXXXX R1: XXXXXXXX R2: XXXXXXXX R3: XXXXXXXX
26 R4: XXXXXXXX R5: XXXXXXXX R6: XXXXXXXX R7: XXXXXXXX
27 R8: XXXXXXXX R9: XXXXXXXX SL: XXXXXXXX FP: XXXXXXXX
28 IP: XXXXXXXX SP: XXXXXXXX LR: XXXXXXXX PC: XXXXXXXX
32 Trap: XXXXXXXX Error: XXXXXXXX OldMask: XXXXXXXX
38 hexvalue (unsigned long int value, char *buf, size_t len)
40 char *cp = _itoa_word (value, buf + len, 16, 0);
46 register_dump (int fd, const ucontext_t *ctx)
52 #define ADD_STRING(str) \
53 iov[nr].iov_base = (char *) str; \
54 iov[nr].iov_len = strlen (str); \
56 #define ADD_MEM(str, len) \
57 iov[nr].iov_base = str; \
58 iov[nr].iov_len = len; \
61 /* Generate strings of register contents. */
62 hexvalue (ctx->uc_mcontext.arm_r0, regs[0], 8);
63 hexvalue (ctx->uc_mcontext.arm_r1, regs[1], 8);
64 hexvalue (ctx->uc_mcontext.arm_r2, regs[2], 8);
65 hexvalue (ctx->uc_mcontext.arm_r3, regs[3], 8);
66 hexvalue (ctx->uc_mcontext.arm_r4, regs[4], 8);
67 hexvalue (ctx->uc_mcontext.arm_r5, regs[5], 8);
68 hexvalue (ctx->uc_mcontext.arm_r6, regs[6], 8);
69 hexvalue (ctx->uc_mcontext.arm_r7, regs[7], 8);
70 hexvalue (ctx->uc_mcontext.arm_r8, regs[8], 8);
71 hexvalue (ctx->uc_mcontext.arm_r9, regs[9], 8);
72 hexvalue (ctx->uc_mcontext.arm_r10, regs[10], 8);
73 hexvalue (ctx->uc_mcontext.arm_fp, regs[11], 8);
74 hexvalue (ctx->uc_mcontext.arm_ip, regs[12], 8);
75 hexvalue (ctx->uc_mcontext.arm_sp, regs[13], 8);
76 hexvalue (ctx->uc_mcontext.arm_lr, regs[14], 8);
77 hexvalue (ctx->uc_mcontext.arm_pc, regs[15], 8);
78 hexvalue (ctx->uc_mcontext.arm_cpsr, regs[16], 8);
79 hexvalue (ctx->uc_mcontext.trap_no, regs[17], 8);
80 hexvalue (ctx->uc_mcontext.error_code, regs[18], 8);
81 hexvalue (ctx->uc_mcontext.oldmask, regs[19], 8);
82 hexvalue (ctx->uc_mcontext.fault_address, regs[20], 8);
84 /* Generate the output. */
85 ADD_STRING ("Register dump:\n\n R0: ");
93 ADD_STRING ("\n R4: ");
100 ADD_MEM (regs[7], 8);
101 ADD_STRING ("\n R8: ");
102 ADD_MEM (regs[8], 8);
103 ADD_STRING (" R9: ");
104 ADD_MEM (regs[9], 8);
105 ADD_STRING (" SL: ");
106 ADD_MEM (regs[10], 8);
107 ADD_STRING (" FP: ");
108 ADD_MEM (regs[11], 8);
109 ADD_STRING ("\n IP: ");
110 ADD_MEM (regs[12], 8);
111 ADD_STRING (" SP: ");
112 ADD_MEM (regs[13], 8);
113 ADD_STRING (" LR: ");
114 ADD_MEM (regs[14], 8);
115 ADD_STRING (" PC: ");
116 ADD_MEM (regs[15], 8);
117 ADD_STRING ("\n\n CPSR: ");
118 ADD_MEM (regs[16], 8);
119 ADD_STRING ("\n\n Trap: ");
120 ADD_MEM (regs[17], 8);
121 ADD_STRING (" Error: ");
122 ADD_MEM (regs[18], 8);
123 ADD_STRING (" OldMask: ");
124 ADD_MEM (regs[19], 8);
125 ADD_STRING ("\n Addr: ");
126 ADD_MEM (regs[20], 8);
130 /* Write the stuff out. */
131 writev (fd, iov, nr);
135 #define REGISTER_DUMP register_dump (fd, ctx)