Home | History | Annotate | Line # | Download | only in dwarf2
      1 /* DIE parent maps
      2 
      3    Copyright (C) 2025 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 "dwarf2/cooked-index-entry.h"
     21 #include "dwarf2/read.h"
     22 #include "dwarf2/parent-map.h"
     23 
     24 /* Dump MAP as parent_map.  */
     25 
     26 static void
     27 dump_parent_map (dwarf2_per_bfd *per_bfd, const struct addrmap *map)
     28 {
     29   auto_obstack temp_storage;
     30 
     31   auto annotate_cooked_index_entry
     32     = [&] (struct ui_file *outfile, CORE_ADDR start_addr, const void *value)
     33 	{
     34 	  const cooked_index_entry *parent_entry
     35 	    = (const cooked_index_entry *)value;
     36 
     37 	  gdb_printf (outfile, "\n\t");
     38 
     39 	  bool found = false;
     40 	  for (auto sections : {per_bfd->infos, per_bfd->types})
     41 	    for (auto section : sections)
     42 	      if ((CORE_ADDR)section.buffer <= start_addr
     43 		&& start_addr < (CORE_ADDR) (section.buffer + section.size))
     44 	      {
     45 		gdb_printf (outfile, "(section: %s, offset: 0x%" PRIx64 ")",
     46 			    section.get_name (),
     47 			    start_addr - (CORE_ADDR)section.buffer);
     48 		found = true;
     49 		break;
     50 	      }
     51 
     52 	  if (!found)
     53 	    gdb_printf (outfile, "()");
     54 
     55 	  if (parent_entry == nullptr)
     56 	    {
     57 	      gdb_printf (outfile, " -> ()");
     58 	      return;
     59 	    }
     60 
     61 	  gdb_printf (outfile, " -> (0x%" PRIx64 ": %s)",
     62 		      to_underlying (parent_entry->die_offset),
     63 		      parent_entry->full_name (&temp_storage));
     64 	};
     65 
     66   addrmap_dump (const_cast<addrmap *> (map), gdb_stdlog, nullptr,
     67 		annotate_cooked_index_entry);
     68 }
     69 
     70 /* See parent-map.h.  */
     71 
     72 void
     73 parent_map::dump (dwarf2_per_bfd *per_bfd) const
     74 {
     75   dump_parent_map (per_bfd, &m_map);
     76 }
     77 
     78 /* See parent-map.h.  */
     79 
     80 void
     81 parent_map_map::dump (dwarf2_per_bfd *per_bfd) const
     82 {
     83   for (const auto &iter : m_maps)
     84     {
     85       gdb_printf (gdb_stdlog, "map start:\n");
     86       dump_parent_map (per_bfd, iter);
     87     }
     88 }
     89