1 /* DWARF 2 low-level section code
3 Copyright (C) 1994-2020 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>. */
28 #include "dwarf2/section.h"
32 struct dwarf2_section_info
*
33 get_containing_section (const struct dwarf2_section_info
*section
)
35 gdb_assert (section
->is_virtual
);
36 return section
->s
.containing_section
;
40 get_section_bfd_owner (const struct dwarf2_section_info
*section
)
42 if (section
->is_virtual
)
44 section
= get_containing_section (section
);
45 gdb_assert (!section
->is_virtual
);
47 return section
->s
.section
->owner
;
51 get_section_bfd_section (const struct dwarf2_section_info
*section
)
53 if (section
->is_virtual
)
55 section
= get_containing_section (section
);
56 gdb_assert (!section
->is_virtual
);
58 return section
->s
.section
;
62 get_section_name (const struct dwarf2_section_info
*section
)
64 asection
*sectp
= get_section_bfd_section (section
);
66 gdb_assert (sectp
!= NULL
);
67 return bfd_section_name (sectp
);
71 get_section_file_name (const struct dwarf2_section_info
*section
)
73 bfd
*abfd
= get_section_bfd_owner (section
);
75 return bfd_get_filename (abfd
);
79 get_section_id (const struct dwarf2_section_info
*section
)
81 asection
*sectp
= get_section_bfd_section (section
);
89 get_section_flags (const struct dwarf2_section_info
*section
)
91 asection
*sectp
= get_section_bfd_section (section
);
93 gdb_assert (sectp
!= NULL
);
94 return bfd_section_flags (sectp
);
98 dwarf2_section_empty_p (const struct dwarf2_section_info
*section
)
100 if (section
->is_virtual
)
101 return section
->size
== 0;
102 return section
->s
.section
== NULL
|| section
->size
== 0;
106 dwarf2_read_section (struct objfile
*objfile
, dwarf2_section_info
*info
)
110 gdb_byte
*buf
, *retbuf
;
117 if (dwarf2_section_empty_p (info
))
120 sectp
= get_section_bfd_section (info
);
122 /* If this is a virtual section we need to read in the real one first. */
123 if (info
->is_virtual
)
125 struct dwarf2_section_info
*containing_section
=
126 get_containing_section (info
);
128 gdb_assert (sectp
!= NULL
);
129 if ((sectp
->flags
& SEC_RELOC
) != 0)
131 error (_("Dwarf Error: DWP format V2 with relocations is not"
132 " supported in section %s [in module %s]"),
133 get_section_name (info
), get_section_file_name (info
));
135 dwarf2_read_section (objfile
, containing_section
);
136 /* Other code should have already caught virtual sections that don't
138 gdb_assert (info
->virtual_offset
+ info
->size
139 <= containing_section
->size
);
140 /* If the real section is empty or there was a problem reading the
141 section we shouldn't get here. */
142 gdb_assert (containing_section
->buffer
!= NULL
);
143 info
->buffer
= containing_section
->buffer
+ info
->virtual_offset
;
147 /* If the section has relocations, we must read it ourselves.
148 Otherwise we attach it to the BFD. */
149 if ((sectp
->flags
& SEC_RELOC
) == 0)
151 info
->buffer
= gdb_bfd_map_section (sectp
, &info
->size
);
155 buf
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
158 /* When debugging .o files, we may need to apply relocations; see
159 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
160 We never compress sections in .o files, so we only need to
161 try this when the section is not compressed. */
162 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
165 info
->buffer
= retbuf
;
169 abfd
= get_section_bfd_owner (info
);
170 gdb_assert (abfd
!= NULL
);
172 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
173 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
175 error (_("Dwarf Error: Can't read DWARF data"
176 " in section %s [in module %s]"),
177 bfd_section_name (sectp
), bfd_get_filename (abfd
));
This page took 0.03479 seconds and 5 git commands to generate.