Repository: llvm/llvm-project
File: lldb/source/Plugins/Process/FreeBSDKernel/RegisterContextFreeBSDKernel_arm64.cpp (C++)

Code before:
  return false;
}

bool RegisterContextFreeBSDKernel_arm64::ReadRegister(
    const RegisterInfo *reg_info, RegisterValue &value) {
  if (m_pcb_addr == LLDB_INVALID_ADDRESS)
    return false;

  struct {
#define PCB_FP 10
#define PCB_LR 11
    llvm::support::ulittle64_t x[12];
    llvm::support::ulittle64_t sp;
  } pcb;

  struct {
    llvm::support::ulittle64_t x[30];
    llvm::support::ulittle64_t lr;
    llvm::support::ulittle64_t _reserved;
    llvm::support::ulittle64_t sp;
  } pcb13;

  Status error;

  // TODO: LLVM 24: Remove FreeBSD 13 support
  if (GetOsreldate() > 1400084) {
    size_t rd =
        m_thread.GetProcess()->ReadMemory(m_pcb_addr, &pcb, sizeof(pcb), error);
    if (rd != sizeof(pcb))
      return false;

    uint32_t reg = reg_info->kinds[lldb::eRegisterKindLLDB];
    switch (reg) {
    case gpr_x19_arm64:
    case gpr_x20_arm64:
    case gpr_x21_arm64:
    case gpr_x22_arm64:
    case gpr_x23_arm64:
    case gpr_x24_arm64:
    case gpr_x25_arm64:
    case gpr_x26_arm64:
    case gpr_x27_arm64:
    case gpr_x28_arm64:
    case gpr_fp_arm64:
      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.

Review comment (suggestion):
I don't actually see the change of __FreeBSD_version in https://github.com/freebsd/freebsd-src/commit/1c1f31a5e517ebb940c752c3468b03cdc687c5c7#diff-d07b4e228ca340857a90658e328d65f8dea9c5063e99197fbaaa046d97ae927c.

I wanted to check the right number was being checked here. Please find when it was bumped and link that commit in the PR description too. (even if it is the case that it was forgotten, and you're using the next time it was bumped for some other reason)

Code after:
bool RegisterContextFreeBSDKernel_arm64::WriteFPR() {
  assert(0);
  return false;
}

bool RegisterContextFreeBSDKernel_arm64::ReadRegister(
    const RegisterInfo *reg_info, RegisterValue &value) {
  if (m_pcb_addr == LLDB_INVALID_ADDRESS)
    return false;

  // https://cgit.freebsd.org/src/tree/sys/arm64/include/pcb.h
  struct {
    llvm::support::ulittle64_t x[12];
    llvm::support::ulittle64_t sp;
  } pcb;

  // https://cgit.freebsd.org/src/tree/sys/arm64/include/pcb.h?h=stable%2F13
  struct {
    llvm::support::ulittle64_t x[30];
    llvm::support::ulittle64_t lr;
    llvm::support::ulittle64_t _reserved;
    llvm::support::ulittle64_t sp;
  } pcb13;

  Status error;
  constexpr int FBSD14 = 1400084;
  int osreldate = FBSD14;

  if (auto osreldate_or_null = GetOsreldate())
    osreldate = *osreldate_or_null;
  else
    LLDB_LOGF(GetLog(LLDBLog::Object),
              "Cannot find osreldate. Defaulting to %d.", FBSD14);

  // TODO: LLVM 24: Remove FreeBSD 13 support
  if (osreldate >= FBSD14) {
    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))
      return false;

    uint32_t reg = reg_info->kinds[lldb::eRegisterKindLLDB];
    switch (reg) {
    case gpr_x19_arm64:
    case gpr_x20_arm64:
    case gpr_x21_arm64:
    case gpr_x22_arm64:
    case gpr_x23_arm64:
    case gpr_x24_arm64: