New Georgian translation for the ld sub-directory
[binutils-gdb.git] / gdb / memtag.c
blobf5096639b2d2c63863a69e72175b4a2c4dc2f366
1 /* GDB generic memory tagging functions.
3 Copyright (C) 2022-2023 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 "memtag.h"
22 #include "bfd.h"
24 /* See memtag.h */
26 bool
27 get_next_core_memtag_section (bfd *abfd, asection *section,
28 CORE_ADDR address, memtag_section_info &info)
30 /* If the caller provided no SECTION to start from, search from the
31 beginning. */
32 if (section == nullptr)
33 section = bfd_get_section_by_name (abfd, "memtag");
35 /* Go through all the memtag sections and figure out if ADDRESS
36 falls within one of the memory ranges that contain tags. */
37 while (section != nullptr)
39 size_t memtag_range_size = section->rawsize;
40 size_t tags_size = bfd_section_size (section);
42 /* Empty memory range or empty tag dump should not happen. Warn about
43 it but keep going through the sections. */
44 if (memtag_range_size == 0 || tags_size == 0)
46 warning (_("Found memtag section with empty memory "
47 "range or empty tag dump"));
48 continue;
50 else
52 CORE_ADDR start_address = bfd_section_vma (section);
53 CORE_ADDR end_address = start_address + memtag_range_size;
55 /* Is the address within [start_address, end_address)? */
56 if (address >= start_address
57 && address < end_address)
59 info.start_address = start_address;
60 info.end_address = end_address;
61 info.memtag_section = section;
62 return true;
65 section = bfd_get_next_section_by_name (abfd, section);
67 return false;