memrange.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* The memory range data structure, and associated utilities.
  2. Copyright (C) 2010-2022 Free Software Foundation, Inc.
  3. This file is part of GDB.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  14. #ifndef MEMRANGE_H
  15. #define MEMRANGE_H
  16. /* Defines a [START, START + LENGTH) memory range. */
  17. struct mem_range
  18. {
  19. mem_range () = default;
  20. mem_range (CORE_ADDR start_, int length_)
  21. : start (start_), length (length_)
  22. {}
  23. bool operator< (const mem_range &other) const
  24. {
  25. return this->start < other.start;
  26. }
  27. bool operator== (const mem_range &other) const
  28. {
  29. return (this->start == other.start
  30. && this->length == other.length);
  31. }
  32. /* Lowest address in the range. */
  33. CORE_ADDR start;
  34. /* Length of the range. */
  35. int length;
  36. };
  37. /* Returns true if the ranges defined by [start1, start1+len1) and
  38. [start2, start2+len2) overlap. */
  39. extern int mem_ranges_overlap (CORE_ADDR start1, int len1,
  40. CORE_ADDR start2, int len2);
  41. /* Returns true if ADDR is in RANGE. */
  42. extern int address_in_mem_range (CORE_ADDR addr,
  43. const struct mem_range *range);
  44. /* Sort ranges by start address, then coalesce contiguous or
  45. overlapping ranges. */
  46. extern void normalize_mem_ranges (std::vector<mem_range> *memory);
  47. #endif