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 | |
9 | #include "RegisterContextMinidump_x86_32.h" |
10 | |
11 | #include "lldb/Utility/DataBufferHeap.h" |
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(dest: reg_dest.data(), src: reg_src, n: reg_dest.size()); |
22 | } |
23 | |
24 | lldb::DataBufferSP lldb_private::minidump::ConvertMinidumpContext_x86_32( |
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::WritableDataBufferSP 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(Buffer&: source_data, Object&: 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)); |
43 | auto x86_32_Flag = MinidumpContext_x86_32_Flags::x86_32_Flag; |
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(reg_src: &context->ebp, |
54 | reg_dest: reg_info[lldb_ebp_i386].mutable_data(context_base: result_base)); |
55 | writeRegister(reg_src: &context->eip, |
56 | reg_dest: reg_info[lldb_eip_i386].mutable_data(context_base: result_base)); |
57 | writeRegister(reg_src: &context->cs, |
58 | reg_dest: reg_info[lldb_cs_i386].mutable_data(context_base: result_base)); |
59 | writeRegister(reg_src: &context->eflags, |
60 | reg_dest: reg_info[lldb_eflags_i386].mutable_data(context_base: result_base)); |
61 | writeRegister(reg_src: &context->esp, |
62 | reg_dest: reg_info[lldb_esp_i386].mutable_data(context_base: result_base)); |
63 | writeRegister(reg_src: &context->ss, |
64 | reg_dest: reg_info[lldb_ss_i386].mutable_data(context_base: result_base)); |
65 | } |
66 | |
67 | if ((context_flags & SegmentsFlag) == SegmentsFlag) { |
68 | writeRegister(reg_src: &context->ds, |
69 | reg_dest: reg_info[lldb_ds_i386].mutable_data(context_base: result_base)); |
70 | writeRegister(reg_src: &context->es, |
71 | reg_dest: reg_info[lldb_es_i386].mutable_data(context_base: result_base)); |
72 | writeRegister(reg_src: &context->fs, |
73 | reg_dest: reg_info[lldb_fs_i386].mutable_data(context_base: result_base)); |
74 | writeRegister(reg_src: &context->gs, |
75 | reg_dest: reg_info[lldb_gs_i386].mutable_data(context_base: result_base)); |
76 | } |
77 | |
78 | if ((context_flags & IntegerFlag) == IntegerFlag) { |
79 | writeRegister(reg_src: &context->eax, |
80 | reg_dest: reg_info[lldb_eax_i386].mutable_data(context_base: result_base)); |
81 | writeRegister(reg_src: &context->ecx, |
82 | reg_dest: reg_info[lldb_ecx_i386].mutable_data(context_base: result_base)); |
83 | writeRegister(reg_src: &context->edx, |
84 | reg_dest: reg_info[lldb_edx_i386].mutable_data(context_base: result_base)); |
85 | writeRegister(reg_src: &context->ebx, |
86 | reg_dest: reg_info[lldb_ebx_i386].mutable_data(context_base: result_base)); |
87 | writeRegister(reg_src: &context->esi, |
88 | reg_dest: reg_info[lldb_esi_i386].mutable_data(context_base: result_base)); |
89 | writeRegister(reg_src: &context->edi, |
90 | reg_dest: reg_info[lldb_edi_i386].mutable_data(context_base: result_base)); |
91 | } |
92 | |
93 | // TODO parse the floating point registers |
94 | |
95 | return result_context_buf; |
96 | } |
97 | |