| File: | src/gnu/usr.bin/clang/liblldbPluginProcess/../../../llvm/lldb/source/Plugins/Process/OpenBSD/NativeRegisterContextOpenBSD_x86_64.cpp |
| Warning: | line 673, column 3 Value stored to 'src' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | //===-- NativeRegisterContextOpenBSD_x86_64.cpp ---------------*- 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 | #if defined(__x86_64__1) |
| 11 | |
| 12 | |
| 13 | #include <elf.h> |
| 14 | #include <err.h> |
| 15 | #include <stdint.h> |
| 16 | #include <stdlib.h> |
| 17 | |
| 18 | #include "NativeRegisterContextOpenBSD_x86_64.h" |
| 19 | |
| 20 | #include "lldb/Host/HostInfo.h" |
| 21 | #include "lldb/Utility/DataBufferHeap.h" |
| 22 | #include "lldb/Utility/Log.h" |
| 23 | #include "lldb/Utility/RegisterValue.h" |
| 24 | #include "lldb/Utility/Status.h" |
| 25 | |
| 26 | #include "Plugins/Process/Utility/RegisterContextOpenBSD_x86_64.h" |
| 27 | |
| 28 | // clang-format off |
| 29 | #include <sys/types.h> |
| 30 | #include <sys/sysctl.h> |
| 31 | #include <sys/time.h> |
| 32 | #include <machine/cpu.h> |
| 33 | // clang-format on |
| 34 | |
| 35 | using namespace lldb_private; |
| 36 | using namespace lldb_private::process_openbsd; |
| 37 | |
| 38 | // ---------------------------------------------------------------------------- |
| 39 | // Private namespace. |
| 40 | // ---------------------------------------------------------------------------- |
| 41 | |
| 42 | namespace { |
| 43 | // x86 64-bit general purpose registers. |
| 44 | static const uint32_t g_gpr_regnums_x86_64[] = { |
| 45 | lldb_rax_x86_64, lldb_rbx_x86_64, lldb_rcx_x86_64, lldb_rdx_x86_64, |
| 46 | lldb_rdi_x86_64, lldb_rsi_x86_64, lldb_rbp_x86_64, lldb_rsp_x86_64, |
| 47 | lldb_r8_x86_64, lldb_r9_x86_64, lldb_r10_x86_64, lldb_r11_x86_64, |
| 48 | lldb_r12_x86_64, lldb_r13_x86_64, lldb_r14_x86_64, lldb_r15_x86_64, |
| 49 | lldb_rip_x86_64, lldb_rflags_x86_64, lldb_cs_x86_64, lldb_fs_x86_64, |
| 50 | lldb_gs_x86_64, lldb_ss_x86_64, lldb_ds_x86_64, lldb_es_x86_64, |
| 51 | lldb_eax_x86_64, lldb_ebx_x86_64, lldb_ecx_x86_64, lldb_edx_x86_64, |
| 52 | lldb_edi_x86_64, lldb_esi_x86_64, lldb_ebp_x86_64, lldb_esp_x86_64, |
| 53 | lldb_r8d_x86_64, lldb_r9d_x86_64, lldb_r10d_x86_64, lldb_r11d_x86_64, |
| 54 | lldb_r12d_x86_64, lldb_r13d_x86_64, lldb_r14d_x86_64, lldb_r15d_x86_64, |
| 55 | lldb_ax_x86_64, lldb_bx_x86_64, lldb_cx_x86_64, lldb_dx_x86_64, |
| 56 | lldb_di_x86_64, lldb_si_x86_64, lldb_bp_x86_64, lldb_sp_x86_64, |
| 57 | lldb_r8w_x86_64, lldb_r9w_x86_64, lldb_r10w_x86_64, lldb_r11w_x86_64, |
| 58 | lldb_r12w_x86_64, lldb_r13w_x86_64, lldb_r14w_x86_64, lldb_r15w_x86_64, |
| 59 | lldb_ah_x86_64, lldb_bh_x86_64, lldb_ch_x86_64, lldb_dh_x86_64, |
| 60 | lldb_al_x86_64, lldb_bl_x86_64, lldb_cl_x86_64, lldb_dl_x86_64, |
| 61 | lldb_dil_x86_64, lldb_sil_x86_64, lldb_bpl_x86_64, lldb_spl_x86_64, |
| 62 | lldb_r8l_x86_64, lldb_r9l_x86_64, lldb_r10l_x86_64, lldb_r11l_x86_64, |
| 63 | lldb_r12l_x86_64, lldb_r13l_x86_64, lldb_r14l_x86_64, lldb_r15l_x86_64, |
| 64 | LLDB_INVALID_REGNUM0xffffffffU // register sets need to end with this flag |
| 65 | }; |
| 66 | static_assert( |
| 67 | (sizeof(g_gpr_regnums_x86_64) / sizeof(g_gpr_regnums_x86_64[0])) - 1 |
| 68 | == k_num_gpr_registers_x86_64, |
| 69 | "g_gpr_regnums_x86_64 has wrong number of register infos"); |
| 70 | |
| 71 | // x86 64-bit floating point registers. |
| 72 | static const uint32_t g_fpu_regnums_x86_64[] = { |
| 73 | lldb_fctrl_x86_64, lldb_fstat_x86_64, lldb_ftag_x86_64, |
| 74 | lldb_fop_x86_64, lldb_fiseg_x86_64, lldb_fioff_x86_64, |
| 75 | lldb_fip_x86_64, lldb_foseg_x86_64, lldb_fooff_x86_64, |
| 76 | lldb_fdp_x86_64, lldb_mxcsr_x86_64, lldb_mxcsrmask_x86_64, |
| 77 | lldb_st0_x86_64, lldb_st1_x86_64, |
| 78 | lldb_st2_x86_64, lldb_st3_x86_64, lldb_st4_x86_64, |
| 79 | lldb_st5_x86_64, lldb_st6_x86_64, lldb_st7_x86_64, |
| 80 | lldb_mm0_x86_64, lldb_mm1_x86_64, lldb_mm2_x86_64, |
| 81 | lldb_mm3_x86_64, lldb_mm4_x86_64, lldb_mm5_x86_64, |
| 82 | lldb_mm6_x86_64, lldb_mm7_x86_64, lldb_xmm0_x86_64, |
| 83 | lldb_xmm1_x86_64, lldb_xmm2_x86_64, lldb_xmm3_x86_64, |
| 84 | lldb_xmm4_x86_64, lldb_xmm5_x86_64, lldb_xmm6_x86_64, |
| 85 | lldb_xmm7_x86_64, lldb_xmm8_x86_64, lldb_xmm9_x86_64, |
| 86 | lldb_xmm10_x86_64, lldb_xmm11_x86_64, lldb_xmm12_x86_64, |
| 87 | lldb_xmm13_x86_64, lldb_xmm14_x86_64, lldb_xmm15_x86_64, |
| 88 | LLDB_INVALID_REGNUM0xffffffffU // register sets need to end with this flag |
| 89 | }; |
| 90 | static_assert( |
| 91 | (sizeof(g_fpu_regnums_x86_64) / sizeof(g_fpu_regnums_x86_64[0])) - 1 |
| 92 | == k_num_fpr_registers_x86_64, |
| 93 | "g_fpu_regnums_x86_64 has wrong number of register infos"); |
| 94 | |
| 95 | // Number of register sets provided by this context. |
| 96 | enum { k_num_register_sets = 2 }; |
| 97 | |
| 98 | // Register sets for x86 64-bit. |
| 99 | static const RegisterSet g_reg_sets_x86_64[k_num_register_sets] = { |
| 100 | {"General Purpose Registers", "gpr", k_num_gpr_registers_x86_64, |
| 101 | g_gpr_regnums_x86_64}, |
| 102 | {"Floating Point Registers", "fpu", k_num_fpr_registers_x86_64, |
| 103 | g_fpu_regnums_x86_64}, |
| 104 | }; |
| 105 | |
| 106 | struct x86_fpu_addr { |
| 107 | uint32_t offset; |
| 108 | uint32_t selector; |
| 109 | }; |
| 110 | |
| 111 | } // namespace |
| 112 | |
| 113 | #define REG_CONTEXT_SIZE(GetGPRSize() + GetFPRSize()) (GetGPRSize() + GetFPRSize()) |
| 114 | |
| 115 | std::unique_ptr<NativeRegisterContextOpenBSD> |
| 116 | NativeRegisterContextOpenBSD::CreateHostNativeRegisterContextOpenBSD( |
| 117 | const ArchSpec &target_arch, NativeThreadProtocol &native_thread) { |
| 118 | return std::make_unique<NativeRegisterContextOpenBSD_x86_64>(target_arch, native_thread); |
| 119 | } |
| 120 | |
| 121 | // ---------------------------------------------------------------------------- |
| 122 | // NativeRegisterContextOpenBSD_x86_64 members. |
| 123 | // ---------------------------------------------------------------------------- |
| 124 | |
| 125 | static RegisterInfoInterface * |
| 126 | CreateRegisterInfoInterface(const ArchSpec &target_arch) { |
| 127 | assert((HostInfo::GetArchitecture().GetAddressByteSize() == 8) &&((void)0) |
| 128 | "Register setting path assumes this is a 64-bit host")((void)0); |
| 129 | // X86_64 hosts know how to work with 64-bit and 32-bit EXEs using the x86_64 |
| 130 | // register context. |
| 131 | return new RegisterContextOpenBSD_x86_64(target_arch); |
| 132 | } |
| 133 | |
| 134 | NativeRegisterContextOpenBSD_x86_64::NativeRegisterContextOpenBSD_x86_64( |
| 135 | const ArchSpec &target_arch, NativeThreadProtocol &native_thread) |
| 136 | : NativeRegisterContextOpenBSD(native_thread, |
| 137 | CreateRegisterInfoInterface(target_arch)), |
| 138 | m_gpr(), m_fpr() {} |
| 139 | |
| 140 | uint32_t NativeRegisterContextOpenBSD_x86_64::GetUserRegisterCount() const { |
| 141 | uint32_t count = 0; |
| 142 | for (uint32_t set_index = 0; set_index < k_num_register_sets; ++set_index) |
| 143 | count += g_reg_sets_x86_64[set_index].num_registers; |
| 144 | return count; |
| 145 | } |
| 146 | |
| 147 | uint32_t NativeRegisterContextOpenBSD_x86_64::GetRegisterSetCount() const { |
| 148 | return k_num_register_sets; |
| 149 | } |
| 150 | |
| 151 | const RegisterSet * |
| 152 | NativeRegisterContextOpenBSD_x86_64::GetRegisterSet(uint32_t set_index) const { |
| 153 | switch (GetRegisterInfoInterface().GetTargetArchitecture().GetMachine()) { |
| 154 | case llvm::Triple::x86_64: |
| 155 | return &g_reg_sets_x86_64[set_index]; |
| 156 | default: |
| 157 | assert(false && "Unhandled target architecture.")((void)0); |
| 158 | return nullptr; |
| 159 | } |
| 160 | |
| 161 | return nullptr; |
| 162 | } |
| 163 | |
| 164 | int NativeRegisterContextOpenBSD_x86_64::GetSetForNativeRegNum( |
| 165 | int reg_num) const { |
| 166 | if (reg_num >= k_first_gpr_x86_64 && reg_num <= k_last_gpr_x86_64) |
| 167 | return GPRegSet; |
| 168 | else if (reg_num >= k_first_fpr_x86_64 && reg_num <= k_last_fpr_x86_64) |
| 169 | return FPRegSet; |
| 170 | else |
| 171 | return -1; |
| 172 | } |
| 173 | |
| 174 | int NativeRegisterContextOpenBSD_x86_64::ReadRegisterSet(uint32_t set) { |
| 175 | switch (set) { |
| 176 | case GPRegSet: |
| 177 | ReadGPR(); |
| 178 | return 0; |
| 179 | case FPRegSet: |
| 180 | ReadFPR(); |
| 181 | return 0; |
| 182 | default: |
| 183 | break; |
| 184 | } |
| 185 | return -1; |
| 186 | } |
| 187 | int NativeRegisterContextOpenBSD_x86_64::WriteRegisterSet(uint32_t set) { |
| 188 | switch (set) { |
| 189 | case GPRegSet: |
| 190 | WriteGPR(); |
| 191 | return 0; |
| 192 | case FPRegSet: |
| 193 | WriteFPR(); |
| 194 | return 0; |
| 195 | default: |
| 196 | break; |
| 197 | } |
| 198 | return -1; |
| 199 | } |
| 200 | |
| 201 | Status |
| 202 | NativeRegisterContextOpenBSD_x86_64::ReadRegister(const RegisterInfo *reg_info, |
| 203 | RegisterValue ®_value) { |
| 204 | Status error; |
| 205 | |
| 206 | if (!reg_info) { |
| 207 | error.SetErrorString("reg_info NULL"); |
| 208 | return error; |
| 209 | } |
| 210 | |
| 211 | const uint32_t reg = reg_info->kinds[lldb::eRegisterKindLLDB]; |
| 212 | if (reg == LLDB_INVALID_REGNUM0xffffffffU) { |
| 213 | // This is likely an internal register for lldb use only and should not be |
| 214 | // directly queried. |
| 215 | error.SetErrorStringWithFormat("register \"%s\" is an internal-only lldb " |
| 216 | "register, cannot read directly", |
| 217 | reg_info->name); |
| 218 | return error; |
| 219 | } |
| 220 | |
| 221 | int set = GetSetForNativeRegNum(reg); |
| 222 | if (set == -1) { |
| 223 | // This is likely an internal register for lldb use only and should not be |
| 224 | // directly queried. |
| 225 | error.SetErrorStringWithFormat("register \"%s\" is in unrecognized set", |
| 226 | reg_info->name); |
| 227 | return error; |
| 228 | } |
| 229 | |
| 230 | if (ReadRegisterSet(set) != 0) { |
| 231 | // This is likely an internal register for lldb use only and should not be |
| 232 | // directly queried. |
| 233 | error.SetErrorStringWithFormat( |
| 234 | "reading register set for register \"%s\" failed", reg_info->name); |
| 235 | return error; |
| 236 | } |
| 237 | |
| 238 | switch (reg) { |
| 239 | case lldb_rax_x86_64: |
| 240 | reg_value = (uint64_t)m_gpr.r_rax; |
| 241 | break; |
| 242 | case lldb_rbx_x86_64: |
| 243 | reg_value = (uint64_t)m_gpr.r_rbx; |
| 244 | break; |
| 245 | case lldb_rcx_x86_64: |
| 246 | reg_value = (uint64_t)m_gpr.r_rcx; |
| 247 | break; |
| 248 | case lldb_rdx_x86_64: |
| 249 | reg_value = (uint64_t)m_gpr.r_rdx; |
| 250 | break; |
| 251 | case lldb_rdi_x86_64: |
| 252 | reg_value = (uint64_t)m_gpr.r_rdi; |
| 253 | break; |
| 254 | case lldb_rsi_x86_64: |
| 255 | reg_value = (uint64_t)m_gpr.r_rsi; |
| 256 | break; |
| 257 | case lldb_rbp_x86_64: |
| 258 | reg_value = (uint64_t)m_gpr.r_rbp; |
| 259 | break; |
| 260 | case lldb_rsp_x86_64: |
| 261 | reg_value = (uint64_t)m_gpr.r_rsp; |
| 262 | break; |
| 263 | case lldb_r8_x86_64: |
| 264 | reg_value = (uint64_t)m_gpr.r_r8; |
| 265 | break; |
| 266 | case lldb_r9_x86_64: |
| 267 | reg_value = (uint64_t)m_gpr.r_r9; |
| 268 | break; |
| 269 | case lldb_r10_x86_64: |
| 270 | reg_value = (uint64_t)m_gpr.r_r10; |
| 271 | break; |
| 272 | case lldb_r11_x86_64: |
| 273 | reg_value = (uint64_t)m_gpr.r_r11; |
| 274 | break; |
| 275 | case lldb_r12_x86_64: |
| 276 | reg_value = (uint64_t)m_gpr.r_r12; |
| 277 | break; |
| 278 | case lldb_r13_x86_64: |
| 279 | reg_value = (uint64_t)m_gpr.r_r13; |
| 280 | break; |
| 281 | case lldb_r14_x86_64: |
| 282 | reg_value = (uint64_t)m_gpr.r_r14; |
| 283 | break; |
| 284 | case lldb_r15_x86_64: |
| 285 | reg_value = (uint64_t)m_gpr.r_r15; |
| 286 | break; |
| 287 | case lldb_rip_x86_64: |
| 288 | reg_value = (uint64_t)m_gpr.r_rip; |
| 289 | break; |
| 290 | case lldb_rflags_x86_64: |
| 291 | reg_value = (uint64_t)m_gpr.r_rflags; |
| 292 | break; |
| 293 | case lldb_cs_x86_64: |
| 294 | reg_value = (uint64_t)m_gpr.r_cs; |
| 295 | break; |
| 296 | case lldb_fs_x86_64: |
| 297 | reg_value = (uint64_t)m_gpr.r_fs; |
| 298 | break; |
| 299 | case lldb_gs_x86_64: |
| 300 | reg_value = (uint64_t)m_gpr.r_gs; |
| 301 | break; |
| 302 | case lldb_ss_x86_64: |
| 303 | reg_value = (uint64_t)m_gpr.r_ss; |
| 304 | break; |
| 305 | case lldb_ds_x86_64: |
| 306 | reg_value = (uint64_t)m_gpr.r_ds; |
| 307 | break; |
| 308 | case lldb_es_x86_64: |
| 309 | reg_value = (uint64_t)m_gpr.r_es; |
| 310 | break; |
| 311 | case lldb_fctrl_x86_64: |
| 312 | reg_value = (uint16_t)m_fpr.fxstate.fx_fcw; |
| 313 | break; |
| 314 | case lldb_fstat_x86_64: |
| 315 | reg_value = (uint16_t)m_fpr.fxstate.fx_fsw; |
| 316 | break; |
| 317 | case lldb_ftag_x86_64: |
| 318 | reg_value = (uint8_t)m_fpr.fxstate.fx_ftw; |
| 319 | break; |
| 320 | case lldb_fop_x86_64: |
| 321 | reg_value = (uint64_t)m_fpr.fxstate.fx_fop; |
| 322 | break; |
| 323 | case lldb_fioff_x86_64: |
| 324 | { |
| 325 | struct x86_fpu_addr *fp = (struct x86_fpu_addr *)&m_fpr.fxstate.fx_rip; |
| 326 | reg_value = fp->offset; |
| 327 | break; |
| 328 | } |
| 329 | case lldb_fiseg_x86_64: |
| 330 | { |
| 331 | struct x86_fpu_addr *fp = (struct x86_fpu_addr *)&m_fpr.fxstate.fx_rip; |
| 332 | reg_value = fp->selector; |
| 333 | break; |
| 334 | } |
| 335 | case lldb_fooff_x86_64: |
| 336 | { |
| 337 | struct x86_fpu_addr *fp = (struct x86_fpu_addr *)&m_fpr.fxstate.fx_rdp; |
| 338 | reg_value = fp->offset; |
| 339 | break; |
| 340 | } |
| 341 | case lldb_foseg_x86_64: |
| 342 | { |
| 343 | struct x86_fpu_addr *fp = (struct x86_fpu_addr *)&m_fpr.fxstate.fx_rdp; |
| 344 | reg_value = fp->selector; |
| 345 | break; |
| 346 | } |
| 347 | case lldb_mxcsr_x86_64: |
| 348 | reg_value = (uint32_t)m_fpr.fxstate.fx_mxcsr; |
| 349 | break; |
| 350 | case lldb_mxcsrmask_x86_64: |
| 351 | reg_value = (uint32_t)m_fpr.fxstate.fx_mxcsr_mask; |
| 352 | break; |
| 353 | case lldb_st0_x86_64: |
| 354 | case lldb_st1_x86_64: |
| 355 | case lldb_st2_x86_64: |
| 356 | case lldb_st3_x86_64: |
| 357 | case lldb_st4_x86_64: |
| 358 | case lldb_st5_x86_64: |
| 359 | case lldb_st6_x86_64: |
| 360 | case lldb_st7_x86_64: |
| 361 | reg_value.SetBytes(&m_fpr.fxstate.fx_st[reg - lldb_st0_x86_64], |
| 362 | reg_info->byte_size, endian::InlHostByteOrder()); |
| 363 | break; |
| 364 | case lldb_mm0_x86_64: |
| 365 | case lldb_mm1_x86_64: |
| 366 | case lldb_mm2_x86_64: |
| 367 | case lldb_mm3_x86_64: |
| 368 | case lldb_mm4_x86_64: |
| 369 | case lldb_mm5_x86_64: |
| 370 | case lldb_mm6_x86_64: |
| 371 | case lldb_mm7_x86_64: |
| 372 | reg_value.SetBytes(&m_fpr.fxstate.fx_st[reg - lldb_mm0_x86_64], |
| 373 | reg_info->byte_size, endian::InlHostByteOrder()); |
| 374 | break; |
| 375 | case lldb_xmm0_x86_64: |
| 376 | case lldb_xmm1_x86_64: |
| 377 | case lldb_xmm2_x86_64: |
| 378 | case lldb_xmm3_x86_64: |
| 379 | case lldb_xmm4_x86_64: |
| 380 | case lldb_xmm5_x86_64: |
| 381 | case lldb_xmm6_x86_64: |
| 382 | case lldb_xmm7_x86_64: |
| 383 | case lldb_xmm8_x86_64: |
| 384 | case lldb_xmm9_x86_64: |
| 385 | case lldb_xmm10_x86_64: |
| 386 | case lldb_xmm11_x86_64: |
| 387 | case lldb_xmm12_x86_64: |
| 388 | case lldb_xmm13_x86_64: |
| 389 | case lldb_xmm14_x86_64: |
| 390 | case lldb_xmm15_x86_64: |
| 391 | reg_value.SetBytes(&m_fpr.fxstate.fx_xmm[reg - lldb_xmm0_x86_64], |
| 392 | reg_info->byte_size, endian::InlHostByteOrder()); |
| 393 | break; |
| 394 | } |
| 395 | |
| 396 | return error; |
| 397 | } |
| 398 | |
| 399 | Status NativeRegisterContextOpenBSD_x86_64::WriteRegister( |
| 400 | const RegisterInfo *reg_info, const RegisterValue ®_value) { |
| 401 | |
| 402 | Status error; |
| 403 | |
| 404 | if (!reg_info) { |
| 405 | error.SetErrorString("reg_info NULL"); |
| 406 | return error; |
| 407 | } |
| 408 | |
| 409 | const uint32_t reg = reg_info->kinds[lldb::eRegisterKindLLDB]; |
| 410 | if (reg == LLDB_INVALID_REGNUM0xffffffffU) { |
| 411 | // This is likely an internal register for lldb use only and should not be |
| 412 | // directly queried. |
| 413 | error.SetErrorStringWithFormat("register \"%s\" is an internal-only lldb " |
| 414 | "register, cannot read directly", |
| 415 | reg_info->name); |
| 416 | return error; |
| 417 | } |
| 418 | |
| 419 | int set = GetSetForNativeRegNum(reg); |
| 420 | if (set == -1) { |
| 421 | // This is likely an internal register for lldb use only and should not be |
| 422 | // directly queried. |
| 423 | error.SetErrorStringWithFormat("register \"%s\" is in unrecognized set", |
| 424 | reg_info->name); |
| 425 | return error; |
| 426 | } |
| 427 | |
| 428 | if (ReadRegisterSet(set) != 0) { |
| 429 | // This is likely an internal register for lldb use only and should not be |
| 430 | // directly queried. |
| 431 | error.SetErrorStringWithFormat( |
| 432 | "reading register set for register \"%s\" failed", reg_info->name); |
| 433 | return error; |
| 434 | } |
| 435 | |
| 436 | switch (reg) { |
| 437 | case lldb_rax_x86_64: |
| 438 | m_gpr.r_rax = reg_value.GetAsUInt64(); |
| 439 | break; |
| 440 | case lldb_rbx_x86_64: |
| 441 | m_gpr.r_rbx = reg_value.GetAsUInt64(); |
| 442 | break; |
| 443 | case lldb_rcx_x86_64: |
| 444 | m_gpr.r_rcx = reg_value.GetAsUInt64(); |
| 445 | break; |
| 446 | case lldb_rdx_x86_64: |
| 447 | m_gpr.r_rdx = reg_value.GetAsUInt64(); |
| 448 | break; |
| 449 | case lldb_rdi_x86_64: |
| 450 | m_gpr.r_rdi = reg_value.GetAsUInt64(); |
| 451 | break; |
| 452 | case lldb_rsi_x86_64: |
| 453 | m_gpr.r_rsi = reg_value.GetAsUInt64(); |
| 454 | break; |
| 455 | case lldb_rbp_x86_64: |
| 456 | m_gpr.r_rbp = reg_value.GetAsUInt64(); |
| 457 | break; |
| 458 | case lldb_rsp_x86_64: |
| 459 | m_gpr.r_rsp = reg_value.GetAsUInt64(); |
| 460 | break; |
| 461 | case lldb_r8_x86_64: |
| 462 | m_gpr.r_r8 = reg_value.GetAsUInt64(); |
| 463 | break; |
| 464 | case lldb_r9_x86_64: |
| 465 | m_gpr.r_r9 = reg_value.GetAsUInt64(); |
| 466 | break; |
| 467 | case lldb_r10_x86_64: |
| 468 | m_gpr.r_r10 = reg_value.GetAsUInt64(); |
| 469 | break; |
| 470 | case lldb_r11_x86_64: |
| 471 | m_gpr.r_r11 = reg_value.GetAsUInt64(); |
| 472 | break; |
| 473 | case lldb_r12_x86_64: |
| 474 | m_gpr.r_r12 = reg_value.GetAsUInt64(); |
| 475 | break; |
| 476 | case lldb_r13_x86_64: |
| 477 | m_gpr.r_r13 = reg_value.GetAsUInt64(); |
| 478 | break; |
| 479 | case lldb_r14_x86_64: |
| 480 | m_gpr.r_r14 = reg_value.GetAsUInt64(); |
| 481 | break; |
| 482 | case lldb_r15_x86_64: |
| 483 | m_gpr.r_r15 = reg_value.GetAsUInt64(); |
| 484 | break; |
| 485 | case lldb_rip_x86_64: |
| 486 | m_gpr.r_rip = reg_value.GetAsUInt64(); |
| 487 | break; |
| 488 | case lldb_rflags_x86_64: |
| 489 | m_gpr.r_rflags = reg_value.GetAsUInt64(); |
| 490 | break; |
| 491 | case lldb_cs_x86_64: |
| 492 | m_gpr.r_cs = reg_value.GetAsUInt64(); |
| 493 | break; |
| 494 | case lldb_fs_x86_64: |
| 495 | m_gpr.r_fs = reg_value.GetAsUInt64(); |
| 496 | break; |
| 497 | case lldb_gs_x86_64: |
| 498 | m_gpr.r_gs = reg_value.GetAsUInt64(); |
| 499 | break; |
| 500 | case lldb_ss_x86_64: |
| 501 | m_gpr.r_ss = reg_value.GetAsUInt64(); |
| 502 | break; |
| 503 | case lldb_ds_x86_64: |
| 504 | m_gpr.r_ds = reg_value.GetAsUInt64(); |
| 505 | break; |
| 506 | case lldb_es_x86_64: |
| 507 | m_gpr.r_es = reg_value.GetAsUInt64(); |
| 508 | break; |
| 509 | case lldb_fctrl_x86_64: |
| 510 | m_fpr.fxstate.fx_fcw = reg_value.GetAsUInt16(); |
| 511 | break; |
| 512 | case lldb_fstat_x86_64: |
| 513 | m_fpr.fxstate.fx_fsw = reg_value.GetAsUInt16(); |
| 514 | break; |
| 515 | case lldb_ftag_x86_64: |
| 516 | m_fpr.fxstate.fx_ftw = reg_value.GetAsUInt8(); |
| 517 | break; |
| 518 | case lldb_fop_x86_64: |
| 519 | m_fpr.fxstate.fx_fop = reg_value.GetAsUInt16(); |
| 520 | break; |
| 521 | case lldb_fioff_x86_64: |
| 522 | { |
| 523 | struct x86_fpu_addr *fp = (struct x86_fpu_addr *)&m_fpr.fxstate.fx_rip; |
| 524 | fp->offset = reg_value.GetAsUInt32(); |
| 525 | break; |
| 526 | } |
| 527 | case lldb_fiseg_x86_64: |
| 528 | { |
| 529 | struct x86_fpu_addr *fp = (struct x86_fpu_addr *)&m_fpr.fxstate.fx_rip; |
| 530 | fp->selector = reg_value.GetAsUInt32(); |
| 531 | break; |
| 532 | } |
| 533 | case lldb_fooff_x86_64: |
| 534 | { |
| 535 | struct x86_fpu_addr *fp = (struct x86_fpu_addr *)&m_fpr.fxstate.fx_rdp; |
| 536 | fp->offset = reg_value.GetAsUInt32(); |
| 537 | break; |
| 538 | } |
| 539 | case lldb_foseg_x86_64: |
| 540 | { |
| 541 | struct x86_fpu_addr *fp = (struct x86_fpu_addr *)&m_fpr.fxstate.fx_rdp; |
| 542 | fp->selector = reg_value.GetAsUInt32(); |
| 543 | break; |
| 544 | } |
| 545 | case lldb_mxcsr_x86_64: |
| 546 | m_fpr.fxstate.fx_mxcsr = reg_value.GetAsUInt32(); |
| 547 | break; |
| 548 | case lldb_mxcsrmask_x86_64: |
| 549 | m_fpr.fxstate.fx_mxcsr_mask = reg_value.GetAsUInt32(); |
| 550 | break; |
| 551 | case lldb_st0_x86_64: |
| 552 | case lldb_st1_x86_64: |
| 553 | case lldb_st2_x86_64: |
| 554 | case lldb_st3_x86_64: |
| 555 | case lldb_st4_x86_64: |
| 556 | case lldb_st5_x86_64: |
| 557 | case lldb_st6_x86_64: |
| 558 | case lldb_st7_x86_64: |
| 559 | ::memcpy(&m_fpr.fxstate.fx_st[reg - lldb_st0_x86_64], |
| 560 | reg_value.GetBytes(), reg_value.GetByteSize()); |
| 561 | break; |
| 562 | case lldb_mm0_x86_64: |
| 563 | case lldb_mm1_x86_64: |
| 564 | case lldb_mm2_x86_64: |
| 565 | case lldb_mm3_x86_64: |
| 566 | case lldb_mm4_x86_64: |
| 567 | case lldb_mm5_x86_64: |
| 568 | case lldb_mm6_x86_64: |
| 569 | case lldb_mm7_x86_64: |
| 570 | ::memcpy(&m_fpr.fxstate.fx_st[reg - lldb_mm0_x86_64], |
| 571 | reg_value.GetBytes(), reg_value.GetByteSize()); |
| 572 | break; |
| 573 | case lldb_xmm0_x86_64: |
| 574 | case lldb_xmm1_x86_64: |
| 575 | case lldb_xmm2_x86_64: |
| 576 | case lldb_xmm3_x86_64: |
| 577 | case lldb_xmm4_x86_64: |
| 578 | case lldb_xmm5_x86_64: |
| 579 | case lldb_xmm6_x86_64: |
| 580 | case lldb_xmm7_x86_64: |
| 581 | case lldb_xmm8_x86_64: |
| 582 | case lldb_xmm9_x86_64: |
| 583 | case lldb_xmm10_x86_64: |
| 584 | case lldb_xmm11_x86_64: |
| 585 | case lldb_xmm12_x86_64: |
| 586 | case lldb_xmm13_x86_64: |
| 587 | case lldb_xmm14_x86_64: |
| 588 | case lldb_xmm15_x86_64: |
| 589 | ::memcpy(&m_fpr.fxstate.fx_xmm[reg - lldb_xmm0_x86_64], |
| 590 | reg_value.GetBytes(), reg_value.GetByteSize()); |
| 591 | break; |
| 592 | } |
| 593 | |
| 594 | if (WriteRegisterSet(set) != 0) |
| 595 | error.SetErrorStringWithFormat("failed to write register set"); |
| 596 | |
| 597 | return error; |
| 598 | } |
| 599 | |
| 600 | Status NativeRegisterContextOpenBSD_x86_64::ReadAllRegisterValues( |
| 601 | lldb::DataBufferSP &data_sp) { |
| 602 | Status error; |
| 603 | |
| 604 | data_sp.reset(new DataBufferHeap(REG_CONTEXT_SIZE(GetGPRSize() + GetFPRSize()), 0)); |
| 605 | if (!data_sp) { |
| 606 | error.SetErrorStringWithFormat( |
| 607 | "failed to allocate DataBufferHeap instance of size %zu", |
| 608 | REG_CONTEXT_SIZE(GetGPRSize() + GetFPRSize())); |
| 609 | return error; |
| 610 | } |
| 611 | |
| 612 | uint8_t *dst = data_sp->GetBytes(); |
| 613 | if (dst == nullptr) { |
| 614 | error.SetErrorStringWithFormat("DataBufferHeap instance of size %zu" |
| 615 | " returned a null pointer", |
| 616 | REG_CONTEXT_SIZE(GetGPRSize() + GetFPRSize())); |
| 617 | return error; |
| 618 | } |
| 619 | |
| 620 | error = ReadGPR(); |
| 621 | if (error.Fail()) |
| 622 | return error; |
| 623 | ::memcpy(dst, &m_gpr, GetGPRSize()); |
| 624 | dst += GetGPRSize(); |
| 625 | |
| 626 | error = ReadFPR(); |
| 627 | if (error.Fail()) |
| 628 | return error; |
| 629 | ::memcpy(dst, &m_fpr, GetFPRSize()); |
| 630 | dst += GetFPRSize(); |
| 631 | |
| 632 | return error; |
| 633 | } |
| 634 | |
| 635 | Status NativeRegisterContextOpenBSD_x86_64::WriteAllRegisterValues( |
| 636 | const lldb::DataBufferSP &data_sp) { |
| 637 | Status error; |
| 638 | |
| 639 | if (!data_sp) { |
| 640 | error.SetErrorStringWithFormat( |
| 641 | "NativeRegisterContextOpenBSD_x86_64::%s invalid data_sp provided", |
| 642 | __FUNCTION__); |
| 643 | return error; |
| 644 | } |
| 645 | |
| 646 | if (data_sp->GetByteSize() != REG_CONTEXT_SIZE(GetGPRSize() + GetFPRSize())) { |
| 647 | error.SetErrorStringWithFormat( |
| 648 | "NativeRegisterContextOpenBSD_x86_64::%s data_sp contained mismatched " |
| 649 | "data size, expected %zu, actual %llu", |
| 650 | __FUNCTION__, REG_CONTEXT_SIZE(GetGPRSize() + GetFPRSize()), data_sp->GetByteSize()); |
| 651 | return error; |
| 652 | } |
| 653 | |
| 654 | uint8_t *src = data_sp->GetBytes(); |
| 655 | if (src == nullptr) { |
| 656 | error.SetErrorStringWithFormat("NativeRegisterContextOpenBSD_x86_64::%s " |
| 657 | "DataBuffer::GetBytes() returned a null " |
| 658 | "pointer", |
| 659 | __FUNCTION__); |
| 660 | return error; |
| 661 | } |
| 662 | |
| 663 | ::memcpy(&m_gpr, src, GetGPRSize()); |
| 664 | error = WriteGPR(); |
| 665 | if (error.Fail()) |
| 666 | return error; |
| 667 | src += GetGPRSize(); |
| 668 | |
| 669 | ::memcpy(&m_fpr, src, GetFPRSize()); |
| 670 | error = WriteFPR(); |
| 671 | if (error.Fail()) |
| 672 | return error; |
| 673 | src += GetFPRSize(); |
Value stored to 'src' is never read | |
| 674 | |
| 675 | return error; |
| 676 | } |
| 677 | #endif |