LLDB mainline
RegisterContextFreeBSDKernelCore_x86_64.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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
11#include "lldb/Target/Process.h"
12#include "lldb/Target/Thread.h"
14#include "llvm/Support/Endian.h"
15
16#if defined(__FreeBSD__) && defined(__amd64__)
17#include <machine/pcb.h>
18#endif
19
20using namespace lldb;
21using namespace lldb_private;
22
28
30
32
34 assert(0);
35 return false;
36}
37
39 assert(0);
40 return false;
41}
42
44 const RegisterInfo *reg_info, RegisterValue &value) {
46 return false;
47
48 // https://cgit.freebsd.org/src/tree/sys/amd64/include/pcb.h
49 struct {
50 llvm::support::ulittle64_t r15;
51 llvm::support::ulittle64_t r14;
52 llvm::support::ulittle64_t r13;
53 llvm::support::ulittle64_t r12;
54 llvm::support::ulittle64_t rbp;
55 llvm::support::ulittle64_t rsp;
56 llvm::support::ulittle64_t rbx;
57 llvm::support::ulittle64_t rip;
58 } pcb;
59
60 constexpr unsigned short CODE_SEL = 4 << 3;
61 constexpr unsigned short DATA_SEL = 5 << 3;
62
63#if defined(__FreeBSD__) && defined(__amd64__)
64 static_assert(offsetof(struct pcb, pcb_r15) == offsetof(decltype(pcb), r15));
65 static_assert(offsetof(struct pcb, pcb_r14) == offsetof(decltype(pcb), r14));
66 static_assert(offsetof(struct pcb, pcb_r13) == offsetof(decltype(pcb), r13));
67 static_assert(offsetof(struct pcb, pcb_r12) == offsetof(decltype(pcb), r12));
68 static_assert(offsetof(struct pcb, pcb_rbp) == offsetof(decltype(pcb), rbp));
69 static_assert(offsetof(struct pcb, pcb_rsp) == offsetof(decltype(pcb), rsp));
70 static_assert(offsetof(struct pcb, pcb_rbx) == offsetof(decltype(pcb), rbx));
71 static_assert(offsetof(struct pcb, pcb_rip) == offsetof(decltype(pcb), rip));
72#endif
73
75 size_t rd =
76 m_thread.GetProcess()->ReadMemory(m_pcb_addr, &pcb, sizeof(pcb), error);
77 if (rd != sizeof(pcb))
78 return false;
79
80 uint32_t reg = reg_info->kinds[lldb::eRegisterKindLLDB];
81 switch (reg) {
82#define REG(x) \
83 case lldb_##x##_x86_64: \
84 value = pcb.x; \
85 break;
86
87 REG(r15);
88 REG(r14);
89 REG(r13);
90 REG(r12);
91 REG(rbp);
92 REG(rsp);
93 REG(rbx);
94 REG(rip);
95#undef REG
96 case lldb_cs_x86_64:
97 value.SetUInt(CODE_SEL, reg_info->byte_size);
98 break;
99 case lldb_ss_x86_64:
100 value.SetUInt(DATA_SEL, reg_info->byte_size);
101 break;
102 default:
103 return false;
104 }
105
106 return true;
107}
108
110 const RegisterInfo *reg_info, const RegisterValue &value) {
111 return false;
112}
static llvm::raw_ostream & error(Stream &strm)
#define REG(x)
RegisterContextCore_x86(lldb_private::Thread &thread, uint32_t concrete_frame_idx, lldb_private::RegisterInfoInterface *register_info)
bool ReadRegister(const lldb_private::RegisterInfo *reg_info, lldb_private::RegisterValue &value) override
bool WriteRegister(const lldb_private::RegisterInfo *reg_info, const lldb_private::RegisterValue &value) override
RegisterContextFreeBSDKernelCore_x86_64(lldb_private::Thread &thread, lldb_private::RegisterInfoInterface *register_info, lldb::addr_t pcb_addr)
RegisterInfo interface to patch RegisterInfo structure for archs.
bool SetUInt(uint64_t uint, uint32_t byte_size)
An error handling class.
Definition Status.h:118
#define LLDB_INVALID_ADDRESS
A class that represents a running process on the host machine.
uint64_t addr_t
Definition lldb-types.h:80
@ eRegisterKindLLDB
lldb's internal register numbers
Every register is described in detail including its name, alternate name (optional),...
uint32_t byte_size
Size in bytes of the register.
uint32_t kinds[lldb::kNumRegisterKinds]
Holds all of the various register numbers for all register kinds.