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

Code before:
}

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;
  auto osreldate_or_null = GetOsreldate();
  if (osreldate_or_null)
    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:
    case gpr_x25_arm64:
    case gpr_x26_arm64:
    case gpr_x27_arm64:

Review comment (suggestion):
You can do:
```
if (auto osreldate_or_null = GetOsreldate())
```

Code after:
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:
    case gpr_x25_arm64:
    case gpr_x26_arm64:
    case gpr_x27_arm64:
    case gpr_x28_arm64:
    case gpr_fp_arm64: