aboutsummaryrefslogtreecommitdiff
path: root/gdb/dwarf2/parent-map.c
blob: d029a76294a0c07e60b745c08cce51131c8c2d76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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 <http://www.gnu.org/licenses/>.  */

#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));
	};

  addrmap_dump (const_cast<addrmap *> (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);
    }
}