Skip to content

[lldb] Replace OptionalBool with LazyBool - #189652

Merged
DavidSpickett merged 2 commits into
llvm:mainfrom
DavidSpickett:lldb-lazy-bool
Apr 1, 2026
Merged

[lldb] Replace OptionalBool with LazyBool#189652
DavidSpickett merged 2 commits into
llvm:mainfrom
DavidSpickett:lldb-lazy-bool

Conversation

@DavidSpickett

Copy link
Copy Markdown
Contributor

The only difference between them is that OptionalBool's third state
is "unknown" and LazyBool's is "calculate". We don't need to tell
the difference in a single context, so I've made a new eLazyBoolDontKnow which is an
alias of eLazyBoolCalculate.

The only difference between them is that OptionalBool's third state
is "unknown" and LazyBool's is "calculate". We don't need to tell
the difference, so I've made a new eLazyBoolDontKnow which is an
alias of eLazyBoolCalculate.
@llvmbot

llvmbot commented Mar 31, 2026

Copy link
Copy Markdown
Member

@llvm/pr-subscribers-lldb

Author: David Spickett (DavidSpickett)

Changes

The only difference between them is that OptionalBool's third state
is "unknown" and LazyBool's is "calculate". We don't need to tell
the difference in a single context, so I've made a new eLazyBoolDontKnow which is an
alias of eLazyBoolCalculate.


Patch is 73.00 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/189652.diff

26 Files Affected:

  • (modified) lldb/include/lldb/Target/MemoryRegionInfo.h (+42-41)
  • (modified) lldb/include/lldb/lldb-private-enumerations.h (+10-1)
  • (modified) lldb/source/API/SBMemoryRegionInfo.cpp (+6-8)
  • (modified) lldb/source/Commands/CommandObjectMemory.cpp (+4-4)
  • (modified) lldb/source/Expression/IRMemoryMap.cpp (+3-6)
  • (modified) lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp (+1-1)
  • (modified) lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp (+15-15)
  • (modified) lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp (+10-10)
  • (modified) lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp (+15-15)
  • (modified) lldb/source/Plugins/Process/Utility/LinuxProcMaps.cpp (+14-14)
  • (modified) lldb/source/Plugins/Process/Utility/MemoryTagManagerAArch64MTE.cpp (+1-1)
  • (modified) lldb/source/Plugins/Process/Windows/Common/ProcessDebugger.cpp (+13-14)
  • (modified) lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp (+19-19)
  • (modified) lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp (+25-25)
  • (modified) lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp (+6-8)
  • (modified) lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp (+1-2)
  • (modified) lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp (+15-17)
  • (modified) lldb/source/Plugins/Process/minidump/MinidumpParser.cpp (+11-11)
  • (modified) lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp (+2-2)
  • (modified) lldb/source/Target/MemoryRegionInfo.cpp (+5-6)
  • (modified) lldb/source/Target/Process.cpp (+6-6)
  • (modified) lldb/unittests/Process/Utility/LinuxProcMapsTest.cpp (+101-115)
  • (modified) lldb/unittests/Process/Utility/MemoryTagManagerAArch64MTETest.cpp (+8-9)
  • (modified) lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp (+13-17)
  • (modified) lldb/unittests/Process/minidump/MinidumpParserTest.cpp (+3-3)
  • (modified) lldb/unittests/Target/MemoryRegionInfoTest.cpp (+3-3)
