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

Code before:
enum {
#define LLDB_PROPERTIES_processfreebsdkernelcore
#include "ProcessFreeBSDKernelCorePropertiesEnum.inc"
};

class PluginProperties : public Properties {
public:
  static llvm::StringRef GetSettingName() {
    return ProcessFreeBSDKernelCore::GetPluginNameStatic();
  }

  PluginProperties() : Properties() {
    m_collection_sp = std::make_shared<OptionValueProperties>(GetSettingName());
    m_collection_sp->Initialize(g_processfreebsdkernelcore_properties_def);
  }

  ~PluginProperties() override = default;

  bool GetReadOnly() const {
    const uint32_t idx = ePropertyReadOnly;
    return GetPropertyAtIndexAs<bool>(idx, true);
  }
};

} // namespace

static PluginProperties &GetGlobalPluginProperties() {
  static PluginProperties g_settings;
  return g_settings;
}

ProcessFreeBSDKernelCore::ProcessFreeBSDKernelCore(lldb::TargetSP target_sp,
                                                   ListenerSP listener_sp,
                                                   kvm_t *kvm,
                                                   const FileSpec &core_file)
    : PostMortemProcess(target_sp, listener_sp, core_file), m_kvm(kvm) {}

ProcessFreeBSDKernelCore::~ProcessFreeBSDKernelCore() {
  if (m_kvm)
    kvm_close(m_kvm);
}

lldb::ProcessSP ProcessFreeBSDKernelCore::CreateInstance(
    lldb::TargetSP target_sp, ListenerSP listener_sp,
    const FileSpec *crash_file, bool can_connect) {
  ModuleSP executable = target_sp->GetExecutableModule();
  if (crash_file && !can_connect && executable) {
    kvm_t *kvm =
        kvm_open2(executable->GetFileSpec().GetPath().c_str(),
                  crash_file->GetPath().c_str(), O_RDONLY, nullptr, nullptr);
    if (kvm)

Review comment (bug):
Unless I'm missing something: These properties aren't added to the global ones yet. That should be done in a `DebuggerInitialize` function, that you pass to `PluginManager::RegisterPlugin`. See for example [`PlatformWasm::DebuggerInitialize`](https://github.com/mchoo7/llvm-project/blob/b7c6d7687c89c6cb94123261d728ad8bc7a5f74f/lldb/source/Plugins/Platform/WebAssembly/PlatformWasm.cpp#L83-L91).

Code after:
#define LLDB_PROPERTIES_processfreebsdkernelcore
#include "ProcessFreeBSDKernelCorePropertiesEnum.inc"
};

class PluginProperties : public Properties {
public:
  static llvm::StringRef GetSettingName() {
    return ProcessFreeBSDKernelCore::GetPluginNameStatic();
  }

  PluginProperties() : Properties() {
    m_collection_sp = std::make_shared<OptionValueProperties>(GetSettingName());
    m_collection_sp->Initialize(g_processfreebsdkernelcore_properties_def);
  }

  ~PluginProperties() override = default;

  bool GetReadOnly() const {
    const uint32_t idx = ePropertyReadOnly;
    return GetPropertyAtIndexAs<bool>(idx, true);
  }
};

} // namespace

static PluginProperties &GetGlobalPluginProperties() {
  static PluginProperties g_settings;
  return g_settings;
}

ProcessFreeBSDKernelCore::ProcessFreeBSDKernelCore(lldb::TargetSP target_sp,
                                                   ListenerSP listener_sp,
                                                   kvm_t *kvm,
                                                   const FileSpec &core_file)
    : PostMortemProcess(target_sp, listener_sp, core_file), m_kvm(kvm) {}

ProcessFreeBSDKernelCore::~ProcessFreeBSDKernelCore() {
  if (m_kvm)
    kvm_close(m_kvm);
}

lldb::ProcessSP ProcessFreeBSDKernelCore::CreateInstance(
    lldb::TargetSP target_sp, ListenerSP listener_sp,
    const FileSpec *crash_file, bool can_connect) {
  ModuleSP executable = target_sp->GetExecutableModule();
  if (crash_file && !can_connect && executable) {
    kvm_t *kvm =
        kvm_open2(executable->GetFileSpec().GetPath().c_str(),
                  crash_file->GetPath().c_str(), O_RDONLY, nullptr, nullptr);
    if (kvm)
      return std::make_shared<ProcessFreeBSDKernelCore>(target_sp, listener_sp,