Home | History | Annotate | Line # | Download | only in dwarf2
      1 /* DWARF indexer
      2 
      3    Copyright (C) 2022-2025 Free Software Foundation, Inc.
      4 
      5    This file is part of GDB.
      6 
      7    This program is free software; you can redistribute it and/or modify
      8    it under the terms of the GNU General Public License as published by
      9    the Free Software Foundation; either version 3 of the License, or
     10    (at your option) any later version.
     11 
     12    This program is distributed in the hope that it will be useful,
     13    but WITHOUT ANY WARRANTY; without even the implied warranty of
     14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15    GNU General Public License for more details.
     16 
     17    You should have received a copy of the GNU General Public License
     18    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
     19 
     20 #ifndef GDB_DWARF2_COOKED_INDEXER_H
     21 #define GDB_DWARF2_COOKED_INDEXER_H
     22 
     23 #include "dwarf2/cooked-index-entry.h"
     24 #include "dwarf2/parent-map.h"
     25 #include "dwarf2/types.h"
     26 #include <variant>
     27 
     28 struct abbrev_info;
     29 struct cooked_index_worker_result;
     30 struct cutu_reader;
     31 struct dwarf2_per_cu;
     32 struct dwarf2_per_objfile;
     33 struct section_and_offset;
     34 
     35 /* An instance of this is created to index a CU.  */
     36 
     37 class cooked_indexer
     38 {
     39 public:
     40   cooked_indexer (cooked_index_worker_result *storage, dwarf2_per_cu *per_cu,
     41 		  enum language language);
     42 
     43   DISABLE_COPY_AND_ASSIGN (cooked_indexer);
     44 
     45   /* Index the given CU.  */
     46   void make_index (cutu_reader *reader);
     47 
     48 private:
     49 
     50   /* A helper function to scan the PC bounds of READER and record them
     51      in the storage's addrmap.  */
     52   void check_bounds (cutu_reader *reader);
     53 
     54   /* Ensure that the indicated CU exists.  The cutu_reader for it is
     55      returned.  FOR_SCANNING is true if the caller intends to scan all
     56      the DIEs in the CU; when false, this use is assumed to be to look
     57      up just a single DIE.  */
     58   cutu_reader *ensure_cu_exists (cutu_reader *reader,
     59 				 const section_and_offset &sect_off,
     60 				 bool for_scanning);
     61 
     62   /* Index DIEs in the READER starting at INFO_PTR.  PARENT is
     63      the entry for the enclosing scope (nullptr at top level).  FULLY
     64      is true when a full scan must be done -- in some languages,
     65      function scopes must be fully explored in order to find nested
     66      functions.  This returns a pointer to just after the spot where
     67      reading stopped.  */
     68   const gdb_byte *index_dies (cutu_reader *reader,
     69 			      const gdb_byte *info_ptr,
     70 			      std::variant<const cooked_index_entry *,
     71 					   parent_map::addr_type> parent,
     72 			      bool fully);
     73 
     74   /* Scan the attributes for a given DIE and update the out
     75      parameters.  Returns a pointer to the byte after the DIE.  */
     76   const gdb_byte *scan_attributes (dwarf2_per_cu *scanning_per_cu,
     77 				   cutu_reader *reader,
     78 				   const gdb_byte *watermark_ptr,
     79 				   const gdb_byte *info_ptr,
     80 				   const abbrev_info *abbrev,
     81 				   const char **name,
     82 				   const char **linkage_name,
     83 				   cooked_index_flag *flags,
     84 				   sect_offset *sibling_offset,
     85 				   const cooked_index_entry **parent_entry,
     86 				   parent_map::addr_type *maybe_defer,
     87 				   bool *is_enum_class,
     88 				   bool for_specification);
     89 
     90   /* Handle DW_TAG_imported_unit, by scanning the DIE to find
     91      DW_AT_import, and then scanning the referenced CU.  Returns a
     92      pointer to the byte after the DIE.  */
     93   const gdb_byte *index_imported_unit (cutu_reader *reader,
     94 				       const gdb_byte *info_ptr,
     95 				       const abbrev_info *abbrev);
     96 
     97   /* Recursively read DIEs, recording the section offsets in
     98      m_die_range_map and then calling index_dies.  */
     99   const gdb_byte *recurse (cutu_reader *reader,
    100 			   const gdb_byte *info_ptr,
    101 			   std::variant<const cooked_index_entry *,
    102 					parent_map::addr_type> parent_entry,
    103 			   bool fully);
    104 
    105   /* The storage object, where the results are kept.  */
    106   cooked_index_worker_result *m_index_storage;
    107   /* The CU that we are reading on behalf of.  This object might be
    108      asked to index one CU but to treat the results as if they come
    109      from some including CU; in this case the including CU would be
    110      recorded here.  */
    111   dwarf2_per_cu *m_per_cu;
    112   /* The language that we're assuming when reading.  */
    113   enum language m_language;
    114 
    115   /* Map from DIE ranges to newly-created entries.  */
    116   parent_map *m_die_range_map;
    117 };
    118 
    119 #endif /* GDB_DWARF2_COOKED_INDEXER_H */
    120