diff --git a/lldb/source/Plugins/Process/FreeBSD-Kernel-Core/RegisterContextFreeBSDKernelCore_arm.cpp b/lldb/source/Plugins/Process/FreeBSD-Kernel-Core/RegisterContextFreeBSDKernelCore_arm.cpp index 0d01a0ec48d3e..8a2d7abfb277f 100644 --- a/lldb/source/Plugins/Process/FreeBSD-Kernel-Core/RegisterContextFreeBSDKernelCore_arm.cpp +++ b/lldb/source/Plugins/Process/FreeBSD-Kernel-Core/RegisterContextFreeBSDKernelCore_arm.cpp @@ -14,6 +14,11 @@ #include "lldb/Utility/RegisterValue.h" #include "llvm/Support/Endian.h" +#if defined(__FreeBSD__) && defined(__arm__) +#include +#include +#endif + using namespace lldb; using namespace lldb_private; @@ -61,6 +66,33 @@ bool RegisterContextFreeBSDKernelCore_arm::ReadRegister( llvm::support::ulittle32_t pc; } pcb; +#if defined(__FreeBSD__) && defined(__arm__) + static_assert(offsetof(struct switchframe, sf_r4) == + offsetof(decltype(pcb), r4)); + static_assert(offsetof(struct switchframe, sf_r5) == + offsetof(decltype(pcb), r5)); + static_assert(offsetof(struct switchframe, sf_r6) == + offsetof(decltype(pcb), r6)); + static_assert(offsetof(struct switchframe, sf_r7) == + offsetof(decltype(pcb), r7)); + static_assert(offsetof(struct switchframe, sf_r8) == + offsetof(decltype(pcb), r8)); + static_assert(offsetof(struct switchframe, sf_r9) == + offsetof(decltype(pcb), r9)); + static_assert(offsetof(struct switchframe, sf_r10) == + offsetof(decltype(pcb), r10)); + static_assert(offsetof(struct switchframe, sf_r11) == + offsetof(decltype(pcb), r11)); + static_assert(offsetof(struct switchframe, sf_r12) == + offsetof(decltype(pcb), r12)); + static_assert(offsetof(struct switchframe, sf_sp) == + offsetof(decltype(pcb), sp)); + static_assert(offsetof(struct switchframe, sf_lr) == + offsetof(decltype(pcb), lr)); + static_assert(offsetof(struct switchframe, sf_pc) == + offsetof(decltype(pcb), pc)); +#endif + Status error; size_t rd = m_thread.GetProcess()->ReadMemory(m_pcb_addr, &pcb, sizeof(pcb), error); diff --git a/lldb/source/Plugins/Process/FreeBSD-Kernel-Core/RegisterContextFreeBSDKernelCore_arm64.cpp b/lldb/source/Plugins/Process/FreeBSD-Kernel-Core/RegisterContextFreeBSDKernelCore_arm64.cpp index afd60a64a6365..a0dafeb6732a4 100644 --- a/lldb/source/Plugins/Process/FreeBSD-Kernel-Core/RegisterContextFreeBSDKernelCore_arm64.cpp +++ b/lldb/source/Plugins/Process/FreeBSD-Kernel-Core/RegisterContextFreeBSDKernelCore_arm64.cpp @@ -18,6 +18,12 @@ #include "lldb/Utility/RegisterValue.h" #include "llvm/Support/Endian.h" +#if defined(__FreeBSD__) && defined(__aarch64__) +#include +#include +#include +#endif + using namespace lldb; using namespace lldb_private; @@ -52,6 +58,11 @@ bool RegisterContextFreeBSDKernelCore_arm64::ReadRegister( llvm::support::ulittle64_t sp; } pcb; +#if defined(__FreeBSD__) && defined(__aarch64__) && __FreeBSD_version >= 1400084 + static_assert(offsetof(struct pcb, pcb_x) == offsetof(decltype(pcb), x)); + static_assert(offsetof(struct pcb, pcb_sp) == offsetof(decltype(pcb), sp)); +#endif + // https://cgit.freebsd.org/src/tree/sys/arm64/include/pcb.h?h=stable%2F13 struct { llvm::support::ulittle64_t x[30]; @@ -60,6 +71,12 @@ bool RegisterContextFreeBSDKernelCore_arm64::ReadRegister( llvm::support::ulittle64_t sp; } pcb13; +#if defined(__FreeBSD__) && defined(__aarch64__) && __FreeBSD_version < 1400084 + static_assert(offsetof(struct pcb, pcb_x) == offsetof(decltype(pcb13), x)); + static_assert(offsetof(struct pcb, pcb_lr) == offsetof(decltype(pcb13), lr)); + static_assert(offsetof(struct pcb, pcb_sp) == offsetof(decltype(pcb13), sp)); +#endif + Status error; constexpr int FBSD14 = 1400084; int osreldate = FBSD14; @@ -72,8 +89,8 @@ bool RegisterContextFreeBSDKernelCore_arm64::ReadRegister( // TODO: LLVM 24: Remove FreeBSD 13 support if (osreldate >= FBSD14) { - constexpr uint32_t PCB_FP = 10; - constexpr uint32_t PCB_LR = 11; + constexpr uint32_t pcb_fp = 10; + constexpr uint32_t pcb_lr = 11; size_t rd = m_thread.GetProcess()->ReadMemory(m_pcb_addr, &pcb, sizeof(pcb), error); if (rd != sizeof(pcb)) @@ -92,14 +109,14 @@ bool RegisterContextFreeBSDKernelCore_arm64::ReadRegister( case gpr_x27_arm64: case gpr_x28_arm64: case gpr_fp_arm64: - static_assert(gpr_fp_arm64 - gpr_x19_arm64 == PCB_FP, + static_assert(gpr_fp_arm64 - gpr_x19_arm64 == pcb_fp, "nonconsecutive arm64 register numbers"); value = pcb.x[reg - gpr_x19_arm64]; break; case gpr_lr_arm64: case gpr_pc_arm64: // The pc of crashing thread is stored in lr. - static_assert(gpr_lr_arm64 - gpr_x19_arm64 == PCB_LR, + static_assert(gpr_lr_arm64 - gpr_x19_arm64 == pcb_lr, "nonconsecutive arm64 register numbers"); value = pcb.x[reg - gpr_x19_arm64]; break; diff --git a/lldb/source/Plugins/Process/FreeBSD-Kernel-Core/RegisterContextFreeBSDKernelCore_i386.cpp b/lldb/source/Plugins/Process/FreeBSD-Kernel-Core/RegisterContextFreeBSDKernelCore_i386.cpp index 83ab12c73b918..c88f7f601b12a 100644 --- a/lldb/source/Plugins/Process/FreeBSD-Kernel-Core/RegisterContextFreeBSDKernelCore_i386.cpp +++ b/lldb/source/Plugins/Process/FreeBSD-Kernel-Core/RegisterContextFreeBSDKernelCore_i386.cpp @@ -13,6 +13,11 @@ #include "lldb/Utility/RegisterValue.h" #include "llvm/Support/Endian.h" +#if defined(__FreeBSD__) && defined(__i386__) +#include +#include +#endif + using namespace lldb; using namespace lldb_private; @@ -50,6 +55,15 @@ bool RegisterContextFreeBSDKernelCore_i386::ReadRegister( llvm::support::ulittle32_t eip; } pcb; +#if defined(__FreeBSD__) && defined(__i386__) + static_assert(offsetof(struct pcb, pcb_edi) == offsetof(decltype(pcb), edi)); + static_assert(offsetof(struct pcb, pcb_esi) == offsetof(decltype(pcb), esi)); + static_assert(offsetof(struct pcb, pcb_ebp) == offsetof(decltype(pcb), ebp)); + static_assert(offsetof(struct pcb, pcb_esp) == offsetof(decltype(pcb), esp)); + static_assert(offsetof(struct pcb, pcb_ebx) == offsetof(decltype(pcb), ebx)); + static_assert(offsetof(struct pcb, pcb_eip) == offsetof(decltype(pcb), eip)); +#endif + Status error; size_t rd = m_thread.GetProcess()->ReadMemory(m_pcb_addr, &pcb, sizeof(pcb), error); diff --git a/lldb/source/Plugins/Process/FreeBSD-Kernel-Core/RegisterContextFreeBSDKernelCore_ppc64le.cpp b/lldb/source/Plugins/Process/FreeBSD-Kernel-Core/RegisterContextFreeBSDKernelCore_ppc64le.cpp index 69932eaeb4e0b..b8e5578b1b51e 100644 --- a/lldb/source/Plugins/Process/FreeBSD-Kernel-Core/RegisterContextFreeBSDKernelCore_ppc64le.cpp +++ b/lldb/source/Plugins/Process/FreeBSD-Kernel-Core/RegisterContextFreeBSDKernelCore_ppc64le.cpp @@ -13,6 +13,11 @@ #include "lldb/Utility/RegisterValue.h" #include "llvm/Support/Endian.h" +#if defined(__FreeBSD__) && defined(__powerpc64__) && defined(__LITTLE_ENDIAN__) +#include +#include +#endif + using namespace lldb; using namespace lldb_private; @@ -37,6 +42,15 @@ bool RegisterContextFreeBSDKernelCore_ppc64le::ReadRegister( llvm::support::ulittle64_t lr; } pcb; +#if defined(__FreeBSD__) && defined(__powerpc64__) && defined(__LITTLE_ENDIAN__) + static_assert(offsetof(struct pcb, pcb_context) == + offsetof(decltype(pcb), context)); + static_assert(offsetof(struct pcb, pcb_cr) == offsetof(decltype(pcb), cr)); + static_assert(offsetof(struct pcb, pcb_sp) == offsetof(decltype(pcb), sp)); + static_assert(offsetof(struct pcb, pcb_toc) == offsetof(decltype(pcb), toc)); + static_assert(offsetof(struct pcb, pcb_lr) == offsetof(decltype(pcb), lr)); +#endif + Status error; size_t rd = m_thread.GetProcess()->ReadMemory(m_pcb_addr, &pcb, sizeof(pcb), error); diff --git a/lldb/source/Plugins/Process/FreeBSD-Kernel-Core/RegisterContextFreeBSDKernelCore_riscv64.cpp b/lldb/source/Plugins/Process/FreeBSD-Kernel-Core/RegisterContextFreeBSDKernelCore_riscv64.cpp index b705c6d6d43bd..ea632968f9ebc 100644 --- a/lldb/source/Plugins/Process/FreeBSD-Kernel-Core/RegisterContextFreeBSDKernelCore_riscv64.cpp +++ b/lldb/source/Plugins/Process/FreeBSD-Kernel-Core/RegisterContextFreeBSDKernelCore_riscv64.cpp @@ -13,6 +13,11 @@ #include "lldb/Utility/RegisterValue.h" #include "llvm/Support/Endian.h" +#if defined(__FreeBSD__) && defined(__riscv) && __riscv_xlen == 64 +#include +#include +#endif + using namespace lldb; using namespace lldb_private; @@ -52,6 +57,14 @@ bool RegisterContextFreeBSDKernelCore_riscv64::ReadRegister( llvm::support::ulittle64_t s[12]; } pcb; +#if defined(__FreeBSD__) && defined(__riscv) && __riscv_xlen == 64 + static_assert(offsetof(struct pcb, pcb_ra) == offsetof(decltype(pcb), ra)); + static_assert(offsetof(struct pcb, pcb_sp) == offsetof(decltype(pcb), sp)); + static_assert(offsetof(struct pcb, pcb_gp) == offsetof(decltype(pcb), gp)); + static_assert(offsetof(struct pcb, pcb_tp) == offsetof(decltype(pcb), tp)); + static_assert(offsetof(struct pcb, pcb_s) == offsetof(decltype(pcb), s)); +#endif + Status error; size_t rd = m_thread.GetProcess()->ReadMemory(m_pcb_addr, &pcb, sizeof(pcb), error); diff --git a/lldb/source/Plugins/Process/FreeBSD-Kernel-Core/RegisterContextFreeBSDKernelCore_x86_64.cpp b/lldb/source/Plugins/Process/FreeBSD-Kernel-Core/RegisterContextFreeBSDKernelCore_x86_64.cpp index a4fe219a2e72d..0034408b8f9ba 100644 --- a/lldb/source/Plugins/Process/FreeBSD-Kernel-Core/RegisterContextFreeBSDKernelCore_x86_64.cpp +++ b/lldb/source/Plugins/Process/FreeBSD-Kernel-Core/RegisterContextFreeBSDKernelCore_x86_64.cpp @@ -13,6 +13,11 @@ #include "lldb/Utility/RegisterValue.h" #include "llvm/Support/Endian.h" +#if defined(__FreeBSD__) && defined(__amd64__) +#include +#include +#endif + using namespace lldb; using namespace lldb_private; @@ -54,6 +59,17 @@ bool RegisterContextFreeBSDKernelCore_x86_64::ReadRegister( llvm::support::ulittle64_t rip; } pcb; +#if defined(__FreeBSD__) && defined(__amd64__) + static_assert(offsetof(struct pcb, pcb_r15) == offsetof(decltype(pcb), r15)); + static_assert(offsetof(struct pcb, pcb_r14) == offsetof(decltype(pcb), r14)); + static_assert(offsetof(struct pcb, pcb_r13) == offsetof(decltype(pcb), r13)); + static_assert(offsetof(struct pcb, pcb_r12) == offsetof(decltype(pcb), r12)); + static_assert(offsetof(struct pcb, pcb_rbp) == offsetof(decltype(pcb), rbp)); + static_assert(offsetof(struct pcb, pcb_rsp) == offsetof(decltype(pcb), rsp)); + static_assert(offsetof(struct pcb, pcb_rbx) == offsetof(decltype(pcb), rbx)); + static_assert(offsetof(struct pcb, pcb_rip) == offsetof(decltype(pcb), rip)); +#endif + Status error; size_t rd = m_thread.GetProcess()->ReadMemory(m_pcb_addr, &pcb, sizeof(pcb), error);