• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 namespace lldb_private {
17 /// Core files PT_NOTE segment descriptor types
18 
19 namespace NETBSD {
20 enum { NT_PROCINFO = 1, NT_AUXV = 2 };
21 
22 /* Size in bytes */
23 enum { NT_PROCINFO_SIZE = 160 };
24 
25 /* Size in bytes */
26 enum {
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 
50 namespace AARCH64 {
51 enum { NT_REGS = 32, NT_FPREGS = 34 };
52 }
53 
54 namespace AMD64 {
55 enum { NT_REGS = 33, NT_FPREGS = 35 };
56 }
57 
58 } // namespace NETBSD
59 
60 namespace OPENBSD {
61 enum {
62   NT_PROCINFO = 10,
63   NT_AUXV = 11,
64   NT_REGS = 20,
65   NT_FPREGS = 21,
66 };
67 }
68 
69 struct CoreNote {
70   ELFNote info;
71   DataExtractor data;
72 };
73 
74 // A structure describing how to find a register set in a core file from a given
75 // OS.
76 struct RegsetDesc {
77   // OS to which this entry applies to. Must not be UnknownOS.
78   llvm::Triple::OSType OS;
79 
80   // Architecture to which this entry applies to. Can be UnknownArch, in which
81   // case it applies to all architectures of a given OS.
82   llvm::Triple::ArchType Arch;
83 
84   // The note type under which the register set can be found.
85   uint32_t Note;
86 };
87 
88 // Returns the register set in Notes which corresponds to the specified Triple
89 // according to the list of register set descriptions in RegsetDescs. The list
90 // is scanned linearly, so you can use a more specific entry (e.g. linux-i386)
91 // to override a more general entry (e.g. general linux), as long as you place
92 // it earlier in the list. If a register set is not found, it returns an empty
93 // DataExtractor.
94 DataExtractor getRegset(llvm::ArrayRef<CoreNote> Notes,
95                         const llvm::Triple &Triple,
96                         llvm::ArrayRef<RegsetDesc> RegsetDescs);
97 
98 constexpr RegsetDesc FPR_Desc[] = {
99     {llvm::Triple::FreeBSD, llvm::Triple::UnknownArch, llvm::ELF::NT_FPREGSET},
100     // In a i386 core file NT_FPREGSET is present, but it's not the result
101     // of the FXSAVE instruction like in 64 bit files.
102     // The result from FXSAVE is in NT_PRXFPREG for i386 core files
103     {llvm::Triple::Linux, llvm::Triple::x86, llvm::ELF::NT_PRXFPREG},
104     {llvm::Triple::Linux, llvm::Triple::UnknownArch, llvm::ELF::NT_FPREGSET},
105     {llvm::Triple::NetBSD, llvm::Triple::aarch64, NETBSD::AARCH64::NT_FPREGS},
106     {llvm::Triple::NetBSD, llvm::Triple::x86_64, NETBSD::AMD64::NT_FPREGS},
107     {llvm::Triple::OpenBSD, llvm::Triple::UnknownArch, OPENBSD::NT_FPREGS},
108 };
109 
110 constexpr RegsetDesc AARCH64_SVE_Desc[] = {
111     {llvm::Triple::Linux, llvm::Triple::aarch64, llvm::ELF::NT_ARM_SVE},
112 };
113 
114 constexpr RegsetDesc PPC_VMX_Desc[] = {
115     {llvm::Triple::FreeBSD, llvm::Triple::UnknownArch, llvm::ELF::NT_PPC_VMX},
116     {llvm::Triple::Linux, llvm::Triple::UnknownArch, llvm::ELF::NT_PPC_VMX},
117 };
118 
119 constexpr RegsetDesc PPC_VSX_Desc[] = {
120     {llvm::Triple::Linux, llvm::Triple::UnknownArch, llvm::ELF::NT_PPC_VSX},
121 };
122 
123 } // namespace lldb_private
124 
125 #endif // LLDB_SOURCE_PLUGINS_PROCESS_ELF_CORE_REGISTERUTILITIES_H
126