Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
#include "lldb/Utility/RegisterValue.h"
#include "llvm/Support/Endian.h"

#if defined(__FreeBSD__) && defined(__arm__)
#include <cstddef>
#include <machine/frame.h>
#endif

using namespace lldb;
using namespace lldb_private;

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
#include "lldb/Utility/RegisterValue.h"
#include "llvm/Support/Endian.h"

#if defined(__FreeBSD__) && defined(__aarch64__)
#include <cstddef>
#include <machine/pcb.h>
#include <sys/param.h>
#endif

using namespace lldb;
using namespace lldb_private;

Expand Down Expand Up @@ -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];
Expand All @@ -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;
Expand All @@ -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))
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
#include "lldb/Utility/RegisterValue.h"
#include "llvm/Support/Endian.h"

#if defined(__FreeBSD__) && defined(__i386__)
#include <cstddef>
#include <machine/pcb.h>
#endif

using namespace lldb;
using namespace lldb_private;

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
#include "lldb/Utility/RegisterValue.h"
#include "llvm/Support/Endian.h"

#if defined(__FreeBSD__) && defined(__powerpc64__) && defined(__LITTLE_ENDIAN__)
#include <cstddef>
#include <machine/pcb.h>
#endif

using namespace lldb;
using namespace lldb_private;

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
#include "lldb/Utility/RegisterValue.h"
#include "llvm/Support/Endian.h"

#if defined(__FreeBSD__) && defined(__riscv) && __riscv_xlen == 64
#include <cstddef>
#include <machine/pcb.h>
#endif

using namespace lldb;
using namespace lldb_private;

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
#include "lldb/Utility/RegisterValue.h"
#include "llvm/Support/Endian.h"

#if defined(__FreeBSD__) && defined(__amd64__)
#include <cstddef>
#include <machine/pcb.h>
#endif

using namespace lldb;
using namespace lldb_private;

Expand Down Expand Up @@ -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);
Expand Down