Repository: llvm/llvm-project
File: lldb/source/Plugins/Process/FreeBSD-Kernel-Core/ProcessFreeBSDKernelCore.cpp (C++)

Code before:

void ProcessFreeBSDKernelCore::RefreshStateAfterStop() {
  if (!m_printed_unread_message) {
    PrintUnreadMessage();
    m_printed_unread_message = true;
  }
}

size_t ProcessFreeBSDKernelCore::DoWriteMemory(lldb::addr_t addr,
                                               const void *buf, size_t size,
                                               Status &error) {
  if (GetGlobalPluginProperties().GetReadOnly()) {
    error = Status::FromErrorString(
        "Memory writes are disabled in read-only mode. Disable with 'settings "
        "set plugin.process.freebsd-kernel-core.read-only false'");
    return 0;
  }

  ssize_t rd = 0;
  rd = kvm_write(m_kvm, addr, buf, size);
  if (rd < 0 || static_cast<size_t>(rd) != size) {
    error = Status::FromErrorStringWithFormat("Writing memory failed: %s",
                                              GetError());
    return rd > 0 ? rd : 0;
  }
  return rd;
}

bool ProcessFreeBSDKernelCore::DoUpdateThreadList(ThreadList &old_thread_list,
                                                  ThreadList &new_thread_list) {
  if (old_thread_list.GetSize(false) == 0) {
    // Make up the thread the first time this is called so we can set our one
    // and only core thread state up.

    // We cannot construct a thread without a register context as that crashes
    // LLDB but we can construct a process without threads to provide minimal
    // memory reading support.
    switch (GetTarget().GetArchitecture().GetMachine()) {
    case llvm::Triple::aarch64:
    case llvm::Triple::x86:
    case llvm::Triple::x86_64:
      break;
    default:
      return false;
    }

    Status error;

    // struct field offsets are written as symbols so that we don't have
    // to figure them out ourselves
    int32_t offset_p_list = ReadSignedIntegerFromMemory(

Review comment (suggestion):
This phrasing is a bit confusing. It's not awful by any means but we can do a better job.

* You say "read-only mode" but this is not a general concept or noun that would help any user find out what to do. It's not something they can search and find anything other than this error message. I would not mention modes at all here.
* Saying "disable" twice is confusing at first because it can be read as if the second disable refers to memory writes. You mean disable the mode, but it's not 100% clear at a glance that that's the case. And once we remove the "mode" mention, this is academic anyway.

So I suggest instead:
Memory writes are currently disabled. You can enable them with `set plugin.process.freebsd-kernel-core.read-only false`.



Code after:
  return Status();
}

DynamicLoader *ProcessFreeBSDKernelCore::GetDynamicLoader() {
  if (m_dyld_up.get() == nullptr)
    m_dyld_up.reset(DynamicLoader::FindPlugin(
        this, DynamicLoaderFreeBSDKernel::GetPluginNameStatic()));
  return m_dyld_up.get();
}

Status ProcessFreeBSDKernelCore::DoDestroy() { return Status(); }

void ProcessFreeBSDKernelCore::RefreshStateAfterStop() {
  if (!m_printed_unread_message) {
    PrintUnreadMessage();
    m_printed_unread_message = true;
  }
}

size_t ProcessFreeBSDKernelCore::DoWriteMemory(lldb::addr_t addr,
                                               const void *buf, size_t size,
                                               Status &error) {
  if (GetGlobalPluginProperties().GetReadOnly()) {
    error = Status::FromErrorString(
        "Memory writes are disabled in read-only mode. Disable with 'settings "
        "set plugin.process.freebsd-kernel-core.read-only false'");
    return 0;
  }

  ssize_t rd = 0;
  rd = kvm_write(m_kvm, addr, buf, size);
  if (rd < 0 || static_cast<size_t>(rd) != size) {
    error = Status::FromErrorStringWithFormat("Writing memory failed: %s",
                                              GetError());
    return rd > 0 ? rd : 0;
  }
  return rd;
}

bool ProcessFreeBSDKernelCore::DoUpdateThreadList(ThreadList &old_thread_list,
                                                  ThreadList &new_thread_list) {
  if (old_thread_list.GetSize(false) == 0) {
    // Make up the thread the first time this is called so we can set our one
    // and only core thread state up.

    // We cannot construct a thread without a register context as that crashes
    // LLDB but we can construct a process without threads to provide minimal
    // memory reading support.
    switch (GetTarget().GetArchitecture().GetMachine()) {
    case llvm::Triple::aarch64:
    case llvm::Triple::x86: