LLDB  mainline
RegisterContextLinux_i386.cpp
Go to the documentation of this file.
1 //===-- RegisterContextLinux_i386.cpp -------------------------------------===//
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 
11 
12 using namespace lldb_private;
13 using namespace lldb;
14 
15 struct GPR {
16  uint32_t ebx;
17  uint32_t ecx;
18  uint32_t edx;
19  uint32_t esi;
20  uint32_t edi;
21  uint32_t ebp;
22  uint32_t eax;
23  uint32_t ds;
24  uint32_t es;
25  uint32_t fs;
26  uint32_t gs;
28  uint32_t eip;
29  uint32_t cs;
30  uint32_t eflags;
31  uint32_t esp;
32  uint32_t ss;
33 };
34 
35 struct FPR_i386 {
36  uint16_t fctrl; // FPU Control Word (fcw)
37  uint16_t fstat; // FPU Status Word (fsw)
38  uint16_t ftag; // FPU Tag Word (ftw)
39  uint16_t fop; // Last Instruction Opcode (fop)
40  union {
41  struct {
42  uint64_t fip; // Instruction Pointer
43  uint64_t fdp; // Data Pointer
44  } x86_64;
45  struct {
46  uint32_t fioff; // FPU IP Offset (fip)
47  uint32_t fiseg; // FPU IP Selector (fcs)
48  uint32_t fooff; // FPU Operand Pointer Offset (foo)
49  uint32_t foseg; // FPU Operand Pointer Selector (fos)
50  } i386_; // Added _ in the end to avoid error with gcc defining i386 in some
51  // cases
52  } ptr;
53  uint32_t mxcsr; // MXCSR Register State
54  uint32_t mxcsrmask; // MXCSR Mask
55  MMSReg stmm[8]; // 8*16 bytes for each FP-reg = 128 bytes
56  XMMReg xmm[8]; // 8*16 bytes for each XMM-reg = 128 bytes
57  uint32_t padding[56];
58 };
59 
60 struct UserArea {
61  GPR regs; // General purpose registers.
62  int32_t fpvalid; // True if FPU is being used.
63  FPR_i386 i387; // FPU registers.
64  uint32_t tsize; // Text segment size.
65  uint32_t dsize; // Data segment size.
66  uint32_t ssize; // Stack segment size.
67  uint32_t start_code; // VM address of text.
68  uint32_t start_stack; // VM address of stack bottom (top in rsp).
69  int32_t signal; // Signal causing core dump.
70  int32_t reserved; // Unused.
71  uint32_t ar0; // Location of GPR's.
72  uint32_t fpstate; // Location of FPR's. Should be a FXSTATE *, but this
73  // has to be 32-bits even on 64-bit systems.
74  uint32_t magic; // Identifier for core dumps.
75  char u_comm[32]; // Command causing core dump.
76  uint32_t u_debugreg[8]; // Debug registers (DR0 - DR7).
77 };
78 
79 #define DR_SIZE sizeof(((UserArea *)NULL)->u_debugreg[0])
80 #define DR_0_OFFSET 0xFC
81 #define DR_OFFSET(reg_index) (DR_0_OFFSET + (reg_index * 4))
82 #define FPR_SIZE(reg) sizeof(((FPR_i386 *)NULL)->reg)
83 
84 // Include RegisterInfos_i386 to declare our g_register_infos_i386 structure.
85 #define DECLARE_REGISTER_INFOS_I386_STRUCT
86 #include "RegisterInfos_i386.h"
87 #undef DECLARE_REGISTER_INFOS_I386_STRUCT
88 
90  const ArchSpec &target_arch)
91  : RegisterInfoInterface(target_arch) {
92  RegisterInfo orig_ax = {
93  "orig_eax",
94  nullptr,
95  sizeof(((GPR *)nullptr)->orig_eax),
96  (LLVM_EXTENSION offsetof(GPR, orig_eax)),
98  eFormatHex,
101  nullptr,
102  nullptr,
103  };
104  d_register_infos.push_back(orig_ax);
105 }
106 
107 size_t RegisterContextLinux_i386::GetGPRSize() const { return sizeof(GPR); }
108 
109 const RegisterInfo *RegisterContextLinux_i386::GetRegisterInfo() const {
110  switch (m_target_arch.GetMachine()) {
111  case llvm::Triple::x86:
112  case llvm::Triple::x86_64:
113  return g_register_infos_i386;
114  default:
115  assert(false && "Unhandled target architecture.");
116  return nullptr;
117  }
118 }
119 
121  return static_cast<uint32_t>(sizeof(g_register_infos_i386) /
122  sizeof(g_register_infos_i386[0]));
123 }
124 
126  return static_cast<uint32_t>(k_num_user_registers_i386);
127 }
128 
129 const std::vector<lldb_private::RegisterInfo> *
131  return &d_register_infos;
132 }
lldb_private::RegisterInfoInterface::m_target_arch
lldb_private::ArchSpec m_target_arch
Definition: RegisterInfoInterface.h:65
RegisterContextLinux_i386::GetRegisterInfo
const lldb_private::RegisterInfo * GetRegisterInfo() const override
Definition: RegisterContextLinux_i386.cpp:109
UserArea::regs
GPR regs
Definition: RegisterContextLinux_i386.cpp:61
UserArea::fpvalid
int32_t fpvalid
Definition: RegisterContextLinux_i386.cpp:62
FPR_i386::fctrl
uint16_t fctrl
Definition: RegisterContextLinux_i386.cpp:36
lldb_private::ArchSpec
Definition: ArchSpec.h:33
UserArea::start_stack
uint32_t start_stack
Definition: RegisterContextLinux_i386.cpp:68
UserArea::fpstate
uint32_t fpstate
Definition: RegisterContextLinux_i386.cpp:72
LLDB_INVALID_REGNUM
#define LLDB_INVALID_REGNUM
Definition: lldb-defines.h:91
lldb_private::ArchSpec::GetMachine
llvm::Triple::ArchType GetMachine() const
Returns a machine family for the current architecture.
Definition: ArchSpec.cpp:667
FPR_i386::fstat
uint16_t fstat
Definition: RegisterContextLinux_i386.cpp:37
lldb_private::MMSReg
Definition: RegisterContext_x86.h:249
esp
@ esp
Definition: CompactUnwindInfo.cpp:978
lldb_private::RegisterInfoInterface
Definition: RegisterInfoInterface.h:21
FPR_i386::fioff
uint32_t fioff
Definition: RegisterContextLinux_i386.cpp:46
FPR_i386::mxcsrmask
uint32_t mxcsrmask
Definition: RegisterContextLinux_i386.cpp:54
ebp
@ ebp
Definition: CompactUnwindInfo.cpp:977
ebx
@ ebx
Definition: CompactUnwindInfo.cpp:976
edx
@ edx
Definition: CompactUnwindInfo.cpp:975
UserArea
Definition: RegisterContext_mips.h:368
RegisterContextLinux_i386.h
RegisterContextLinux_i386::d_register_infos
std::vector< lldb_private::RegisterInfo > d_register_infos
Definition: RegisterContextLinux_i386.h:30
RegisterContextPOSIX_x86.h
FPR_i386::fiseg
uint32_t fiseg
Definition: RegisterContextLinux_i386.cpp:47
UserArea::signal
int32_t signal
Definition: RegisterContextLinux_i386.cpp:69
lldb::eEncodingUint
@ eEncodingUint
unsigned integer
Definition: lldb-enumerations.h:148
UserArea::ar0
uint32_t ar0
Definition: RegisterContextLinux_i386.cpp:71
UserArea::tsize
uint32_t tsize
Definition: RegisterContextLinux_i386.cpp:64
FPR_i386::fip
uint64_t fip
Definition: RegisterContextLinux_i386.cpp:42
RegisterContextLinux_i386::RegisterContextLinux_i386
RegisterContextLinux_i386(const lldb_private::ArchSpec &target_arch)
Definition: RegisterContextLinux_i386.cpp:89
RegisterContextLinux_i386::GetDynamicRegisterInfoP
const std::vector< lldb_private::RegisterInfo > * GetDynamicRegisterInfoP() const override
Definition: RegisterContextLinux_i386.cpp:130
UserArea::start_code
uint32_t start_code
Definition: RegisterContextLinux_i386.cpp:67
GPR
Definition: RegisterContextFreeBSD_i386.cpp:16
FPR_i386::mxcsr
uint32_t mxcsr
Definition: RegisterContextLinux_i386.cpp:53
UserArea::dsize
uint32_t dsize
Definition: RegisterContextLinux_i386.cpp:65
ecx
@ ecx
Definition: CompactUnwindInfo.cpp:974
GPR
#define GPR(r16)
Definition: ABIX86.cpp:144
UserArea::reserved
int32_t reserved
Definition: RegisterContextLinux_i386.cpp:70
UserArea::ssize
uint32_t ssize
Definition: RegisterContextLinux_i386.cpp:66
uint32_t
UserArea::magic
uint32_t magic
Definition: RegisterContextLinux_i386.cpp:74
lldb_private::XMMReg
Definition: RegisterContext_x86.h:261
FPR_i386::fdp
uint64_t fdp
Definition: RegisterContextLinux_i386.cpp:43
edi
@ edi
Definition: CompactUnwindInfo.cpp:980
eax
@ eax
Definition: CompactUnwindInfo.cpp:973
uint16_t
FPR_i386::foseg
uint32_t foseg
Definition: RegisterContextLinux_i386.cpp:49
RegisterContextLinux_i386::GetRegisterCount
uint32_t GetRegisterCount() const override
Definition: RegisterContextLinux_i386.cpp:120
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb::eFormatHex
@ eFormatHex
Definition: lldb-enumerations.h:169
RegisterInfos_i386.h
esi
@ esi
Definition: CompactUnwindInfo.cpp:979
lldb
Definition: SBAddress.h:15
FPR_i386::fooff
uint32_t fooff
Definition: RegisterContextLinux_i386.cpp:48
FPR_i386::fop
uint16_t fop
Definition: RegisterContextLinux_i386.cpp:39
lldb_private::k_num_user_registers_i386
@ k_num_user_registers_i386
Definition: lldb-x86-register-enums.h:132
FPR_i386::ftag
uint16_t ftag
Definition: RegisterContextLinux_i386.cpp:38
RegisterContextLinux_i386::GetGPRSize
size_t GetGPRSize() const override
Definition: RegisterContextLinux_i386.cpp:107
FPR_i386
Definition: RegisterContextLinux_i386.cpp:35
GPR::orig_eax
uint32_t orig_eax
Definition: RegisterContextLinux_i386.cpp:27
RegisterContextLinux_i386::GetUserRegisterCount
uint32_t GetUserRegisterCount() const override
Definition: RegisterContextLinux_i386.cpp:125
eip
@ eip
Definition: CompactUnwindInfo.cpp:981