Automatic date update in version.in
[binutils-gdb/blckswan.git] / gdb / memrange.c
blob45a85f7f3183309c6e95dd57d2ec70bdddab1698
1 /* Memory ranges
3 Copyright (C) 2010-2022 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include "defs.h"
21 #include "memrange.h"
22 #include <algorithm>
24 int
25 mem_ranges_overlap (CORE_ADDR start1, int len1,
26 CORE_ADDR start2, int len2)
28 ULONGEST h, l;
30 l = std::max (start1, start2);
31 h = std::min (start1 + len1, start2 + len2);
32 return (l < h);
35 /* See memrange.h. */
37 int
38 address_in_mem_range (CORE_ADDR address, const struct mem_range *r)
40 return (r->start <= address
41 && (address - r->start) < r->length);
44 void
45 normalize_mem_ranges (std::vector<mem_range> *memory)
47 if (!memory->empty ())
49 std::vector<mem_range> &m = *memory;
51 std::sort (m.begin (), m.end ());
53 int a = 0;
54 for (int b = 1; b < m.size (); b++)
56 /* If mem_range B overlaps or is adjacent to mem_range A,
57 merge them. */
58 if (m[b].start <= m[a].start + m[a].length)
60 m[a].length = std::max ((CORE_ADDR) m[a].length,
61 (m[b].start - m[a].start) + m[b].length);
62 continue; /* next b, same a */
64 a++; /* next a */
66 if (a != b)
67 m[a] = m[b];
70 m.resize (a + 1);