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"
31 #include "complaints.h"
34 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
36 complaint (_("debug info runs off end of %s section"
39 section
->get_file_name ());
42 struct dwarf2_section_info
*
43 dwarf2_section_info::get_containing_section () const
45 gdb_assert (is_virtual
);
46 return s
.containing_section
;
50 dwarf2_section_info::get_bfd_owner () const
52 const dwarf2_section_info
*section
= this;
55 section
= get_containing_section ();
56 gdb_assert (!section
->is_virtual
);
58 return section
->s
.section
->owner
;
62 dwarf2_section_info::get_bfd_section () const
64 const dwarf2_section_info
*section
= this;
65 if (section
->is_virtual
)
67 section
= get_containing_section ();
68 gdb_assert (!section
->is_virtual
);
70 return section
->s
.section
;
74 dwarf2_section_info::get_name () const
76 asection
*sectp
= get_bfd_section ();
78 gdb_assert (sectp
!= NULL
);
79 return bfd_section_name (sectp
);
83 dwarf2_section_info::get_file_name () const
85 bfd
*abfd
= get_bfd_owner ();
87 return bfd_get_filename (abfd
);
91 dwarf2_section_info::get_id () const
93 asection
*sectp
= get_bfd_section ();
101 dwarf2_section_info::get_flags () const
103 asection
*sectp
= get_bfd_section ();
105 gdb_assert (sectp
!= NULL
);
106 return bfd_section_flags (sectp
);
110 dwarf2_section_info::empty () const
114 return s
.section
== NULL
|| size
== 0;
118 dwarf2_section_info::read (struct objfile
*objfile
)
122 gdb_byte
*buf
, *retbuf
;
132 sectp
= get_bfd_section ();
134 /* If this is a virtual section we need to read in the real one first. */
137 struct dwarf2_section_info
*containing_section
=
138 get_containing_section ();
140 gdb_assert (sectp
!= NULL
);
141 if ((sectp
->flags
& SEC_RELOC
) != 0)
143 error (_("Dwarf Error: DWP format V2 with relocations is not"
144 " supported in section %s [in module %s]"),
145 get_name (), get_file_name ());
147 containing_section
->read (objfile
);
148 /* Other code should have already caught virtual sections that don't
150 gdb_assert (virtual_offset
+ size
<= containing_section
->size
);
151 /* If the real section is empty or there was a problem reading the
152 section we shouldn't get here. */
153 gdb_assert (containing_section
->buffer
!= NULL
);
154 buffer
= containing_section
->buffer
+ virtual_offset
;
158 /* If the section has relocations, we must read it ourselves.
159 Otherwise we attach it to the BFD. */
160 if ((sectp
->flags
& SEC_RELOC
) == 0)
162 buffer
= gdb_bfd_map_section (sectp
, &size
);
166 buf
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, size
);
169 /* When debugging .o files, we may need to apply relocations; see
170 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
171 We never compress sections in .o files, so we only need to
172 try this when the section is not compressed. */
173 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
180 abfd
= get_bfd_owner ();
181 gdb_assert (abfd
!= NULL
);
183 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
184 || bfd_bread (buf
, size
, abfd
) != size
)
186 error (_("Dwarf Error: Can't read DWARF data"
187 " in section %s [in module %s]"),
188 bfd_section_name (sectp
), bfd_get_filename (abfd
));
This page took 0.03983 seconds and 4 git commands to generate.