17d62b00eSchristos /* DWARF 2 low-level section code 27d62b00eSchristos 3*6881a400Schristos Copyright (C) 1994-2023 Free Software Foundation, Inc. 47d62b00eSchristos 57d62b00eSchristos Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology, 67d62b00eSchristos Inc. with support from Florida State University (under contract 77d62b00eSchristos with the Ada Joint Program Office), and Silicon Graphics, Inc. 87d62b00eSchristos Initial contribution by Brent Benson, Harris Computer Systems, Inc., 97d62b00eSchristos based on Fred Fish's (Cygnus Support) implementation of DWARF 1 107d62b00eSchristos support. 117d62b00eSchristos 127d62b00eSchristos This file is part of GDB. 137d62b00eSchristos 147d62b00eSchristos This program is free software; you can redistribute it and/or modify 157d62b00eSchristos it under the terms of the GNU General Public License as published by 167d62b00eSchristos the Free Software Foundation; either version 3 of the License, or 177d62b00eSchristos (at your option) any later version. 187d62b00eSchristos 197d62b00eSchristos This program is distributed in the hope that it will be useful, 207d62b00eSchristos but WITHOUT ANY WARRANTY; without even the implied warranty of 217d62b00eSchristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 227d62b00eSchristos GNU General Public License for more details. 237d62b00eSchristos 247d62b00eSchristos You should have received a copy of the GNU General Public License 257d62b00eSchristos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 267d62b00eSchristos 277d62b00eSchristos #ifndef GDB_DWARF2_SECTION_H 287d62b00eSchristos #define GDB_DWARF2_SECTION_H 297d62b00eSchristos 307d62b00eSchristos /* A descriptor for dwarf sections. 317d62b00eSchristos 327d62b00eSchristos S.ASECTION, SIZE are typically initialized when the objfile is first 337d62b00eSchristos scanned. BUFFER, READIN are filled in later when the section is read. 347d62b00eSchristos If the section contained compressed data then SIZE is updated to record 357d62b00eSchristos the uncompressed size of the section. 367d62b00eSchristos 377d62b00eSchristos DWP file format V2 introduces a wrinkle that is easiest to handle by 387d62b00eSchristos creating the concept of virtual sections contained within a real section. 397d62b00eSchristos In DWP V2 the sections of the input DWO files are concatenated together 407d62b00eSchristos into one section, but section offsets are kept relative to the original 417d62b00eSchristos input section. 427d62b00eSchristos If this is a virtual dwp-v2 section, S.CONTAINING_SECTION is a backlink to 437d62b00eSchristos the real section this "virtual" section is contained in, and BUFFER,SIZE 447d62b00eSchristos describe the virtual section. */ 457d62b00eSchristos 467d62b00eSchristos struct dwarf2_section_info 477d62b00eSchristos { 487d62b00eSchristos /* Return the name of this section. */ 497d62b00eSchristos const char *get_name () const; 507d62b00eSchristos 517d62b00eSchristos /* Return the containing section of this section, which must be a 527d62b00eSchristos virtual section. */ 537d62b00eSchristos struct dwarf2_section_info *get_containing_section () const; 547d62b00eSchristos 557d62b00eSchristos /* Return the bfd owner of this section. */ 567d62b00eSchristos struct bfd *get_bfd_owner () const; 577d62b00eSchristos 587d62b00eSchristos /* Return the bfd section of this section. 597d62b00eSchristos Returns NULL if the section is not present. */ 607d62b00eSchristos asection *get_bfd_section () const; 617d62b00eSchristos 627d62b00eSchristos /* Return the name of the file this section is in. */ 637d62b00eSchristos const char *get_file_name () const; 647d62b00eSchristos 657d62b00eSchristos /* Return the id of this section. 667d62b00eSchristos Returns 0 if this section doesn't exist. */ 677d62b00eSchristos int get_id () const; 687d62b00eSchristos 697d62b00eSchristos /* Return the flags of this section. This section (or containing 707d62b00eSchristos section if this is a virtual section) must exist. */ 717d62b00eSchristos int get_flags () const; 727d62b00eSchristos 737d62b00eSchristos /* Return true if this section does not exist or if it has no 747d62b00eSchristos contents. */ 757d62b00eSchristos bool empty () const; 767d62b00eSchristos 777d62b00eSchristos /* Read the contents of this section. 787d62b00eSchristos OBJFILE is the main object file, but not necessarily the file where 797d62b00eSchristos the section comes from. E.g., for DWO files the bfd of INFO is the bfd 807d62b00eSchristos of the DWO file. 817d62b00eSchristos If the section is compressed, uncompress it before returning. */ 827d62b00eSchristos void read (struct objfile *objfile); 837d62b00eSchristos 847d62b00eSchristos /* A helper function that returns the size of a section in a safe way. 857d62b00eSchristos If you are positive that the section has been read before using the 867d62b00eSchristos size, then it is safe to refer to the dwarf2_section_info object's 877d62b00eSchristos "size" field directly. In other cases, you must call this 887d62b00eSchristos function, because for compressed sections the size field is not set 897d62b00eSchristos correctly until the section has been read. */ 907d62b00eSchristos bfd_size_type get_size (struct objfile *objfile) 917d62b00eSchristos { 927d62b00eSchristos if (!readin) 937d62b00eSchristos read (objfile); 947d62b00eSchristos return size; 957d62b00eSchristos } 967d62b00eSchristos 977d62b00eSchristos /* Issue a complaint that something was outside the bounds of this 987d62b00eSchristos buffer. */ 997d62b00eSchristos void overflow_complaint () const; 1007d62b00eSchristos 1017d62b00eSchristos /* Return pointer to string in this section at offset STR_OFFSET 1027d62b00eSchristos with error reporting string FORM_NAME. */ 1037d62b00eSchristos const char *read_string (struct objfile *objfile, LONGEST str_offset, 1047d62b00eSchristos const char *form_name); 1057d62b00eSchristos 1067d62b00eSchristos union 1077d62b00eSchristos { 1087d62b00eSchristos /* If this is a real section, the bfd section. */ 1097d62b00eSchristos asection *section; 1107d62b00eSchristos /* If this is a virtual section, pointer to the containing ("real") 1117d62b00eSchristos section. */ 1127d62b00eSchristos struct dwarf2_section_info *containing_section; 1137d62b00eSchristos } s; 1147d62b00eSchristos /* Pointer to section data, only valid if readin. */ 1157d62b00eSchristos const gdb_byte *buffer; 1167d62b00eSchristos /* The size of the section, real or virtual. */ 1177d62b00eSchristos bfd_size_type size; 1187d62b00eSchristos /* If this is a virtual section, the offset in the real section. 1197d62b00eSchristos Only valid if is_virtual. */ 1207d62b00eSchristos bfd_size_type virtual_offset; 1217d62b00eSchristos /* True if we have tried to read this section. */ 1227d62b00eSchristos bool readin; 1237d62b00eSchristos /* True if this is a virtual section, False otherwise. 1247d62b00eSchristos This specifies which of s.section and s.containing_section to use. */ 1257d62b00eSchristos bool is_virtual; 1267d62b00eSchristos }; 1277d62b00eSchristos 1287d62b00eSchristos #endif /* GDB_DWARF2_SECTION_H */ 129