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
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to