RegisterContextMinidump_x86_64.h revision 311145
1//===-- RegisterContextMinidump_x86_64.h ------------------------*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef liblldb_RegisterContextMinidump_h_
11#define liblldb_RegisterContextMinidump_h_
12
13// Project includes
14#include "MinidumpTypes.h"
15
16// Other libraries and framework includes
17#include "Plugins/Process/Utility/RegisterInfoInterface.h"
18#include "Plugins/Process/Utility/lldb-x86-register-enums.h"
19
20#include "lldb/Target/RegisterContext.h"
21
22#include "llvm/ADT/ArrayRef.h"
23#include "llvm/ADT/BitmaskEnum.h"
24#include "llvm/Support/Endian.h"
25
26// C includes
27// C++ includes
28
29namespace lldb_private {
30
31namespace minidump {
32
33// This function receives an ArrayRef pointing to the bytes of the Minidump
34// register context and returns a DataBuffer that's ordered by the offsets
35// specified in the RegisterInfoInterface argument
36// This way we can reuse the already existing register contexts
37lldb::DataBufferSP
38ConvertMinidumpContext_x86_64(llvm::ArrayRef<uint8_t> source_data,
39                              RegisterInfoInterface *target_reg_interface);
40
41struct Uint128 {
42  llvm::support::ulittle64_t high;
43  llvm::support::ulittle64_t low;
44};
45
46// Reference: see breakpad/crashpad source or WinNT.h
47struct MinidumpXMMSaveArea32AMD64 {
48  llvm::support::ulittle16_t control_word;
49  llvm::support::ulittle16_t status_word;
50  uint8_t tag_word;
51  uint8_t reserved1;
52  llvm::support::ulittle16_t error_opcode;
53  llvm::support::ulittle32_t error_offset;
54  llvm::support::ulittle16_t error_selector;
55  llvm::support::ulittle16_t reserved2;
56  llvm::support::ulittle32_t data_offset;
57  llvm::support::ulittle16_t data_selector;
58  llvm::support::ulittle16_t reserved3;
59  llvm::support::ulittle32_t mx_csr;
60  llvm::support::ulittle32_t mx_csr_mask;
61  Uint128 float_registers[8];
62  Uint128 xmm_registers[16];
63  uint8_t reserved4[96];
64};
65
66struct MinidumpContext_x86_64 {
67  // Register parameter home addresses.
68  llvm::support::ulittle64_t p1_home;
69  llvm::support::ulittle64_t p2_home;
70  llvm::support::ulittle64_t p3_home;
71  llvm::support::ulittle64_t p4_home;
72  llvm::support::ulittle64_t p5_home;
73  llvm::support::ulittle64_t p6_home;
74
75  // The context_flags field determines which parts
76  // of the structure are populated (have valid values)
77  llvm::support::ulittle32_t context_flags;
78  llvm::support::ulittle32_t mx_csr;
79
80  // The next register is included with
81  // MinidumpContext_x86_64_Flags::Control
82  llvm::support::ulittle16_t cs;
83
84  // The next 4 registers are included with
85  // MinidumpContext_x86_64_Flags::Segments
86  llvm::support::ulittle16_t ds;
87  llvm::support::ulittle16_t es;
88  llvm::support::ulittle16_t fs;
89  llvm::support::ulittle16_t gs;
90
91  // The next 2 registers are included with
92  // MinidumpContext_x86_64_Flags::Control
93  llvm::support::ulittle16_t ss;
94  llvm::support::ulittle32_t eflags;
95
96  // The next 6 registers are included with
97  // MinidumpContext_x86_64_Flags::DebugRegisters
98  llvm::support::ulittle64_t dr0;
99  llvm::support::ulittle64_t dr1;
100  llvm::support::ulittle64_t dr2;
101  llvm::support::ulittle64_t dr3;
102  llvm::support::ulittle64_t dr6;
103  llvm::support::ulittle64_t dr7;
104
105  // The next 4 registers are included with
106  // MinidumpContext_x86_64_Flags::Integer
107  llvm::support::ulittle64_t rax;
108  llvm::support::ulittle64_t rcx;
109  llvm::support::ulittle64_t rdx;
110  llvm::support::ulittle64_t rbx;
111
112  // The next register is included with
113  // MinidumpContext_x86_64_Flags::Control
114  llvm::support::ulittle64_t rsp;
115
116  // The next 11 registers are included with
117  // MinidumpContext_x86_64_Flags::Integer
118  llvm::support::ulittle64_t rbp;
119  llvm::support::ulittle64_t rsi;
120  llvm::support::ulittle64_t rdi;
121  llvm::support::ulittle64_t r8;
122  llvm::support::ulittle64_t r9;
123  llvm::support::ulittle64_t r10;
124  llvm::support::ulittle64_t r11;
125  llvm::support::ulittle64_t r12;
126  llvm::support::ulittle64_t r13;
127  llvm::support::ulittle64_t r14;
128  llvm::support::ulittle64_t r15;
129
130  // The next register is included with
131  // MinidumpContext_x86_64_Flags::Control
132  llvm::support::ulittle64_t rip;
133
134  // The next set of registers are included with
135  // MinidumpContext_x86_64_Flags:FloatingPoint
136  union FPR {
137    MinidumpXMMSaveArea32AMD64 flt_save;
138    struct {
139      Uint128 header[2];
140      Uint128 legacy[8];
141      Uint128 xmm[16];
142    } sse_registers;
143  };
144
145  enum {
146    VRCount = 26,
147  };
148
149  Uint128 vector_register[VRCount];
150  llvm::support::ulittle64_t vector_control;
151
152  // The next 5 registers are included with
153  // MinidumpContext_x86_64_Flags::DebugRegisters
154  llvm::support::ulittle64_t debug_control;
155  llvm::support::ulittle64_t last_branch_to_rip;
156  llvm::support::ulittle64_t last_branch_from_rip;
157  llvm::support::ulittle64_t last_exception_to_rip;
158  llvm::support::ulittle64_t last_exception_from_rip;
159};
160
161// For context_flags. These values indicate the type of
162// context stored in the structure. The high 24 bits identify the CPU, the
163// low 8 bits identify the type of context saved.
164LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE();
165
166enum class MinidumpContext_x86_64_Flags : uint32_t {
167  x86_64_Flag = 0x00100000,
168  Control = x86_64_Flag | 0x00000001,
169  Integer = x86_64_Flag | 0x00000002,
170  Segments = x86_64_Flag | 0x00000004,
171  FloatingPoint = x86_64_Flag | 0x00000008,
172  DebugRegisters = x86_64_Flag | 0x00000010,
173  XState = x86_64_Flag | 0x00000040,
174
175  Full = Control | Integer | FloatingPoint,
176  All = Full | Segments | DebugRegisters,
177
178  LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue = */ All)
179};
180
181} // end namespace minidump
182} // end namespace lldb_private
183#endif // liblldb_RegisterContextMinidump_h_
184