Changeset View
Changeset View
Standalone View
Standalone View
source/Plugins/Process/Utility/RegisterContextWindows_x86_64.cpp
- This file was added.
//===-- RegisterContextWindows_x86_64.cpp -----------------------*- C++ -*-===// | |||||
// | |||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | |||||
// See https://llvm.org/LICENSE.txt for license information. | |||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | |||||
// | |||||
//===----------------------------------------------------------------------===// | |||||
#include "RegisterContextWindows_x86_64.h" | |||||
#include "RegisterContextWindows_wow64.h" | |||||
#include "RegisterContext_x86.h" | |||||
#include "lldb-x86-register-enums.h" | |||||
#include <vector> | |||||
using namespace lldb_private; | |||||
using namespace lldb; | |||||
typedef struct _GPR { | |||||
uint64_t r15; | |||||
uint64_t r14; | |||||
uint64_t r13; | |||||
uint64_t r12; | |||||
uint64_t rbp; | |||||
uint64_t rbx; | |||||
uint64_t r11; | |||||
uint64_t r10; | |||||
uint64_t r9; | |||||
uint64_t r8; | |||||
uint64_t rax; | |||||
uint64_t rcx; | |||||
uint64_t rdx; | |||||
uint64_t rsi; | |||||
uint64_t rdi; | |||||
uint64_t rip; | |||||
uint64_t rflags; | |||||
uint64_t rsp; | |||||
uint16_t cs; | |||||
uint16_t ds; | |||||
uint16_t es; | |||||
uint16_t fs; | |||||
uint16_t gs; | |||||
uint16_t ss; | |||||
} GPR; | |||||
#define GPR_OFFSET(regname) (LLVM_EXTENSION offsetof(GPR, regname)) | |||||
// clang-format off | |||||
#define DEFINE_GPR(reg, alt, kind1, kind2, kind3, kind4) \ | |||||
{ \ | |||||
#reg, alt, sizeof(((GPR *)nullptr)->reg), GPR_OFFSET(reg), eEncodingUint, \ | |||||
eFormatHex, \ | |||||
{kind1, kind2, kind3, kind4, lldb_##reg##_x86_64 }, nullptr, nullptr, \ | |||||
nullptr, 0 \ | |||||
} | |||||
// clang-format off | |||||
static RegisterInfo g_register_infos_x86_64[] = { | |||||
// General purpose registers EH_Frame DWARF Generic Process Plugin | |||||
// =========================== ================== ================ ========================= ==================== | |||||
DEFINE_GPR(rax, nullptr, dwarf_rax_x86_64, dwarf_rax_x86_64, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM), | |||||
DEFINE_GPR(rbx, nullptr, dwarf_rbx_x86_64, dwarf_rbx_x86_64, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM), | |||||
DEFINE_GPR(rcx, "arg4", dwarf_rcx_x86_64, dwarf_rcx_x86_64, LLDB_REGNUM_GENERIC_ARG4, LLDB_INVALID_REGNUM), | |||||
DEFINE_GPR(rdx, "arg3", dwarf_rdx_x86_64, dwarf_rdx_x86_64, LLDB_REGNUM_GENERIC_ARG3, LLDB_INVALID_REGNUM), | |||||
DEFINE_GPR(rdi, "arg1", dwarf_rdi_x86_64, dwarf_rdi_x86_64, LLDB_REGNUM_GENERIC_ARG1, LLDB_INVALID_REGNUM), | |||||
DEFINE_GPR(rsi, "arg2", dwarf_rsi_x86_64, dwarf_rsi_x86_64, LLDB_REGNUM_GENERIC_ARG2, LLDB_INVALID_REGNUM), | |||||
DEFINE_GPR(rbp, "fp", dwarf_rbp_x86_64, dwarf_rbp_x86_64, LLDB_REGNUM_GENERIC_FP, LLDB_INVALID_REGNUM), | |||||
DEFINE_GPR(rsp, "sp", dwarf_rsp_x86_64, dwarf_rsp_x86_64, LLDB_REGNUM_GENERIC_SP, LLDB_INVALID_REGNUM), | |||||
DEFINE_GPR(r8, "arg5", dwarf_r8_x86_64, dwarf_r8_x86_64, LLDB_REGNUM_GENERIC_ARG5, LLDB_INVALID_REGNUM), | |||||
DEFINE_GPR(r9, "arg6", dwarf_r9_x86_64, dwarf_r9_x86_64, LLDB_REGNUM_GENERIC_ARG6, LLDB_INVALID_REGNUM), | |||||
DEFINE_GPR(r10, nullptr, dwarf_r10_x86_64, dwarf_r10_x86_64, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM), | |||||
DEFINE_GPR(r11, nullptr, dwarf_r11_x86_64, dwarf_r11_x86_64, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM), | |||||
DEFINE_GPR(r12, nullptr, dwarf_r12_x86_64, dwarf_r12_x86_64, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM), | |||||
DEFINE_GPR(r13, nullptr, dwarf_r13_x86_64, dwarf_r13_x86_64, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM), | |||||
DEFINE_GPR(r14, nullptr, dwarf_r14_x86_64, dwarf_r14_x86_64, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM), | |||||
DEFINE_GPR(r15, nullptr, dwarf_r15_x86_64, dwarf_r15_x86_64, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM), | |||||
DEFINE_GPR(rip, "pc", dwarf_rip_x86_64, dwarf_rip_x86_64, LLDB_REGNUM_GENERIC_PC, LLDB_INVALID_REGNUM), | |||||
DEFINE_GPR(rflags, "flags", dwarf_rflags_x86_64, dwarf_rflags_x86_64, LLDB_REGNUM_GENERIC_FLAGS, LLDB_INVALID_REGNUM), | |||||
DEFINE_GPR(cs, nullptr, dwarf_cs_x86_64, dwarf_cs_x86_64, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM), | |||||
DEFINE_GPR(fs, nullptr, dwarf_fs_x86_64, dwarf_fs_x86_64, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM), | |||||
DEFINE_GPR(gs, nullptr, dwarf_gs_x86_64, dwarf_gs_x86_64, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM), | |||||
DEFINE_GPR(ss, nullptr, dwarf_ss_x86_64, dwarf_ss_x86_64, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM), | |||||
DEFINE_GPR(ds, nullptr, dwarf_ds_x86_64, dwarf_ds_x86_64, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM), | |||||
DEFINE_GPR(es, nullptr, dwarf_es_x86_64, dwarf_es_x86_64, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM), | |||||
}; | |||||
static std::vector<lldb_private::RegisterInfo> &GetPrivateRegisterInfoVector() { | |||||
static std::vector<lldb_private::RegisterInfo> g_register_infos; | |||||
return g_register_infos; | |||||
} | |||||
static std::unique_ptr<RegisterContextWindows_wow64> g_private_reg_interface = nullptr; | |||||
static const RegisterInfo * | |||||
GetRegisterInfo_wow64(const lldb_private::ArchSpec &arch) { | |||||
// A wow64 register info is the same as the i386's. | |||||
std::vector<lldb_private::RegisterInfo> &g_register_infos = | |||||
GetPrivateRegisterInfoVector(); | |||||
if (g_register_infos.empty()) { | |||||
g_private_reg_interface.reset( | |||||
new RegisterContextWindows_wow64(arch)); | |||||
const RegisterInfo *base_info = g_private_reg_interface->GetRegisterInfo(); | |||||
g_register_infos.insert(g_register_infos.end(), &base_info[0], | |||||
&base_info[g_private_reg_interface->GetRegisterCount()]); | |||||
} | |||||
return g_register_infos.data(); | |||||
} | |||||
static const RegisterInfo *GetRegisterInfoPtr(const ArchSpec &target_arch) { | |||||
switch (target_arch.GetMachine()) { | |||||
case llvm::Triple::x86: | |||||
return GetRegisterInfo_wow64(target_arch); | |||||
case llvm::Triple::x86_64: | |||||
return g_register_infos_x86_64; | |||||
default: | |||||
assert(false && "Unhandled target architecture."); | |||||
return nullptr; | |||||
} | |||||
} | |||||
static uint32_t GetRegisterInfoCount(const ArchSpec &target_arch) { | |||||
switch (target_arch.GetMachine()) { | |||||
case llvm::Triple::x86: | |||||
assert(g_private_reg_interface && | |||||
"wow64 register info not yet filled."); | |||||
return static_cast<uint32_t>(g_private_reg_interface->GetRegisterCount()); | |||||
case llvm::Triple::x86_64: | |||||
return static_cast<uint32_t>(sizeof(g_register_infos_x86_64) / | |||||
sizeof(g_register_infos_x86_64[0])); | |||||
default: | |||||
assert(false && "Unhandled target architecture."); | |||||
return 0; | |||||
} | |||||
} | |||||
static uint32_t GetUserRegisterInfoCount(const ArchSpec &target_arch) { | |||||
switch (target_arch.GetMachine()) { | |||||
case llvm::Triple::x86: | |||||
assert(g_private_reg_interface && | |||||
"wow64 register info not yet filled."); | |||||
return static_cast<uint32_t>(g_private_reg_interface->GetUserRegisterCount()); | |||||
case llvm::Triple::x86_64: | |||||
return static_cast<uint32_t>(sizeof(g_register_infos_x86_64) / | |||||
sizeof(g_register_infos_x86_64[0])); | |||||
default: | |||||
assert(false && "Unhandled target architecture."); | |||||
return 0; | |||||
} | |||||
} | |||||
RegisterContextWindows_x86_64::RegisterContextWindows_x86_64( | |||||
const ArchSpec &target_arch) | |||||
: lldb_private::RegisterInfoInterface(target_arch), | |||||
m_register_info_p(GetRegisterInfoPtr(target_arch)), | |||||
m_register_info_count(GetRegisterInfoCount(target_arch)), | |||||
m_user_register_count(GetUserRegisterInfoCount(target_arch)) { | |||||
} | |||||
size_t RegisterContextWindows_x86_64::GetGPRSize() const { return sizeof(GPR); } |