Fix building Loongarch BFD with a 32-bit compiler
[binutils-gdb.git] / gdb / memtag.c
blob54bdc0ad323c1ef75839bad15e6e4a6688556abc
1 /* GDB generic memory tagging functions.
3 Copyright (C) 2022-2024 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 "memtag.h"
21 #include "bfd.h"
23 /* See memtag.h */
25 bool
26 get_next_core_memtag_section (bfd *abfd, asection *section,
27 CORE_ADDR address, memtag_section_info &info)
29 /* If the caller provided no SECTION to start from, search from the
30 beginning. */
31 if (section == nullptr)
32 section = bfd_get_section_by_name (abfd, "memtag");
34 /* Go through all the memtag sections and figure out if ADDRESS
35 falls within one of the memory ranges that contain tags. */
36 while (section != nullptr)
38 size_t memtag_range_size = section->rawsize;
39 size_t tags_size = bfd_section_size (section);
41 /* Empty memory range or empty tag dump should not happen. Warn about
42 it but keep going through the sections. */
43 if (memtag_range_size == 0 || tags_size == 0)
45 warning (_("Found memtag section with empty memory "
46 "range or empty tag dump"));
47 continue;
49 else
51 CORE_ADDR start_address = bfd_section_vma (section);
52 CORE_ADDR end_address = start_address + memtag_range_size;
54 /* Is the address within [start_address, end_address)? */
55 if (address >= start_address
56 && address < end_address)
58 info.start_address = start_address;
59 info.end_address = end_address;
60 info.memtag_section = section;
61 return true;
64 section = bfd_get_next_section_by_name (abfd, section);
66 return false;