]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/memtag.c
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / memtag.c
1 /* GDB generic memory tagging functions.
2
3 Copyright (C) 2022-2023 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
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.
11
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.
16
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/>. */
19
20 #include "defs.h"
21 #include "memtag.h"
22 #include "bfd.h"
23
24 /* See memtag.h */
25
26 bool
27 get_next_core_memtag_section (bfd *abfd, asection *section,
28 CORE_ADDR address, memtag_section_info &info)
29 {
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");
34
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)
38 {
39 size_t memtag_range_size = section->rawsize;
40 size_t tags_size = bfd_section_size (section);
41
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)
45 {
46 warning (_("Found memtag section with empty memory "
47 "range or empty tag dump"));
48 continue;
49 }
50 else
51 {
52 CORE_ADDR start_address = bfd_section_vma (section);
53 CORE_ADDR end_address = start_address + memtag_range_size;
54
55 /* Is the address within [start_address, end_address)? */
56 if (address >= start_address
57 && address < end_address)
58 {
59 info.start_address = start_address;
60 info.end_address = end_address;
61 info.memtag_section = section;
62 return true;
63 }
64 }
65 section = bfd_get_next_section_by_name (abfd, section);
66 }
67 return false;
68 }