|
| 1 | +/* |
| 2 | + * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 3 | + * See https://llvm.org/LICENSE.txt for license information. |
| 4 | + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 5 | + * |
| 6 | + */ |
| 7 | + |
| 8 | +#include <sys/ucontext.h> |
| 9 | +#include <stdio.h> |
| 10 | +#include <stdint.h> |
| 11 | +#include <inttypes.h> |
| 12 | +#include <ctype.h> |
| 13 | +#include "stdioInterf.h" |
| 14 | + |
| 15 | +typedef struct { |
| 16 | + int rn; // Register index in to "regs" pointer |
| 17 | + char *s; // Symbolic name of register |
| 18 | +} gprs_t; |
| 19 | + |
| 20 | + |
| 21 | +/* |
| 22 | + * The way the structure below is organized, the registers are all |
| 23 | + * sequential with no gaps - the structure is probably overkill - but |
| 24 | + * allows for some flexibility. |
| 25 | + */ |
| 26 | + |
| 27 | +gprs_t gprs[] = { |
| 28 | + { 0, "x0" }, { 1, "x1" }, { 2, "x2"}, { 3, "x3" }, { 4, "x4" }, |
| 29 | + { 5, "x5" }, { 6, "x6" }, { 7, "x7" }, { 8, "x8" }, { 9, "x9" }, |
| 30 | + {10, "x10"}, {11, "x11"}, {12, "x12"}, {13, "x13"}, {14, "x14"}, |
| 31 | + {15, "x15"}, {16, "x16"}, {17, "x17"}, {18, "x18"}, {19, "x19"}, |
| 32 | + {20, "x20"}, {21, "x21"}, {22, "x22"}, {23, "x23"}, {24, "xr24"}, |
| 33 | + {25, "x25"}, {26, "x26"}, {27, "x27"}, {28, "x28"}, {29, "x29"}, |
| 34 | + {30, "x30"}, {31, "x31"}, |
| 35 | +}; |
| 36 | + |
| 37 | +void |
| 38 | +dumpregs(uint64_t *regs) |
| 39 | +{ |
| 40 | + int i; |
| 41 | + int j; |
| 42 | + char *pc = NULL; |
| 43 | + |
| 44 | + if (regs == NULL) |
| 45 | + return; // Not sure if this is possible |
| 46 | + |
| 47 | +/* |
| 48 | + * Output has the following format: |
| 49 | + * <REG> <HEXADECIMAL> <DECIMAL> <ASCII> |
| 50 | + * Example: |
| 51 | + * r0 0x00003fffaf4a309c 70367390085276 .0J..?.. |
| 52 | + * sp 0x00003ffff437d1a0 70368546509216 ..7..?.. |
| 53 | + * toc 0x0000000010019300 268538624 ........ |
| 54 | + * r3 0x0000000010000e64 268439140 d....... |
| 55 | + * ... |
| 56 | + */ |
| 57 | + |
| 58 | + for (i = 0; i < sizeof gprs / sizeof *gprs; ++i) { |
| 59 | + fprintf(__io_stderr(), " %-8s 0x%016" PRIx64 " %20" PRId64 "\t", |
| 60 | + gprs[i].s, regs[gprs[i].rn], regs[gprs[i].rn]); |
| 61 | + pc = (char *)&(regs[gprs[i].rn]); |
| 62 | + for (j = 0; j < 8; ++j) { |
| 63 | + fputc(isprint(pc[j]) ? pc[j] : '.', __io_stderr()); |
| 64 | + } |
| 65 | + fputs("\n", __io_stderr()); |
| 66 | + } |
| 67 | +} |
| 68 | + |
| 69 | +uint64_t * |
| 70 | +getRegs(ucontext_t *u) |
| 71 | +{ |
| 72 | + mcontext_t *mc = &u->uc_mcontext; |
| 73 | + return (uint64_t *)&(mc->__gregs); |
| 74 | +} |
0 commit comments