[Lldb-commits] [lldb] [lldb] IRMemoryMap zero address mapping fix (PR #99045)

Jason Molenda via lldb-commits lldb-commits at lists.llvm.org
Sat Jul 20 13:49:53 PDT 2024


jasonmolenda wrote:

I haven't tested it (or even tried to compile it, lol) but I think this loop might be expressable as simply
```
    MemoryRegionInfo region_info;
    while (process_sp->GetMemoryRegionInfo(ret, region_info) == err.Success() &&
        region_info.GetRange().GetRangeEnd() - 1 < end_of_memory) {
      
      // Don't ever choose a memory region starting at address 0,
      // it will conflict with programs that deference null pointers.
      if (ret == 0) {
        ret = region_info.GetRange().GetRangeEnd();
        continue;
      }

      // A memory region that is inaccessible, and large enough, is a good
      // choice.
      if (region_info.GetReadable() != MemoryRegionInfo::OptionalBool::eNo && 
          region_info.GetWritable() != MemoryRegionInfo::OptionalBool::eNo && 
          region_info.GetExecutable() != MemoryRegionInfo::OptionalBool::eNo) {
         if (ret + size < region_info.GetRange().GetRangeEnd()) {
          return ret;
         }
      }
      
      // Get the next region.
      ret = region_info.GetRange().GetRangeEnd();
    }
```

I dropped two behaviors here - one is that it would emit a unique assert if qMemoryRegionInfo worked once, but failed for a different address.  The second is that I think the old code would try to combine consecutive memory regions to make one block large enough to satisfy the size requirement (not sure it was doing this correctly).

https://github.com/llvm/llvm-project/pull/99045


More information about the lldb-commits mailing list