1//===-- RegisterUtilities.h -------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_SOURCE_PLUGINS_PROCESS_ELF_CORE_REGISTERUTILITIES_H
10#define LLDB_SOURCE_PLUGINS_PROCESS_ELF_CORE_REGISTERUTILITIES_H
11
12#include "Plugins/ObjectFile/ELF/ObjectFileELF.h"
13#include "lldb/Utility/DataExtractor.h"
14#include "llvm/BinaryFormat/ELF.h"
15
16namespace lldb_private {
17/// Core files PT_NOTE segment descriptor types
18
19namespace NETBSD {
20enum { NT_PROCINFO = 1, NT_AUXV = 2 };
21
22/* Size in bytes */
23enum { NT_PROCINFO_SIZE = 160 };
24
25/* Size in bytes */
26enum {
27 NT_PROCINFO_CPI_VERSION_SIZE = 4,
28 NT_PROCINFO_CPI_CPISIZE_SIZE = 4,
29 NT_PROCINFO_CPI_SIGNO_SIZE = 4,
30 NT_PROCINFO_CPI_SIGCODE_SIZE = 4,
31 NT_PROCINFO_CPI_SIGPEND_SIZE = 16,
32 NT_PROCINFO_CPI_SIGMASK_SIZE = 16,
33 NT_PROCINFO_CPI_SIGIGNORE_SIZE = 16,
34 NT_PROCINFO_CPI_SIGCATCH_SIZE = 16,
35 NT_PROCINFO_CPI_PID_SIZE = 4,
36 NT_PROCINFO_CPI_PPID_SIZE = 4,
37 NT_PROCINFO_CPI_PGRP_SIZE = 4,
38 NT_PROCINFO_CPI_SID_SIZE = 4,
39 NT_PROCINFO_CPI_RUID_SIZE = 4,
40 NT_PROCINFO_CPI_EUID_SIZE = 4,
41 NT_PROCINFO_CPI_SVUID_SIZE = 4,
42 NT_PROCINFO_CPI_RGID_SIZE = 4,
43 NT_PROCINFO_CPI_EGID_SIZE = 4,
44 NT_PROCINFO_CPI_SVGID_SIZE = 4,
45 NT_PROCINFO_CPI_NLWPS_SIZE = 4,
46 NT_PROCINFO_CPI_NAME_SIZE = 32,
47 NT_PROCINFO_CPI_SIGLWP_SIZE = 4,
48};
49
50namespace AARCH64 {
51enum { NT_REGS = 32, NT_FPREGS = 34 };
52}
53
54namespace AMD64 {
55enum { NT_REGS = 33, NT_FPREGS = 35 };
56}
57
58namespace I386 {
59enum { NT_REGS = 33, NT_FPREGS = 35 };
60}
61
62} // namespace NETBSD
63
64namespace OPENBSD {
65enum {
66 NT_PROCINFO = 10,
67 NT_AUXV = 11,
68 NT_REGS = 20,
69 NT_FPREGS = 21,
70};
71}
72
73struct CoreNote {
74 ELFNote info;
75 DataExtractor data;
76};
77
78// A structure describing how to find a register set in a core file from a given
79// OS.
80struct RegsetDesc {
81 // OS to which this entry applies to. Must not be UnknownOS.
82 llvm::Triple::OSType OS;
83
84 // Architecture to which this entry applies to. Can be UnknownArch, in which
85 // case it applies to all architectures of a given OS.
86 llvm::Triple::ArchType Arch;
87
88 // The note type under which the register set can be found.
89 uint32_t Note;
90};
91
92// Returns the register set in Notes which corresponds to the specified Triple
93// according to the list of register set descriptions in RegsetDescs. The list
94// is scanned linearly, so you can use a more specific entry (e.g. linux-i386)
95// to override a more general entry (e.g. general linux), as long as you place
96// it earlier in the list. If a register set is not found, it returns an empty
97// DataExtractor.
98DataExtractor getRegset(llvm::ArrayRef<CoreNote> Notes,
99 const llvm::Triple &Triple,
100 llvm::ArrayRef<RegsetDesc> RegsetDescs);
101
102constexpr RegsetDesc FPR_Desc[] = {
103 // FreeBSD/i386 core NT_FPREGSET is x87 FSAVE result but the XSAVE dump
104 // starts with FXSAVE struct, so use that instead if available.
105 {.OS: llvm::Triple::FreeBSD, .Arch: llvm::Triple::x86, .Note: llvm::ELF::NT_X86_XSTATE},
106 {.OS: llvm::Triple::FreeBSD, .Arch: llvm::Triple::UnknownArch, .Note: llvm::ELF::NT_FPREGSET},
107 // In a i386 core file NT_FPREGSET is present, but it's not the result
108 // of the FXSAVE instruction like in 64 bit files.
109 // The result from FXSAVE is in NT_PRXFPREG for i386 core files
110 {.OS: llvm::Triple::Linux, .Arch: llvm::Triple::x86, .Note: llvm::ELF::NT_PRXFPREG},
111 {.OS: llvm::Triple::Linux, .Arch: llvm::Triple::UnknownArch, .Note: llvm::ELF::NT_FPREGSET},
112 {.OS: llvm::Triple::NetBSD, .Arch: llvm::Triple::aarch64, .Note: NETBSD::AARCH64::NT_FPREGS},
113 {.OS: llvm::Triple::NetBSD, .Arch: llvm::Triple::x86, .Note: NETBSD::I386::NT_FPREGS},
114 {.OS: llvm::Triple::NetBSD, .Arch: llvm::Triple::x86_64, .Note: NETBSD::AMD64::NT_FPREGS},
115 {.OS: llvm::Triple::OpenBSD, .Arch: llvm::Triple::UnknownArch, .Note: OPENBSD::NT_FPREGS},
116};
117
118constexpr RegsetDesc AARCH64_SVE_Desc[] = {
119 {.OS: llvm::Triple::Linux, .Arch: llvm::Triple::aarch64, .Note: llvm::ELF::NT_ARM_SVE},
120};
121
122constexpr RegsetDesc AARCH64_SSVE_Desc[] = {
123 {.OS: llvm::Triple::Linux, .Arch: llvm::Triple::aarch64, .Note: llvm::ELF::NT_ARM_SSVE},
124};
125
126constexpr RegsetDesc AARCH64_ZA_Desc[] = {
127 {.OS: llvm::Triple::Linux, .Arch: llvm::Triple::aarch64, .Note: llvm::ELF::NT_ARM_ZA},
128};
129
130constexpr RegsetDesc AARCH64_ZT_Desc[] = {
131 {.OS: llvm::Triple::Linux, .Arch: llvm::Triple::aarch64, .Note: llvm::ELF::NT_ARM_ZT},
132};
133
134constexpr RegsetDesc AARCH64_PAC_Desc[] = {
135 {.OS: llvm::Triple::Linux, .Arch: llvm::Triple::aarch64, .Note: llvm::ELF::NT_ARM_PAC_MASK},
136};
137
138constexpr RegsetDesc AARCH64_TLS_Desc[] = {
139 {.OS: llvm::Triple::Linux, .Arch: llvm::Triple::aarch64, .Note: llvm::ELF::NT_ARM_TLS},
140};
141
142constexpr RegsetDesc AARCH64_MTE_Desc[] = {
143 {.OS: llvm::Triple::Linux, .Arch: llvm::Triple::aarch64,
144 .Note: llvm::ELF::NT_ARM_TAGGED_ADDR_CTRL},
145};
146
147constexpr RegsetDesc PPC_VMX_Desc[] = {
148 {.OS: llvm::Triple::FreeBSD, .Arch: llvm::Triple::UnknownArch, .Note: llvm::ELF::NT_PPC_VMX},
149 {.OS: llvm::Triple::Linux, .Arch: llvm::Triple::UnknownArch, .Note: llvm::ELF::NT_PPC_VMX},
150};
151
152constexpr RegsetDesc PPC_VSX_Desc[] = {
153 {.OS: llvm::Triple::Linux, .Arch: llvm::Triple::UnknownArch, .Note: llvm::ELF::NT_PPC_VSX},
154};
155
156} // namespace lldb_private
157
158#endif // LLDB_SOURCE_PLUGINS_PROCESS_ELF_CORE_REGISTERUTILITIES_H
159

source code of lldb/source/Plugins/Process/elf-core/RegisterUtilities.h