Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * Mapping of DWARF debug register numbers into register names.
0004  *
0005  * Copyright IBM Corp. 2010, 2017
0006  * Author(s): Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
0007  *
0008  */
0009 
0010 #include <errno.h>
0011 #include <stddef.h>
0012 #include <stdlib.h>
0013 #include <linux/kernel.h>
0014 #include <asm/ptrace.h>
0015 #include <string.h>
0016 #include <dwarf-regs.h>
0017 #include "dwarf-regs-table.h"
0018 
0019 const char *get_arch_regstr(unsigned int n)
0020 {
0021     return (n >= ARRAY_SIZE(s390_dwarf_regs)) ? NULL : s390_dwarf_regs[n];
0022 }
0023 
0024 /*
0025  * Convert the register name into an offset to struct pt_regs (kernel).
0026  * This is required by the BPF prologue generator.  The BPF
0027  * program is called in the BPF overflow handler in the perf
0028  * core.
0029  */
0030 int regs_query_register_offset(const char *name)
0031 {
0032     unsigned long gpr;
0033 
0034     if (!name || strncmp(name, "%r", 2))
0035         return -EINVAL;
0036 
0037     errno = 0;
0038     gpr = strtoul(name + 2, NULL, 10);
0039     if (errno || gpr >= 16)
0040         return -EINVAL;
0041 
0042     return offsetof(user_pt_regs, gprs) + 8 * gpr;
0043 }