diff --git a/lldb/include/lldb/Target/MemoryRegionInfo.h b/lldb/include/lldb/Target/MemoryRegionInfo.h
index 527461dd91e91..d6bbe92e0ab58 100644
--- a/lldb/include/lldb/Target/MemoryRegionInfo.h
+++ b/lldb/include/lldb/Target/MemoryRegionInfo.h
@@ -22,12 +22,10 @@ class MemoryRegionInfo {
 public:
   typedef Range<lldb::addr_t, lldb::addr_t> RangeType;
 
-  enum OptionalBool { eDontKnow = -1, eNo = 0, eYes = 1 };
-
   MemoryRegionInfo() = default;
-  MemoryRegionInfo(RangeType range, OptionalBool read, OptionalBool write,
-                   OptionalBool execute, OptionalBool shared,
-                   OptionalBool mapped, ConstString name)
+  MemoryRegionInfo(RangeType range, LazyBool read, LazyBool write,
+                   LazyBool execute, LazyBool shared, LazyBool mapped,
+                   ConstString name)
       : m_range(range), m_read(read), m_write(write), m_execute(execute),
         m_shared(shared), m_mapped(mapped), m_name(name) {}
 
@@ -37,48 +35,48 @@ class MemoryRegionInfo {
 
   const RangeType &GetRange() const { return m_range; }
 
-  OptionalBool GetReadable() const { return m_read; }
+  LazyBool GetReadable() const { return m_read; }
 
-  OptionalBool GetWritable() const { return m_write; }
+  LazyBool GetWritable() const { return m_write; }
 
-  OptionalBool GetExecutable() const { return m_execute; }
+  LazyBool GetExecutable() const { return m_execute; }
 
-  OptionalBool GetShared() const { return m_shared; }
+  LazyBool GetShared() const { return m_shared; }
 
-  OptionalBool GetMapped() const { return m_mapped; }
+  LazyBool GetMapped() const { return m_mapped; }
 
   ConstString GetName() const { return m_name; }
 
-  OptionalBool GetMemoryTagged() const { return m_memory_tagged; }
+  LazyBool GetMemoryTagged() const { return m_memory_tagged; }
 
-  OptionalBool IsShadowStack() const { return m_is_shadow_stack; }
+  LazyBool IsShadowStack() const { return m_is_shadow_stack; }
 
-  void SetReadable(OptionalBool val) { m_read = val; }
+  void SetReadable(LazyBool val) { m_read = val; }
 
-  void SetWritable(OptionalBool val) { m_write = val; }
+  void SetWritable(LazyBool val) { m_write = val; }
 
-  void SetExecutable(OptionalBool val) { m_execute = val; }
+  void SetExecutable(LazyBool val) { m_execute = val; }
 
-  void SetShared(OptionalBool val) { m_shared = val; }
+  void SetShared(LazyBool val) { m_shared = val; }
 
-  void SetMapped(OptionalBool val) { m_mapped = val; }
+  void SetMapped(LazyBool val) { m_mapped = val; }
 
   void SetName(const char *name) { m_name = ConstString(name); }
 
-  OptionalBool GetFlash() const { return m_flash; }
+  LazyBool GetFlash() const { return m_flash; }
 
-  void SetFlash(OptionalBool val) { m_flash = val; }
+  void SetFlash(LazyBool val) { m_flash = val; }
 
   lldb::offset_t GetBlocksize() const { return m_blocksize; }
 
   void SetBlocksize(lldb::offset_t blocksize) { m_blocksize = blocksize; }
 
-  MemoryRegionInfo &SetMemoryTagged(OptionalBool val) {
+  MemoryRegionInfo &SetMemoryTagged(LazyBool val) {
     m_memory_tagged = val;
     return *this;
   }
 
-  MemoryRegionInfo &SetIsShadowStack(OptionalBool val) {
+  MemoryRegionInfo &SetIsShadowStack(LazyBool val) {
     m_is_shadow_stack = val;
     return *this;
   }
@@ -87,11 +85,11 @@ class MemoryRegionInfo {
   // lldb::Permissions
   uint32_t GetLLDBPermissions() const {
     uint32_t permissions = 0;
-    if (m_read == eYes)
+    if (m_read == eLazyBoolYes)
       permissions |= lldb::ePermissionsReadable;
-    if (m_write == eYes)
+    if (m_write == eLazyBoolYes)
       permissions |= lldb::ePermissionsWritable;
-    if (m_execute == eYes)
+    if (m_execute == eLazyBoolYes)
       permissions |= lldb::ePermissionsExecutable;
     return permissions;
   }
@@ -99,9 +97,12 @@ class MemoryRegionInfo {
   // Set permissions from a uint32_t that contains one or more bits from the
   // lldb::Permissions
   void SetLLDBPermissions(uint32_t permissions) {
-    m_read = (permissions & lldb::ePermissionsReadable) ? eYes : eNo;
-    m_write = (permissions & lldb::ePermissionsWritable) ? eYes : eNo;
-    m_execute = (permissions & lldb::ePermissionsExecutable) ? eYes : eNo;
+    m_read =
+        (permissions & lldb::ePermissionsReadable) ? eLazyBoolYes : eLazyBoolNo;
+    m_write =
+        (permissions & lldb::ePermissionsWritable) ? eLazyBoolYes : eLazyBoolNo;
+    m_execute = (permissions & lldb::ePermissionsExecutable) ? eLazyBoolYes
+                                                             : eLazyBoolNo;
   }
 
   bool operator==(const MemoryRegionInfo &rhs) const {
@@ -131,9 +132,9 @@ class MemoryRegionInfo {
     return m_dirty_pages;
   }
 
-  OptionalBool IsStackMemory() const { return m_is_stack_memory; }
+  LazyBool IsStackMemory() const { return m_is_stack_memory; }
 
-  void SetIsStackMemory(OptionalBool val) { m_is_stack_memory = val; }
+  void SetIsStackMemory(LazyBool val) { m_is_stack_memory = val; }
 
   void SetPageSize(int pagesize) { m_pagesize = pagesize; }
 
@@ -145,17 +146,17 @@ class MemoryRegionInfo {
 
 protected:
   RangeType m_range;
-  OptionalBool m_read = eDontKnow;
-  OptionalBool m_write = eDontKnow;
-  OptionalBool m_execute = eDontKnow;
-  OptionalBool m_shared = eDontKnow;
-  OptionalBool m_mapped = eDontKnow;
+  LazyBool m_read = eLazyBoolDontKnow;
+  LazyBool m_write = eLazyBoolDontKnow;
+  LazyBool m_execute = eLazyBoolDontKnow;
+  LazyBool m_shared = eLazyBoolDontKnow;
+  LazyBool m_mapped = eLazyBoolDontKnow;
   ConstString m_name;
-  OptionalBool m_flash = eDontKnow;
+  LazyBool m_flash = eLazyBoolDontKnow;
   lldb::offset_t m_blocksize = 0;
-  OptionalBool m_memory_tagged = eDontKnow;
-  OptionalBool m_is_stack_memory = eDontKnow;
-  OptionalBool m_is_shadow_stack = eDontKnow;
+  LazyBool m_memory_tagged = eLazyBoolDontKnow;
+  LazyBool m_is_stack_memory = eLazyBoolDontKnow;
+  LazyBool m_is_shadow_stack = eLazyBoolDontKnow;
   int m_pagesize = 0;
   std::optional<std::vector<lldb::addr_t>> m_dirty_pages;
 };
@@ -190,9 +191,9 @@ template <>
 /// Options is a single character, it uses that character for the "yes" value,
 /// while "no" is printed as "-", and "don't know" as "?". This can be used to
 /// print the permissions in the traditional "rwx" form.
-struct format_provider<lldb_private::MemoryRegionInfo::OptionalBool> {
-  static void format(const lldb_private::MemoryRegionInfo::OptionalBool &B,
-                     raw_ostream &OS, StringRef Options);
+struct format_provider<lldb_private::LazyBool> {
+  static void format(const lldb_private::LazyBool &B, raw_ostream &OS,
+                     StringRef Options);
 };
 } // namespace llvm
 
diff --git a/lldb/include/lldb/lldb-private-enumerations.h b/lldb/include/lldb/lldb-private-enumerations.h
index cc4657c87cb0f..a6965657f5bc9 100644
--- a/lldb/include/lldb/lldb-private-enumerations.h
+++ b/lldb/include/lldb/lldb-private-enumerations.h
@@ -120,7 +120,16 @@ enum SortOrder {
 // LazyBool is for boolean values that need to be calculated lazily. Values
 // start off set to eLazyBoolCalculate, and then they can be calculated once
 // and set to eLazyBoolNo or eLazyBoolYes.
-enum LazyBool { eLazyBoolCalculate = -1, eLazyBoolNo = 0, eLazyBoolYes = 1 };
+//
+// eLazyBoolDontKnow is the same value as eLazyBoolCalculate but is used in
+// contexts where the calculation is always attempted, but may turn out to not
+// be possible.
+enum LazyBool {
+  eLazyBoolCalculate = -1,
+  eLazyBoolDontKnow = eLazyBoolCalculate,
+  eLazyBoolNo = 0,
+  eLazyBoolYes = 1
+};
 
 /// Instruction types
 enum InstructionType {
diff --git a/lldb/source/API/SBMemoryRegionInfo.cpp b/lldb/source/API/SBMemoryRegionInfo.cpp
index cd25be5d52769..df85b5eb6e289 100644
--- a/lldb/source/API/SBMemoryRegionInfo.cpp
+++ b/lldb/source/API/SBMemoryRegionInfo.cpp
@@ -32,10 +32,8 @@ SBMemoryRegionInfo::SBMemoryRegionInfo(const char *name, lldb::addr_t begin,
   m_opaque_up->GetRange().SetRangeBase(begin);
   m_opaque_up->GetRange().SetRangeEnd(end);
   m_opaque_up->SetLLDBPermissions(permissions);
-  m_opaque_up->SetMapped(mapped ? MemoryRegionInfo::eYes
-                                : MemoryRegionInfo::eNo);
-  m_opaque_up->SetIsStackMemory(stack_memory ? MemoryRegionInfo::eYes
-                                             : MemoryRegionInfo::eNo);
+  m_opaque_up->SetMapped(mapped ? eLazyBoolYes : eLazyBoolNo);
+  m_opaque_up->SetIsStackMemory(stack_memory ? eLazyBoolYes : eLazyBoolNo);
 }
 
 SBMemoryRegionInfo::SBMemoryRegionInfo(const MemoryRegionInfo *lldb_object_ptr)
@@ -97,25 +95,25 @@ lldb::addr_t SBMemoryRegionInfo::GetRegionEnd() {
 bool SBMemoryRegionInfo::IsReadable() {
   LLDB_INSTRUMENT_VA(this);
 
-  return m_opaque_up->GetReadable() == MemoryRegionInfo::eYes;
+  return m_opaque_up->GetReadable() == eLazyBoolYes;
 }
 
 bool SBMemoryRegionInfo::IsWritable() {
   LLDB_INSTRUMENT_VA(this);
 
-  return m_opaque_up->GetWritable() == MemoryRegionInfo::eYes;
+  return m_opaque_up->GetWritable() == eLazyBoolYes;
 }
 
 bool SBMemoryRegionInfo::IsExecutable() {
   LLDB_INSTRUMENT_VA(this);
 
-  return m_opaque_up->GetExecutable() == MemoryRegionInfo::eYes;
+  return m_opaque_up->GetExecutable() == eLazyBoolYes;
 }
 
 bool SBMemoryRegionInfo::IsMapped() {
   LLDB_INSTRUMENT_VA(this);
 
-  return m_opaque_up->GetMapped() == MemoryRegionInfo::eYes;
+  return m_opaque_up->GetMapped() == eLazyBoolYes;
 }
 
 const char *SBMemoryRegionInfo::GetName() {
diff --git a/lldb/source/Commands/CommandObjectMemory.cpp b/lldb/source/Commands/CommandObjectMemory.cpp
index 21ee0f21b8e0e..f8d9d027bdff0 100644
--- a/lldb/source/Commands/CommandObjectMemory.cpp
+++ b/lldb/source/Commands/CommandObjectMemory.cpp
@@ -1688,11 +1688,11 @@ class CommandObjectMemoryRegion : public CommandObjectParsed {
         range_info.GetRange().GetRangeEnd(), range_info.GetReadable(),
         range_info.GetWritable(), range_info.GetExecutable(), name ? " " : "",
         name, section_name ? " " : "", section_name);
-    MemoryRegionInfo::OptionalBool memory_tagged = range_info.GetMemoryTagged();
-    if (memory_tagged == MemoryRegionInfo::OptionalBool::eYes)
+    LazyBool memory_tagged = range_info.GetMemoryTagged();
+    if (memory_tagged == eLazyBoolYes)
       result.AppendMessage("memory tagging: enabled");
-    MemoryRegionInfo::OptionalBool is_shadow_stack = range_info.IsShadowStack();
-    if (is_shadow_stack == MemoryRegionInfo::OptionalBool::eYes)
+    LazyBool is_shadow_stack = range_info.IsShadowStack();
+    if (is_shadow_stack == eLazyBoolYes)
       result.AppendMessage("shadow stack: yes");
 
     const std::optional<std::vector<addr_t>> &dirty_page_list =
diff --git a/lldb/source/Expression/IRMemoryMap.cpp b/lldb/source/Expression/IRMemoryMap.cpp
index f978217fa8f2b..38921bc91d591 100644
--- a/lldb/source/Expression/IRMemoryMap.cpp
+++ b/lldb/source/Expression/IRMemoryMap.cpp
@@ -122,12 +122,9 @@ lldb::addr_t IRMemoryMap::FindSpace(size_t size) {
           // it can make it harder to debug null dereference crashes
           // in the inferior.
           ret = region_info.GetRange().GetRangeEnd();
-        } else if (region_info.GetReadable() !=
-                       MemoryRegionInfo::OptionalBool::eNo ||
-                   region_info.GetWritable() !=
-                       MemoryRegionInfo::OptionalBool::eNo ||
-                   region_info.GetExecutable() !=
-                       MemoryRegionInfo::OptionalBool::eNo) {
+        } else if (region_info.GetReadable() != eLazyBoolNo ||
+                   region_info.GetWritable() != eLazyBoolNo ||
+                   region_info.GetExecutable() != eLazyBoolNo) {
           if (region_info.GetRange().GetRangeEnd() - 1 >= end_of_memory) {
             ret = LLDB_INVALID_ADDRESS;
             break;
diff --git a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
index 5e7c44d796bb9..8e920f4e127a3 100644
--- a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
+++ b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
@@ -625,7 +625,7 @@ ModuleSP DynamicLoaderPOSIXDYLD::LoadInterpreterModule() {
   MemoryRegionInfo info;
   Target &target = m_process->GetTarget();
   Status status = m_process->GetMemoryRegionInfo(m_interpreter_base, info);
-  if (status.Fail() || info.GetMapped() != MemoryRegionInfo::eYes ||
+  if (status.Fail() || info.GetMapped() != eLazyBoolYes ||
       info.GetName().IsEmpty()) {
     Log *log = GetLog(LLDBLog::DynamicLoader);
     LLDB_LOG(log, "Failed to get interpreter region info: {0}", status);
diff --git a/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp b/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp
index 293471e4278a8..ab8f8a426d9f9 100644
--- a/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp
+++ b/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp
@@ -615,10 +615,10 @@ Status NativeProcessFreeBSD::GetMemoryRegionInfo(lldb::addr_t load_addr,
       range_info.GetRange().SetRangeBase(load_addr);
       range_info.GetRange().SetByteSize(
           proc_entry_info.GetRange().GetRangeBase() - load_addr);
-      range_info.SetReadable(MemoryRegionInfo::OptionalBool::eNo);
-      range_info.SetWritable(MemoryRegionInfo::OptionalBool::eNo);
-      range_info.SetExecutable(MemoryRegionInfo::OptionalBool::eNo);
-      range_info.SetMapped(MemoryRegionInfo::OptionalBool::eNo);
+      range_info.SetReadable(eLazyBoolNo);
+      range_info.SetWritable(eLazyBoolNo);
+      range_info.SetExecutable(eLazyBoolNo);
+      range_info.SetMapped(eLazyBoolNo);
       return error;
     } else if (proc_entry_info.GetRange().Contains(load_addr)) {
       // The target address is within the memory region we're processing here.
@@ -633,10 +633,10 @@ Status NativeProcessFreeBSD::GetMemoryRegionInfo(lldb::addr_t load_addr,
   // load address and the end of the memory as size.
   range_info.GetRange().SetRangeBase(load_addr);
   range_info.GetRange().SetRangeEnd(LLDB_INVALID_ADDRESS);
-  range_info.SetReadable(MemoryRegionInfo::OptionalBool::eNo);
-  range_info.SetWritable(MemoryRegionInfo::OptionalBool::eNo);
-  range_info.SetExecutable(MemoryRegionInfo::OptionalBool::eNo);
-  range_info.SetMapped(MemoryRegionInfo::OptionalBool::eNo);
+  range_info.SetReadable(eLazyBoolNo);
+  range_info.SetWritable(eLazyBoolNo);
+  range_info.SetExecutable(eLazyBoolNo);
+  range_info.SetMapped(eLazyBoolNo);
   return error;
 }
 
@@ -680,22 +680,22 @@ Status NativeProcessFreeBSD::PopulateMemoryRegionCache() {
     info.Clear();
     info.GetRange().SetRangeBase(kv->kve_start);
     info.GetRange().SetRangeEnd(kv->kve_end);
-    info.SetMapped(MemoryRegionInfo::OptionalBool::eYes);
+    info.SetMapped(eLazyBoolYes);
 
     if (kv->kve_protection & VM_PROT_READ)
-      info.SetReadable(MemoryRegionInfo::OptionalBool::eYes);
+      info.SetReadable(eLazyBoolYes);
     else
-      info.SetReadable(MemoryRegionInfo::OptionalBool::eNo);
+      info.SetReadable(eLazyBoolNo);
 
     if (kv->kve_protection & VM_PROT_WRITE)
-      info.SetWritable(MemoryRegionInfo::OptionalBool::eYes);
+      info.SetWritable(eLazyBoolYes);
     else
-      info.SetWritable(MemoryRegionInfo::OptionalBool::eNo);
+      info.SetWritable(eLazyBoolNo);
 
     if (kv->kve_protection & VM_PROT_EXECUTE)
-      info.SetExecutable(MemoryRegionInfo::OptionalBool::eYes);
+      info.SetExecutable(eLazyBoolYes);
     else
-      info.SetExecutable(MemoryRegionInfo::OptionalBool::eNo);
+      info.SetExecutable(eLazyBoolNo);
 
     if (kv->kve_path[0])
       info.SetName(kv->kve_path);
diff --git a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
index fe8e56b527a61..a40a66e838a89 100644
--- a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
+++ b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
@@ -1222,10 +1222,10 @@ Status NativeProcessLinux::GetMemoryRegionInfo(lldb::addr_t load_addr,
       range_info.GetRange().SetRangeBase(load_addr);
       range_info.GetRange().SetByteSize(
           proc_entry_info.GetRange().GetRangeBase() - load_addr);
-      range_info.SetReadable(MemoryRegionInfo::OptionalBool::eNo);
-      range_info.SetWritable(MemoryRegionInfo::OptionalBool::eNo);
-      range_info.SetExecutable(MemoryRegionInfo::OptionalBool::eNo);
-      range_info.SetMapped(MemoryRegionInfo::OptionalBool::eNo);
+      range_info.SetReadable(eLazyBoolNo);
+      range_info.SetWritable(eLazyBoolNo);
+      range_info.SetExecutable(eLazyBoolNo);
+      range_info.SetMapped(eLazyBoolNo);
 
       return error;
     } else if (proc_entry_info.GetRange().Contains(load_addr)) {
@@ -1243,10 +1243,10 @@ Status NativeProcessLinux::GetMemoryRegionInfo(lldb::addr_t load_addr,
   // load address and the end of the memory as size.
   range_info.GetRange().SetRangeBase(load_addr);
   range_info.GetRange().SetRangeEnd(LLDB_INVALID_ADDRESS);
-  range_info.SetReadable(MemoryRegionInfo::OptionalBool::eNo);
-  range_info.SetWritable(MemoryRegionInfo::OptionalBool::eNo);
-  range_info.SetExecutable(MemoryRegionInfo::OptionalBool::eNo);
-  range_info.SetMapped(MemoryRegionInfo::OptionalBool::eNo);
+  range_info.SetReadable(eLazyBoolNo);
+  range_info.SetWritable(eLazyBoolNo);
+  range_info.SetExecutable(eLazyBoolNo);
+  range_info.SetMapped(eLazyBoolNo);
   return error;
 }
 
@@ -1325,8 +1325,8 @@ llvm::Expected<uint64_t>
 NativeProcessLinux::Syscall(llvm::ArrayRef<uint64_t> args) {
   PopulateMemoryRegionCache();
   auto region_it = llvm::find_if(m_mem_region_cache, [](const auto &pair) {
-    return pair.first.GetExecutable() == MemoryRegionInfo::eYes &&
-        pair.first.GetShared() != MemoryRegionInfo::eYes;
+    return pair.first.GetExecutable() == eLazyBoolYes &&
+           pair.first.GetShared() != eLazyBoolYes;
   });
   if (region_it == m_mem_region_cache.end())
     return llvm::createStringError(llvm::inconvertibleErrorCode(),
diff --git a/lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp b/lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
index 8695019c85d46..e4de3fab3a0fa 100644
--- a/lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
+++ b/lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
@@ -647,10 +647,10 @@ Status NativeProcessNetBSD::GetMemoryRegionInfo(lldb::addr_t load_addr,
       range_info.GetRange().SetRangeBase(load_addr);
       range_info.GetRange().SetByteSize(
           proc_entry_info.GetRange().GetRangeBase() - load_addr);
-      range_info.SetReadable(MemoryRegionInfo::OptionalBool::eNo);
-      range_info.SetWritable(MemoryRegionInfo::OptionalBool::eNo);
-      range_info.SetExecutable(MemoryRegionInfo::OptionalBool::eNo);
-      range_info.SetMapped(MemoryRegionInfo::OptionalBool::eNo);
+      range_info.SetReadable(eLazyBoolNo);
+      range_info.SetWritable(eLazyBoolNo);
+      range_info.SetExecutable(eLazyBoolNo);
+      range_info.SetMapped(eLazyBoolNo);
       return error;
     } else if (proc_entry_info.GetRange().Contains(load_addr)) {
       // The target address is within the memory region we're processing here.
@@ -665,10 +665,10 @@ Status NativeProcessNetBSD::GetMemoryRegionInfo(lldb::addr_t load_addr,
   // load address and the end of the memory as size.
   range_info.GetRange().SetRangeBase(load_addr);
   range_info.GetRange().SetRangeEnd(LLDB_INVALID_ADDRESS);
-  range_info.SetReadable(MemoryRegionInfo::OptionalBool::eNo);
-  range_info.SetWritable(MemoryRegionInfo::OptionalBool::eNo);
-  range_info.SetExecutable(MemoryRegionInfo::OptionalBool::eNo);
-  range_info.SetMapped(MemoryRegionInfo::OptionalBool::eNo);
+  range_info.SetReadable(eLazyBoolNo);
+  range_info.SetWritable(eLazyBoolNo);
+  range_info.SetExecutable(eLazyBoolNo);
+  range_info.SetMapped(eLazyBoolNo);
   return error;
 }
 
@@ -696,22 +696,22 @@ Status NativeProcessNetBSD::PopulateMemoryRegionCache() {
     info.Clear();
     info.GetRange().SetRangeBase(vm[i].kve_start);
     info.GetRange().SetRangeEnd(vm[i].kve_end);
-    info.SetMapped(MemoryRegionInfo::OptionalBool::eYes);
+    info.SetMapped(eLazyBoolYes);
 
     if (vm[i].kve_protection & VM_PROT_READ)
-      info.SetReadable(MemoryRegionInfo::OptionalBool::eYes);
+      info.SetReadable(eLazyBoolYes);
     else
-      info.SetReadable(MemoryRegionInfo::OptionalBool::eNo);
+      info.SetReadable(eLazyBoolNo);
 
     if (vm[i].kve_protection & VM_PROT_...
[truncated]

@DavidSpickett

Copy link
Copy Markdown
Contributor Author

Commit 1 is the change and commit 2 is the formatting, if you want to see without formatting or think I should split them up.

@mchoo7 mchoo7 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM for FreeBSD and I agree that OptionalBool is redundant when LazyBool exists.

@JDevlieghere JDevlieghere left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@DavidSpickett
DavidSpickett merged commit 2e51fda into llvm:main Apr 1, 2026
12 checks passed
@DavidSpickett
DavidSpickett deleted the lldb-lazy-bool branch April 1, 2026 08:26
joaovam pushed a commit to joaovam/llvm-project that referenced this pull request Apr 2, 2026
The only difference between them is that OptionalBool's third state
is "unknown" and LazyBool's is "calculate". We don't need to tell
the difference in a single context, so I've made a new eLazyBoolDontKnow
which is an alias of eLazyBoolCalculate.
zwu-2025 pushed a commit to zwu-2025/llvm-project that referenced this pull request May 17, 2026
The only difference between them is that OptionalBool's third state
is "unknown" and LazyBool's is "calculate". We don't need to tell
the difference in a single context, so I've made a new eLazyBoolDontKnow
which is an alias of eLazyBoolCalculate.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants