LLDB  mainline
RegisterContextMinidump_x86_64.cpp
Go to the documentation of this file.
1 //===-- RegisterContextMinidump_x86_64.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 
10 
12 
13 // C includes
14 // C++ includes
15 
16 using namespace lldb_private;
17 using namespace minidump;
18 
19 static llvm::MutableArrayRef<uint8_t> getDestRegister(uint8_t *context,
20  const RegisterInfo &reg) {
21  auto bytes = reg.mutable_data(context);
22 
23  switch (reg.kinds[lldb::eRegisterKindLLDB]) {
24  case lldb_cs_x86_64:
25  case lldb_ds_x86_64:
26  case lldb_es_x86_64:
27  case lldb_fs_x86_64:
28  case lldb_gs_x86_64:
29  case lldb_ss_x86_64:
30  return bytes.take_front(2);
31  break;
32  case lldb_rflags_x86_64:
33  return bytes.take_front(4);
34  break;
35  default:
36  return bytes.take_front(8);
37  break;
38  }
39 }
40 
41 static void writeRegister(const void *reg_src, uint8_t *context,
42  const RegisterInfo &reg) {
43  llvm::MutableArrayRef<uint8_t> reg_dest = getDestRegister(context, reg);
44  memcpy(reg_dest.data(), reg_src, reg_dest.size());
45 }
46 
48  llvm::ArrayRef<uint8_t> source_data,
49  RegisterInfoInterface *target_reg_interface) {
50 
51  const RegisterInfo *reg_info = target_reg_interface->GetRegisterInfo();
52 
53  lldb::DataBufferSP result_context_buf(
54  new DataBufferHeap(target_reg_interface->GetGPRSize(), 0));
55  uint8_t *result_base = result_context_buf->GetBytes();
56 
57  if (source_data.size() < sizeof(MinidumpContext_x86_64))
58  return nullptr;
59 
60  const MinidumpContext_x86_64 *context;
61  consumeObject(source_data, context);
62 
63  const MinidumpContext_x86_64_Flags context_flags =
64  static_cast<MinidumpContext_x86_64_Flags>(
65  static_cast<uint32_t>(context->context_flags));
67  auto ControlFlag = MinidumpContext_x86_64_Flags::Control;
68  auto IntegerFlag = MinidumpContext_x86_64_Flags::Integer;
69  auto SegmentsFlag = MinidumpContext_x86_64_Flags::Segments;
70 
71  if ((context_flags & x86_64_Flag) != x86_64_Flag)
72  return nullptr;
73 
74  if ((context_flags & ControlFlag) == ControlFlag) {
75  writeRegister(&context->cs, result_base, reg_info[lldb_cs_x86_64]);
76  writeRegister(&context->ss, result_base, reg_info[lldb_ss_x86_64]);
77  writeRegister(&context->eflags, result_base, reg_info[lldb_rflags_x86_64]);
78  writeRegister(&context->rsp, result_base, reg_info[lldb_rsp_x86_64]);
79  writeRegister(&context->rip, result_base, reg_info[lldb_rip_x86_64]);
80  }
81 
82  if ((context_flags & SegmentsFlag) == SegmentsFlag) {
83  writeRegister(&context->ds, result_base, reg_info[lldb_ds_x86_64]);
84  writeRegister(&context->es, result_base, reg_info[lldb_es_x86_64]);
85  writeRegister(&context->fs, result_base, reg_info[lldb_fs_x86_64]);
86  writeRegister(&context->gs, result_base, reg_info[lldb_gs_x86_64]);
87  }
88 
89  if ((context_flags & IntegerFlag) == IntegerFlag) {
90  writeRegister(&context->rax, result_base, reg_info[lldb_rax_x86_64]);
91  writeRegister(&context->rcx, result_base, reg_info[lldb_rcx_x86_64]);
92  writeRegister(&context->rdx, result_base, reg_info[lldb_rdx_x86_64]);
93  writeRegister(&context->rbx, result_base, reg_info[lldb_rbx_x86_64]);
94  writeRegister(&context->rbp, result_base, reg_info[lldb_rbp_x86_64]);
95  writeRegister(&context->rsi, result_base, reg_info[lldb_rsi_x86_64]);
96  writeRegister(&context->rdi, result_base, reg_info[lldb_rdi_x86_64]);
97  writeRegister(&context->r8, result_base, reg_info[lldb_r8_x86_64]);
98  writeRegister(&context->r9, result_base, reg_info[lldb_r9_x86_64]);
99  writeRegister(&context->r10, result_base, reg_info[lldb_r10_x86_64]);
100  writeRegister(&context->r11, result_base, reg_info[lldb_r11_x86_64]);
101  writeRegister(&context->r12, result_base, reg_info[lldb_r12_x86_64]);
102  writeRegister(&context->r13, result_base, reg_info[lldb_r13_x86_64]);
103  writeRegister(&context->r14, result_base, reg_info[lldb_r14_x86_64]);
104  writeRegister(&context->r15, result_base, reg_info[lldb_r15_x86_64]);
105  }
106 
107  // TODO parse the floating point registers
108 
109  return result_context_buf;
110 }
lldb_private::minidump::MinidumpContext_x86_64_Flags::Integer
@ Integer
lldb_private::minidump::MinidumpContext_x86_64::rsi
llvm::support::ulittle64_t rsi
Definition: RegisterContextMinidump_x86_64.h:116
lldb_private::lldb_r11_x86_64
@ lldb_r11_x86_64
Definition: lldb-x86-register-enums.h:153
lldb_private::lldb_rbp_x86_64
@ lldb_rbp_x86_64
Definition: lldb-x86-register-enums.h:148
lldb_private::lldb_r13_x86_64
@ lldb_r13_x86_64
Definition: lldb-x86-register-enums.h:155
lldb_private::minidump::MinidumpContext_x86_64::r14
llvm::support::ulittle64_t r14
Definition: RegisterContextMinidump_x86_64.h:124
lldb_private::lldb_r10_x86_64
@ lldb_r10_x86_64
Definition: lldb-x86-register-enums.h:152
lldb_private::RegisterInfoInterface
Definition: RegisterInfoInterface.h:21
lldb_private::lldb_r14_x86_64
@ lldb_r14_x86_64
Definition: lldb-x86-register-enums.h:156
lldb_private::minidump::MinidumpContext_x86_64
Definition: RegisterContextMinidump_x86_64.h:63
lldb_private::minidump::MinidumpContext_x86_64::r15
llvm::support::ulittle64_t r15
Definition: RegisterContextMinidump_x86_64.h:125
lldb_private::lldb_r8_x86_64
@ lldb_r8_x86_64
Definition: lldb-x86-register-enums.h:150
getDestRegister
static llvm::MutableArrayRef< uint8_t > getDestRegister(uint8_t *context, const RegisterInfo &reg)
Definition: RegisterContextMinidump_x86_64.cpp:19
lldb_private::minidump::MinidumpContext_x86_64_Flags
MinidumpContext_x86_64_Flags
Definition: RegisterContextMinidump_x86_64.h:163
lldb_private::minidump::MinidumpContext_x86_64::fs
llvm::support::ulittle16_t fs
Definition: RegisterContextMinidump_x86_64.h:85
writeRegister
static void writeRegister(const void *reg_src, uint8_t *context, const RegisterInfo &reg)
Definition: RegisterContextMinidump_x86_64.cpp:41
lldb_private::minidump::MinidumpContext_x86_64::rcx
llvm::support::ulittle64_t rcx
Definition: RegisterContextMinidump_x86_64.h:105
lldb_private::minidump::MinidumpContext_x86_64::context_flags
llvm::support::ulittle32_t context_flags
Definition: RegisterContextMinidump_x86_64.h:74
lldb_private::lldb_cs_x86_64
@ lldb_cs_x86_64
Definition: lldb-x86-register-enums.h:160
lldb_private::minidump::MinidumpContext_x86_64::eflags
llvm::support::ulittle32_t eflags
Definition: RegisterContextMinidump_x86_64.h:91
lldb_private::lldb_rdx_x86_64
@ lldb_rdx_x86_64
Definition: lldb-x86-register-enums.h:145
lldb_private::minidump::MinidumpContext_x86_64::ss
llvm::support::ulittle16_t ss
Definition: RegisterContextMinidump_x86_64.h:90
lldb_private::minidump::MinidumpContext_x86_64::rbp
llvm::support::ulittle64_t rbp
Definition: RegisterContextMinidump_x86_64.h:115
lldb_private::minidump::MinidumpContext_x86_64::r8
llvm::support::ulittle64_t r8
Definition: RegisterContextMinidump_x86_64.h:118
lldb::eRegisterKindLLDB
@ eRegisterKindLLDB
lldb's internal register numbers
Definition: lldb-enumerations.h:234
lldb_private::lldb_rip_x86_64
@ lldb_rip_x86_64
Definition: lldb-x86-register-enums.h:158
lldb_private::minidump::MinidumpContext_x86_64::gs
llvm::support::ulittle16_t gs
Definition: RegisterContextMinidump_x86_64.h:86
lldb_private::minidump::ConvertMinidumpContext_x86_64
lldb::DataBufferSP ConvertMinidumpContext_x86_64(llvm::ArrayRef< uint8_t > source_data, RegisterInfoInterface *target_reg_interface)
Definition: RegisterContextMinidump_x86_64.cpp:47
lldb_private::lldb_rbx_x86_64
@ lldb_rbx_x86_64
Definition: lldb-x86-register-enums.h:143
lldb_private::lldb_rcx_x86_64
@ lldb_rcx_x86_64
Definition: lldb-x86-register-enums.h:144
lldb_private::lldb_r12_x86_64
@ lldb_r12_x86_64
Definition: lldb-x86-register-enums.h:154
lldb_private::minidump::MinidumpContext_x86_64_Flags::Control
@ Control
lldb_private::minidump::MinidumpContext_x86_64_Flags::Segments
@ Segments
lldb_private::minidump::MinidumpContext_x86_64::r13
llvm::support::ulittle64_t r13
Definition: RegisterContextMinidump_x86_64.h:123
lldb_private::minidump::MinidumpContext_x86_64::rip
llvm::support::ulittle64_t rip
Definition: RegisterContextMinidump_x86_64.h:129
RegisterContextMinidump_x86_64.h
lldb_private::lldb_rsp_x86_64
@ lldb_rsp_x86_64
Definition: lldb-x86-register-enums.h:149
lldb_private::minidump::MinidumpContext_x86_64::rdx
llvm::support::ulittle64_t rdx
Definition: RegisterContextMinidump_x86_64.h:106
lldb_private::RegisterInfoInterface::GetRegisterInfo
virtual const lldb_private::RegisterInfo * GetRegisterInfo() const =0
lldb_private::minidump::MinidumpContext_x86_64::rax
llvm::support::ulittle64_t rax
Definition: RegisterContextMinidump_x86_64.h:104
lldb_private::lldb_rax_x86_64
@ lldb_rax_x86_64
Definition: lldb-x86-register-enums.h:142
lldb_private::lldb_r9_x86_64
@ lldb_r9_x86_64
Definition: lldb-x86-register-enums.h:151
lldb_private::lldb_ss_x86_64
@ lldb_ss_x86_64
Definition: lldb-x86-register-enums.h:163
uint32_t
lldb_private::minidump::MinidumpContext_x86_64_Flags::x86_64_Flag
@ x86_64_Flag
lldb_private::minidump::MinidumpContext_x86_64::rsp
llvm::support::ulittle64_t rsp
Definition: RegisterContextMinidump_x86_64.h:111
lldb_private::minidump::MinidumpContext_x86_64::r11
llvm::support::ulittle64_t r11
Definition: RegisterContextMinidump_x86_64.h:121
lldb_private::minidump::MinidumpContext_x86_64::r9
llvm::support::ulittle64_t r9
Definition: RegisterContextMinidump_x86_64.h:119
lldb_private::minidump::consumeObject
Status consumeObject(llvm::ArrayRef< uint8_t > &Buffer, const T *&Object)
Definition: MinidumpTypes.h:50
lldb_private::lldb_es_x86_64
@ lldb_es_x86_64
Definition: lldb-x86-register-enums.h:165
lldb_private::minidump::MinidumpContext_x86_64::rdi
llvm::support::ulittle64_t rdi
Definition: RegisterContextMinidump_x86_64.h:117
lldb_private::lldb_rflags_x86_64
@ lldb_rflags_x86_64
Definition: lldb-x86-register-enums.h:159
lldb_private::lldb_r15_x86_64
@ lldb_r15_x86_64
Definition: lldb-x86-register-enums.h:157
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::minidump::MinidumpContext_x86_64::ds
llvm::support::ulittle16_t ds
Definition: RegisterContextMinidump_x86_64.h:83
lldb_private::lldb_rsi_x86_64
@ lldb_rsi_x86_64
Definition: lldb-x86-register-enums.h:147
lldb_private::lldb_gs_x86_64
@ lldb_gs_x86_64
Definition: lldb-x86-register-enums.h:162
lldb_private::lldb_rdi_x86_64
@ lldb_rdi_x86_64
Definition: lldb-x86-register-enums.h:146
lldb_private::minidump::MinidumpContext_x86_64::r10
llvm::support::ulittle64_t r10
Definition: RegisterContextMinidump_x86_64.h:120
lldb_private::lldb_ds_x86_64
@ lldb_ds_x86_64
Definition: lldb-x86-register-enums.h:164
lldb_private::DataBufferHeap
Definition: DataBufferHeap.h:30
lldb_private::minidump::MinidumpContext_x86_64::cs
llvm::support::ulittle16_t cs
Definition: RegisterContextMinidump_x86_64.h:79
lldb_private::lldb_fs_x86_64
@ lldb_fs_x86_64
Definition: lldb-x86-register-enums.h:161
lldb_private::minidump::MinidumpContext_x86_64::es
llvm::support::ulittle16_t es
Definition: RegisterContextMinidump_x86_64.h:84
lldb_private::minidump::MinidumpContext_x86_64::rbx
llvm::support::ulittle64_t rbx
Definition: RegisterContextMinidump_x86_64.h:107
DataBufferHeap.h
lldb_private::RegisterInfoInterface::GetGPRSize
virtual size_t GetGPRSize() const =0
lldb_private::minidump::MinidumpContext_x86_64::r12
llvm::support::ulittle64_t r12
Definition: RegisterContextMinidump_x86_64.h:122