From: Tom Tromey Date: Wed, 26 Feb 2025 02:27:52 +0000 (-0700) Subject: Create dwarf2/parent-map.c X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4ad3a0115d6c542178cd3a0d9b2abdc58fd9ecbd;p=thirdparty%2Fbinutils-gdb.git Create dwarf2/parent-map.c This creates a new file, dwarf2/parent-map.c, to hold some code related to parent maps. This helps shrink read.c a bit. Approved-By: Simon Marchi --- diff --git a/gdb/Makefile.in b/gdb/Makefile.in index 1619c8253dc..a24c86fcff8 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -1110,6 +1110,7 @@ COMMON_SFILES = \ dwarf2/line-header.c \ dwarf2/loc.c \ dwarf2/macro.c \ + dwarf2/parent-map.c \ dwarf2/read.c \ dwarf2/read-debug-names.c \ dwarf2/read-gdb-index.c \ diff --git a/gdb/dwarf2/parent-map.c b/gdb/dwarf2/parent-map.c new file mode 100644 index 00000000000..956f1f287f8 --- /dev/null +++ b/gdb/dwarf2/parent-map.c @@ -0,0 +1,88 @@ +/* DIE parent maps + + Copyright (C) 2025 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include "dwarf2/cooked-index.h" +#include "dwarf2/read.h" +#include "dwarf2/parent-map.h" + +/* Dump MAP as parent_map. */ + +static void +dump_parent_map (dwarf2_per_bfd *per_bfd, const struct addrmap *map) +{ + auto_obstack temp_storage; + + auto annotate_cooked_index_entry + = [&] (struct ui_file *outfile, CORE_ADDR start_addr, const void *value) + { + const cooked_index_entry *parent_entry + = (const cooked_index_entry *)value; + + gdb_printf (outfile, "\n\t"); + + bool found = false; + for (auto sections : {per_bfd->infos, per_bfd->types}) + for (auto section : sections) + if ((CORE_ADDR)section.buffer <= start_addr + && start_addr < (CORE_ADDR) (section.buffer + section.size)) + { + gdb_printf (outfile, "(section: %s, offset: 0x%" PRIx64 ")", + section.get_name (), + start_addr - (CORE_ADDR)section.buffer); + found = true; + break; + } + + if (!found) + gdb_printf (outfile, "()"); + + if (parent_entry == nullptr) + { + gdb_printf (outfile, " -> ()"); + return; + } + + gdb_printf (outfile, " -> (0x%" PRIx64 ": %s)", + to_underlying (parent_entry->die_offset), + parent_entry->full_name (&temp_storage, false)); + }; + + addrmap_dump (const_cast (map), gdb_stdlog, nullptr, + annotate_cooked_index_entry); +} + +/* See parent-map.h. */ + +void +parent_map::dump (dwarf2_per_bfd *per_bfd) const +{ + dump_parent_map (per_bfd, &m_map); +} + +/* See parent-map.h. */ + +void +parent_map_map::dump (dwarf2_per_bfd *per_bfd) const +{ + for (const auto &iter : m_maps) + { + gdb_printf (gdb_stdlog, "map start:\n"); + dump_parent_map (per_bfd, iter); + } +} diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 6080dca6ea6..bacec23af3e 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -3628,72 +3628,6 @@ cooked_index_storage::eq_cutu_reader (const void *a, const void *b) return ra->cu->per_cu->index == *rb; } -/* Dump MAP as parent_map. */ - -static void -dump_parent_map (dwarf2_per_bfd *per_bfd, const struct addrmap *map) -{ - auto_obstack temp_storage; - - auto annotate_cooked_index_entry - = [&] (struct ui_file *outfile, CORE_ADDR start_addr, const void *value) - { - const cooked_index_entry *parent_entry - = (const cooked_index_entry *)value; - - gdb_printf (outfile, "\n\t"); - - bool found = false; - for (auto sections : {per_bfd->infos, per_bfd->types}) - for (auto section : sections) - if ((CORE_ADDR)section.buffer <= start_addr - && start_addr < (CORE_ADDR) (section.buffer + section.size)) - { - gdb_printf (outfile, "(section: %s, offset: 0x%" PRIx64 ")", - section.get_name (), - start_addr - (CORE_ADDR)section.buffer); - found = true; - break; - } - - if (!found) - gdb_printf (outfile, "()"); - - if (parent_entry == nullptr) - { - gdb_printf (outfile, " -> ()"); - return; - } - - gdb_printf (outfile, " -> (0x%" PRIx64 ": %s)", - to_underlying (parent_entry->die_offset), - parent_entry->full_name (&temp_storage, false)); - }; - - addrmap_dump (const_cast (map), gdb_stdlog, nullptr, - annotate_cooked_index_entry); -} - -/* See parent-map.h. */ - -void -parent_map::dump (dwarf2_per_bfd *per_bfd) const -{ - dump_parent_map (per_bfd, &m_map); -} - -/* See parent-map.h. */ - -void -parent_map_map::dump (dwarf2_per_bfd *per_bfd) const -{ - for (const auto &iter : m_maps) - { - gdb_printf (gdb_stdlog, "map start:\n"); - dump_parent_map (per_bfd, iter); - } -} - /* An instance of this is created to index a CU. */ class cooked_indexer