xref: /netbsd-src/external/gpl3/gcc/dist/include/gdb/gdb-index.h (revision b1e838363e3c6fc78a55519254d99869742dd33c)
14d5abbe8Smrg /* Public attributes of the .gdb_index section.
2*b1e83836Smrg    Copyright (C) 2012-2022 Free Software Foundation, Inc.
34d5abbe8Smrg 
44d5abbe8Smrg    This file is part of GDB.
54d5abbe8Smrg 
64d5abbe8Smrg    This program is free software; you can redistribute it and/or modify
74d5abbe8Smrg    it under the terms of the GNU General Public License as published by
84d5abbe8Smrg    the Free Software Foundation; either version 3 of the License, or
94d5abbe8Smrg    (at your option) any later version.
104d5abbe8Smrg 
114d5abbe8Smrg    This program is distributed in the hope that it will be useful,
124d5abbe8Smrg    but WITHOUT ANY WARRANTY; without even the implied warranty of
134d5abbe8Smrg    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
144d5abbe8Smrg    GNU General Public License for more details.
154d5abbe8Smrg 
164d5abbe8Smrg    You should have received a copy of the GNU General Public License
174d5abbe8Smrg    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
184d5abbe8Smrg 
194d5abbe8Smrg /* This file contains values for understanding the .gdb_index section
204d5abbe8Smrg    needed by more than just GDB, e.g. readelf.  */
214d5abbe8Smrg 
224d5abbe8Smrg #ifndef GDB_INDEX_H
234d5abbe8Smrg #define GDB_INDEX_H
244d5abbe8Smrg 
254d5abbe8Smrg /* Each symbol in .gdb_index refers to a set of CUs that defines the symbol.
264d5abbe8Smrg    Each CU is represented by a 32 bit number that is the index of the CU in
274d5abbe8Smrg    the CU table, plus some attributes of the use of the symbol in that CU.
284d5abbe8Smrg 
294d5abbe8Smrg    The values are defined such that if all the bits are zero, then no
304d5abbe8Smrg    special meaning is assigned to any of them.  This is done to preserve
314d5abbe8Smrg    compatibility with older indices.  The way this is done is to specify
324d5abbe8Smrg    that if the GDB_INDEX_SYMBOL_KIND value is zero then all other attribute
334d5abbe8Smrg    bits must be zero.
344d5abbe8Smrg 
354d5abbe8Smrg     0-23  CU index
364d5abbe8Smrg    24-27  reserved
374d5abbe8Smrg    28-30  symbol kind
384d5abbe8Smrg    31     0 == global, 1 == static
394d5abbe8Smrg 
404d5abbe8Smrg    Bits 24-27 are reserved because it's easier to relax restrictions than
414d5abbe8Smrg    it is to impose them after the fact.  At present 24 bits to represent
424d5abbe8Smrg    the CU index is plenty.  If we need more bits for the CU index or for
434d5abbe8Smrg    attributes then we have them.  */
444d5abbe8Smrg 
454d5abbe8Smrg /* Whether the symbol is in GLOBAL_BLOCK (== 0) or STATIC_BLOCK (== 1).  */
464d5abbe8Smrg #define GDB_INDEX_SYMBOL_STATIC_SHIFT 31
474d5abbe8Smrg #define GDB_INDEX_SYMBOL_STATIC_MASK 1
484d5abbe8Smrg #define GDB_INDEX_SYMBOL_STATIC_VALUE(cu_index) \
494d5abbe8Smrg   (((cu_index) >> GDB_INDEX_SYMBOL_STATIC_SHIFT) & GDB_INDEX_SYMBOL_STATIC_MASK)
504d5abbe8Smrg #define GDB_INDEX_SYMBOL_STATIC_SET_VALUE(cu_index, value) \
514d5abbe8Smrg   do { \
524d5abbe8Smrg     (cu_index) |= (((value) & GDB_INDEX_SYMBOL_STATIC_MASK) \
534d5abbe8Smrg 		   << GDB_INDEX_SYMBOL_STATIC_SHIFT); \
544d5abbe8Smrg   } while (0)
554d5abbe8Smrg 
564d5abbe8Smrg /* The kind of the symbol.
574d5abbe8Smrg    We don't use GDB's internal values as these numbers are published
584d5abbe8Smrg    so that other tools can build and read .gdb_index.  */
594d5abbe8Smrg 
604d5abbe8Smrg typedef enum {
614d5abbe8Smrg   /* Special value to indicate no attributes are present.  */
624d5abbe8Smrg   GDB_INDEX_SYMBOL_KIND_NONE = 0,
634d5abbe8Smrg   GDB_INDEX_SYMBOL_KIND_TYPE = 1,
644d5abbe8Smrg   GDB_INDEX_SYMBOL_KIND_VARIABLE = 2,
654d5abbe8Smrg   GDB_INDEX_SYMBOL_KIND_FUNCTION = 3,
664d5abbe8Smrg   GDB_INDEX_SYMBOL_KIND_OTHER = 4,
674d5abbe8Smrg   /* We currently allocate 3 bits to record the symbol kind.
684d5abbe8Smrg      Give the unused bits a value so gdb will print them sensibly.  */
694d5abbe8Smrg   GDB_INDEX_SYMBOL_KIND_UNUSED5 = 5,
704d5abbe8Smrg   GDB_INDEX_SYMBOL_KIND_UNUSED6 = 6,
714d5abbe8Smrg   GDB_INDEX_SYMBOL_KIND_UNUSED7 = 7
724d5abbe8Smrg } gdb_index_symbol_kind;
734d5abbe8Smrg 
744d5abbe8Smrg #define GDB_INDEX_SYMBOL_KIND_SHIFT 28
754d5abbe8Smrg #define GDB_INDEX_SYMBOL_KIND_MASK 7
764d5abbe8Smrg #define GDB_INDEX_SYMBOL_KIND_VALUE(cu_index) \
774d5abbe8Smrg   ((gdb_index_symbol_kind) (((cu_index) >> GDB_INDEX_SYMBOL_KIND_SHIFT) \
784d5abbe8Smrg 			    & GDB_INDEX_SYMBOL_KIND_MASK))
794d5abbe8Smrg #define GDB_INDEX_SYMBOL_KIND_SET_VALUE(cu_index, value) \
804d5abbe8Smrg   do { \
814d5abbe8Smrg     (cu_index) |= (((value) & GDB_INDEX_SYMBOL_KIND_MASK) \
824d5abbe8Smrg 		   << GDB_INDEX_SYMBOL_KIND_SHIFT); \
834d5abbe8Smrg   } while (0)
844d5abbe8Smrg 
854d5abbe8Smrg #define GDB_INDEX_RESERVED_SHIFT 24
864d5abbe8Smrg #define GDB_INDEX_RESERVED_MASK 15
874d5abbe8Smrg #define GDB_INDEX_RESERVED_VALUE(cu_index) \
884d5abbe8Smrg   (((cu_index) >> GDB_INDEX_RESERVED_SHIFT) & GDB_INDEX_RESERVED_MASK)
894d5abbe8Smrg 
904d5abbe8Smrg /* CU index.  */
914d5abbe8Smrg #define GDB_INDEX_CU_BITSIZE 24
924d5abbe8Smrg #define GDB_INDEX_CU_MASK ((1 << GDB_INDEX_CU_BITSIZE) - 1)
934d5abbe8Smrg #define GDB_INDEX_CU_VALUE(cu_index) ((cu_index) & GDB_INDEX_CU_MASK)
944d5abbe8Smrg #define GDB_INDEX_CU_SET_VALUE(cu_index, value) \
954d5abbe8Smrg   do { \
964d5abbe8Smrg     (cu_index) |= (value) & GDB_INDEX_CU_MASK; \
974d5abbe8Smrg   } while (0)
984d5abbe8Smrg 
994d5abbe8Smrg #endif /* GDB_INDEX_H */
100