LLDB  mainline
RegisterContextMinidump_x86_32.cpp
Go to the documentation of this file.
1 //===-- RegisterContextMinidump_x86_32.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 void writeRegister(const void *reg_src,
20  llvm::MutableArrayRef<uint8_t> reg_dest) {
21  memcpy(reg_dest.data(), reg_src, reg_dest.size());
22 }
23 
25  llvm::ArrayRef<uint8_t> source_data,
26  RegisterInfoInterface *target_reg_interface) {
27 
28  const RegisterInfo *reg_info = target_reg_interface->GetRegisterInfo();
29 
30  lldb::DataBufferSP result_context_buf(
31  new DataBufferHeap(target_reg_interface->GetGPRSize(), 0));
32  uint8_t *result_base = result_context_buf->GetBytes();
33 
34  if (source_data.size() < sizeof(MinidumpContext_x86_32))
35  return nullptr;
36 
37  const MinidumpContext_x86_32 *context;
38  consumeObject(source_data, context);
39 
40  const MinidumpContext_x86_32_Flags context_flags =
41  static_cast<MinidumpContext_x86_32_Flags>(
42  static_cast<uint32_t>(context->context_flags));
44  auto ControlFlag = MinidumpContext_x86_32_Flags::Control;
45  auto IntegerFlag = MinidumpContext_x86_32_Flags::Integer;
46  auto SegmentsFlag = MinidumpContext_x86_32_Flags::Segments;
47 
48  if ((context_flags & x86_32_Flag) != x86_32_Flag) {
49  return nullptr;
50  }
51 
52  if ((context_flags & ControlFlag) == ControlFlag) {
53  writeRegister(&context->ebp,
54  reg_info[lldb_ebp_i386].mutable_data(result_base));
55  writeRegister(&context->eip,
56  reg_info[lldb_eip_i386].mutable_data(result_base));
57  writeRegister(&context->cs,
58  reg_info[lldb_cs_i386].mutable_data(result_base));
59  writeRegister(&context->eflags,
60  reg_info[lldb_eflags_i386].mutable_data(result_base));
61  writeRegister(&context->esp,
62  reg_info[lldb_esp_i386].mutable_data(result_base));
63  writeRegister(&context->ss,
64  reg_info[lldb_ss_i386].mutable_data(result_base));
65  }
66 
67  if ((context_flags & SegmentsFlag) == SegmentsFlag) {
68  writeRegister(&context->ds,
69  reg_info[lldb_ds_i386].mutable_data(result_base));
70  writeRegister(&context->es,
71  reg_info[lldb_es_i386].mutable_data(result_base));
72  writeRegister(&context->fs,
73  reg_info[lldb_fs_i386].mutable_data(result_base));
74  writeRegister(&context->gs,
75  reg_info[lldb_gs_i386].mutable_data(result_base));
76  }
77 
78  if ((context_flags & IntegerFlag) == IntegerFlag) {
79  writeRegister(&context->eax,
80  reg_info[lldb_eax_i386].mutable_data(result_base));
81  writeRegister(&context->ecx,
82  reg_info[lldb_ecx_i386].mutable_data(result_base));
83  writeRegister(&context->edx,
84  reg_info[lldb_edx_i386].mutable_data(result_base));
85  writeRegister(&context->ebx,
86  reg_info[lldb_ebx_i386].mutable_data(result_base));
87  writeRegister(&context->esi,
88  reg_info[lldb_esi_i386].mutable_data(result_base));
89  writeRegister(&context->edi,
90  reg_info[lldb_edi_i386].mutable_data(result_base));
91  }
92 
93  // TODO parse the floating point registers
94 
95  return result_context_buf;
96 }
lldb_private::minidump::MinidumpContext_x86_32::context_flags
llvm::support::ulittle32_t context_flags
Definition: RegisterContextMinidump_x86_32.h:60
RegisterContextMinidump_x86_32.h
lldb_private::minidump::ConvertMinidumpContext_x86_32
lldb::DataBufferSP ConvertMinidumpContext_x86_32(llvm::ArrayRef< uint8_t > source_data, RegisterInfoInterface *target_reg_interface)
Definition: RegisterContextMinidump_x86_32.cpp:24
lldb_private::minidump::MinidumpContext_x86_32_Flags::Segments
@ Segments
lldb_private::lldb_esp_i386
@ lldb_esp_i386
Definition: lldb-x86-register-enums.h:25
lldb_private::minidump::MinidumpContext_x86_32_Flags
MinidumpContext_x86_32_Flags
Definition: RegisterContextMinidump_x86_32.h:117
lldb_private::RegisterInfoInterface
Definition: RegisterInfoInterface.h:21
lldb_private::minidump::MinidumpContext_x86_32::es
llvm::support::ulittle32_t es
Definition: RegisterContextMinidump_x86_32.h:79
lldb_private::minidump::MinidumpContext_x86_32::edi
llvm::support::ulittle32_t edi
Definition: RegisterContextMinidump_x86_32.h:84
lldb_private::minidump::MinidumpContext_x86_32::edx
llvm::support::ulittle32_t edx
Definition: RegisterContextMinidump_x86_32.h:87
lldb_private::minidump::MinidumpContext_x86_32::eflags
llvm::support::ulittle32_t eflags
Definition: RegisterContextMinidump_x86_32.h:96
lldb_private::minidump::MinidumpContext_x86_32::eax
llvm::support::ulittle32_t eax
Definition: RegisterContextMinidump_x86_32.h:89
lldb_private::lldb_eax_i386
@ lldb_eax_i386
Definition: lldb-x86-register-enums.h:18
lldb_private::minidump::MinidumpContext_x86_32::ebx
llvm::support::ulittle32_t ebx
Definition: RegisterContextMinidump_x86_32.h:86
lldb_private::minidump::MinidumpContext_x86_32_Flags::x86_32_Flag
@ x86_32_Flag
lldb_private::minidump::MinidumpContext_x86_32::ss
llvm::support::ulittle32_t ss
Definition: RegisterContextMinidump_x86_32.h:98
lldb_private::minidump::MinidumpContext_x86_32::eip
llvm::support::ulittle32_t eip
Definition: RegisterContextMinidump_x86_32.h:94
lldb_private::lldb_es_i386
@ lldb_es_i386
Definition: lldb-x86-register-enums.h:33
lldb_private::lldb_edi_i386
@ lldb_edi_i386
Definition: lldb-x86-register-enums.h:22
lldb_private::minidump::MinidumpContext_x86_32::cs
llvm::support::ulittle32_t cs
Definition: RegisterContextMinidump_x86_32.h:95
lldb_private::minidump::MinidumpContext_x86_32::ebp
llvm::support::ulittle32_t ebp
Definition: RegisterContextMinidump_x86_32.h:93
lldb_private::lldb_ecx_i386
@ lldb_ecx_i386
Definition: lldb-x86-register-enums.h:20
lldb_private::minidump::MinidumpContext_x86_32::esi
llvm::support::ulittle32_t esi
Definition: RegisterContextMinidump_x86_32.h:85
lldb_private::lldb_ebx_i386
@ lldb_ebx_i386
Definition: lldb-x86-register-enums.h:19
lldb_private::RegisterInfoInterface::GetRegisterInfo
virtual const lldb_private::RegisterInfo * GetRegisterInfo() const =0
lldb_private::minidump::MinidumpContext_x86_32
Definition: RegisterContextMinidump_x86_32.h:57
lldb_private::minidump::MinidumpContext_x86_32::ecx
llvm::support::ulittle32_t ecx
Definition: RegisterContextMinidump_x86_32.h:88
lldb_private::lldb_fs_i386
@ lldb_fs_i386
Definition: lldb-x86-register-enums.h:29
lldb_private::lldb_cs_i386
@ lldb_cs_i386
Definition: lldb-x86-register-enums.h:28
uint32_t
lldb_private::lldb_ds_i386
@ lldb_ds_i386
Definition: lldb-x86-register-enums.h:32
lldb_private::lldb_edx_i386
@ lldb_edx_i386
Definition: lldb-x86-register-enums.h:21
lldb_private::lldb_ebp_i386
@ lldb_ebp_i386
Definition: lldb-x86-register-enums.h:24
lldb_private::lldb_ss_i386
@ lldb_ss_i386
Definition: lldb-x86-register-enums.h:31
lldb_private::minidump::consumeObject
Status consumeObject(llvm::ArrayRef< uint8_t > &Buffer, const T *&Object)
Definition: MinidumpTypes.h:50
lldb_private::lldb_esi_i386
@ lldb_esi_i386
Definition: lldb-x86-register-enums.h:23
lldb_private::lldb_eflags_i386
@ lldb_eflags_i386
Definition: lldb-x86-register-enums.h:27
lldb_private::minidump::MinidumpContext_x86_32::esp
llvm::support::ulittle32_t esp
Definition: RegisterContextMinidump_x86_32.h:97
lldb_private::minidump::MinidumpContext_x86_32_Flags::Control
@ Control
lldb_private::minidump::MinidumpContext_x86_32::gs
llvm::support::ulittle32_t gs
Definition: RegisterContextMinidump_x86_32.h:77
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::minidump::MinidumpContext_x86_32::fs
llvm::support::ulittle32_t fs
Definition: RegisterContextMinidump_x86_32.h:78
writeRegister
static void writeRegister(const void *reg_src, llvm::MutableArrayRef< uint8_t > reg_dest)
Definition: RegisterContextMinidump_x86_32.cpp:19
lldb_private::DataBufferHeap
Definition: DataBufferHeap.h:30
lldb_private::minidump::MinidumpContext_x86_32_Flags::Integer
@ Integer
DataBufferHeap.h
lldb_private::lldb_eip_i386
@ lldb_eip_i386
Definition: lldb-x86-register-enums.h:26
lldb_private::lldb_gs_i386
@ lldb_gs_i386
Definition: lldb-x86-register-enums.h:30
lldb_private::RegisterInfoInterface::GetGPRSize
virtual size_t GetGPRSize() const =0
lldb_private::minidump::MinidumpContext_x86_32::ds
llvm::support::ulittle32_t ds
Definition: RegisterContextMinidump_x86_32.h:80