Home | History | Annotate | Line # | Download | only in gdb
      1 /* Target sections.
      2 
      3    Copyright (C) 2020-2024 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_TARGET_SECTION_H
     21 #define GDB_TARGET_SECTION_H
     22 
     23 struct bfd;
     24 struct objfile;
     25 struct solib;
     26 
     27 /* A union representing the possible owner types of a target_section.  */
     28 
     29 union target_section_owner
     30 {
     31   target_section_owner () : m_v (nullptr) {}
     32   target_section_owner (const bfd *bfd) : bfd (bfd) {}
     33   target_section_owner (const objfile *objfile) : objfile (objfile) {}
     34   target_section_owner (const solib *solib) : solib (solib) {}
     35 
     36   /* Use this to access the type-erased version of the owner, for
     37      comparisons, printing, etc.  We don't access the M_V member
     38      directly, because pedantically it is not valid to access a
     39      non-active union member.  */
     40   const void *v () const
     41   {
     42     void *tmp;
     43     memcpy (&tmp, this, sizeof (*this));
     44     return tmp;
     45   }
     46 
     47   const struct bfd *bfd;
     48   const struct objfile *objfile;
     49   const struct solib *solib;
     50 
     51 private:
     52   const void *m_v;
     53 };
     54 
     55 /* Struct target_section maps address ranges to file sections.  It is
     56    mostly used with BFD files, but can be used without (e.g. for handling
     57    raw disks, or files not in formats handled by BFD).  */
     58 
     59 struct target_section
     60 {
     61   target_section (CORE_ADDR addr_, CORE_ADDR end_, struct bfd_section *sect_,
     62 		  target_section_owner owner_ = {})
     63     : addr (addr_),
     64       endaddr (end_),
     65       the_bfd_section (sect_),
     66       owner (owner_)
     67   {
     68   }
     69 
     70   /* Lowest address in section.  */
     71   CORE_ADDR addr;
     72   /* Highest address in section, plus 1.  */
     73   CORE_ADDR endaddr;
     74 
     75   /* The BFD section.  */
     76   struct bfd_section *the_bfd_section;
     77 
     78   /* The "owner" of the section.
     79 
     80      It is set by add_target_sections and used by remove_target_sections.
     81      For example, for executables it is a pointer to exec_bfd and
     82      for shlibs it is the solib pointer.  */
     83   target_section_owner owner;
     84 };
     85 
     86 #endif /* GDB_TARGET_SECTION_H */
     87