| 1 | /* DWARF 2 low-level section code |
| 2 | |
| 3 | Copyright (C) 1994-2020 Free Software Foundation, Inc. |
| 4 | |
| 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 |
| 10 | support. |
| 11 | |
| 12 | This file is part of GDB. |
| 13 | |
| 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. |
| 18 | |
| 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. |
| 23 | |
| 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/>. */ |
| 26 | |
| 27 | #ifndef GDB_DWARF2_SECTION_H |
| 28 | #define GDB_DWARF2_SECTION_H |
| 29 | |
| 30 | /* A descriptor for dwarf sections. |
| 31 | |
| 32 | S.ASECTION, SIZE are typically initialized when the objfile is first |
| 33 | scanned. BUFFER, READIN are filled in later when the section is read. |
| 34 | If the section contained compressed data then SIZE is updated to record |
| 35 | the uncompressed size of the section. |
| 36 | |
| 37 | DWP file format V2 introduces a wrinkle that is easiest to handle by |
| 38 | creating the concept of virtual sections contained within a real section. |
| 39 | In DWP V2 the sections of the input DWO files are concatenated together |
| 40 | into one section, but section offsets are kept relative to the original |
| 41 | input section. |
| 42 | If this is a virtual dwp-v2 section, S.CONTAINING_SECTION is a backlink to |
| 43 | the real section this "virtual" section is contained in, and BUFFER,SIZE |
| 44 | describe the virtual section. */ |
| 45 | |
| 46 | struct dwarf2_section_info |
| 47 | { |
| 48 | /* Return the name of this section. */ |
| 49 | const char *get_name () const; |
| 50 | |
| 51 | /* Return the containing section of this section, which must be a |
| 52 | virtual section. */ |
| 53 | struct dwarf2_section_info *get_containing_section () const; |
| 54 | |
| 55 | /* Return the bfd owner of this section. */ |
| 56 | struct bfd *get_bfd_owner () const; |
| 57 | |
| 58 | /* Return the bfd section of this section. |
| 59 | Returns NULL if the section is not present. */ |
| 60 | asection *get_bfd_section () const; |
| 61 | |
| 62 | /* Return the name of the file this section is in. */ |
| 63 | const char *get_file_name () const; |
| 64 | |
| 65 | /* Return the id of this section. |
| 66 | Returns 0 if this section doesn't exist. */ |
| 67 | int get_id () const; |
| 68 | |
| 69 | /* Return the flags of this section. This section (or containing |
| 70 | section if this is a virtual section) must exist. */ |
| 71 | int get_flags () const; |
| 72 | |
| 73 | /* Return true if this section does not exist or if it has no |
| 74 | contents. */ |
| 75 | bool empty () const; |
| 76 | |
| 77 | /* Read the contents of this section. |
| 78 | OBJFILE is the main object file, but not necessarily the file where |
| 79 | the section comes from. E.g., for DWO files the bfd of INFO is the bfd |
| 80 | of the DWO file. |
| 81 | If the section is compressed, uncompress it before returning. */ |
| 82 | void read (struct objfile *objfile); |
| 83 | |
| 84 | /* A helper function that returns the size of a section in a safe way. |
| 85 | If you are positive that the section has been read before using the |
| 86 | size, then it is safe to refer to the dwarf2_section_info object's |
| 87 | "size" field directly. In other cases, you must call this |
| 88 | function, because for compressed sections the size field is not set |
| 89 | correctly until the section has been read. */ |
| 90 | bfd_size_type get_size (struct objfile *objfile) |
| 91 | { |
| 92 | if (!readin) |
| 93 | read (objfile); |
| 94 | return size; |
| 95 | } |
| 96 | |
| 97 | union |
| 98 | { |
| 99 | /* If this is a real section, the bfd section. */ |
| 100 | asection *section; |
| 101 | /* If this is a virtual section, pointer to the containing ("real") |
| 102 | section. */ |
| 103 | struct dwarf2_section_info *containing_section; |
| 104 | } s; |
| 105 | /* Pointer to section data, only valid if readin. */ |
| 106 | const gdb_byte *buffer; |
| 107 | /* The size of the section, real or virtual. */ |
| 108 | bfd_size_type size; |
| 109 | /* If this is a virtual section, the offset in the real section. |
| 110 | Only valid if is_virtual. */ |
| 111 | bfd_size_type virtual_offset; |
| 112 | /* True if we have tried to read this section. */ |
| 113 | bool readin; |
| 114 | /* True if this is a virtual section, False otherwise. |
| 115 | This specifies which of s.section and s.containing_section to use. */ |
| 116 | bool is_virtual; |
| 117 | }; |
| 118 | |
| 119 | extern void dwarf2_section_buffer_overflow_complaint |
| 120 | (struct dwarf2_section_info *section); |
| 121 | |
| 122 | #endif /* GDB_DWARF2_SECTION_H */ |