xref: /netbsd-src/external/gpl3/binutils.old/dist/include/gdb/gdb-index.h (revision e992f068c547fd6e84b3f104dc2340adcc955732)
175fd0b74Schristos /* Public attributes of the .gdb_index section.
2*e992f068Schristos    Copyright (C) 2012-2022 Free Software Foundation, Inc.
375fd0b74Schristos 
475fd0b74Schristos    This file is part of GDB.
575fd0b74Schristos 
675fd0b74Schristos    This program is free software; you can redistribute it and/or modify
775fd0b74Schristos    it under the terms of the GNU General Public License as published by
875fd0b74Schristos    the Free Software Foundation; either version 3 of the License, or
975fd0b74Schristos    (at your option) any later version.
1075fd0b74Schristos 
1175fd0b74Schristos    This program is distributed in the hope that it will be useful,
1275fd0b74Schristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
1375fd0b74Schristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1475fd0b74Schristos    GNU General Public License for more details.
1575fd0b74Schristos 
1675fd0b74Schristos    You should have received a copy of the GNU General Public License
1775fd0b74Schristos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
1875fd0b74Schristos 
1975fd0b74Schristos /* This file contains values for understanding the .gdb_index section
2075fd0b74Schristos    needed by more than just GDB, e.g. readelf.  */
2175fd0b74Schristos 
2275fd0b74Schristos #ifndef GDB_INDEX_H
2375fd0b74Schristos #define GDB_INDEX_H
2475fd0b74Schristos 
2575fd0b74Schristos /* Each symbol in .gdb_index refers to a set of CUs that defines the symbol.
2675fd0b74Schristos    Each CU is represented by a 32 bit number that is the index of the CU in
2775fd0b74Schristos    the CU table, plus some attributes of the use of the symbol in that CU.
2875fd0b74Schristos 
2975fd0b74Schristos    The values are defined such that if all the bits are zero, then no
3075fd0b74Schristos    special meaning is assigned to any of them.  This is done to preserve
3175fd0b74Schristos    compatibility with older indices.  The way this is done is to specify
3275fd0b74Schristos    that if the GDB_INDEX_SYMBOL_KIND value is zero then all other attribute
3375fd0b74Schristos    bits must be zero.
3475fd0b74Schristos 
3575fd0b74Schristos     0-23  CU index
3675fd0b74Schristos    24-27  reserved
3775fd0b74Schristos    28-30  symbol kind
3875fd0b74Schristos    31     0 == global, 1 == static
3975fd0b74Schristos 
4075fd0b74Schristos    Bits 24-27 are reserved because it's easier to relax restrictions than
4175fd0b74Schristos    it is to impose them after the fact.  At present 24 bits to represent
4275fd0b74Schristos    the CU index is plenty.  If we need more bits for the CU index or for
4375fd0b74Schristos    attributes then we have them.  */
4475fd0b74Schristos 
4575fd0b74Schristos /* Whether the symbol is in GLOBAL_BLOCK (== 0) or STATIC_BLOCK (== 1).  */
4675fd0b74Schristos #define GDB_INDEX_SYMBOL_STATIC_SHIFT 31
4775fd0b74Schristos #define GDB_INDEX_SYMBOL_STATIC_MASK 1
4875fd0b74Schristos #define GDB_INDEX_SYMBOL_STATIC_VALUE(cu_index) \
4975fd0b74Schristos   (((cu_index) >> GDB_INDEX_SYMBOL_STATIC_SHIFT) & GDB_INDEX_SYMBOL_STATIC_MASK)
5075fd0b74Schristos #define GDB_INDEX_SYMBOL_STATIC_SET_VALUE(cu_index, value) \
5175fd0b74Schristos   do { \
5275fd0b74Schristos     (cu_index) |= (((value) & GDB_INDEX_SYMBOL_STATIC_MASK) \
5375fd0b74Schristos 		   << GDB_INDEX_SYMBOL_STATIC_SHIFT); \
5475fd0b74Schristos   } while (0)
5575fd0b74Schristos 
5675fd0b74Schristos /* The kind of the symbol.
5775fd0b74Schristos    We don't use GDB's internal values as these numbers are published
5875fd0b74Schristos    so that other tools can build and read .gdb_index.  */
5975fd0b74Schristos 
6075fd0b74Schristos typedef enum {
6175fd0b74Schristos   /* Special value to indicate no attributes are present.  */
6275fd0b74Schristos   GDB_INDEX_SYMBOL_KIND_NONE = 0,
6375fd0b74Schristos   GDB_INDEX_SYMBOL_KIND_TYPE = 1,
6475fd0b74Schristos   GDB_INDEX_SYMBOL_KIND_VARIABLE = 2,
6575fd0b74Schristos   GDB_INDEX_SYMBOL_KIND_FUNCTION = 3,
6675fd0b74Schristos   GDB_INDEX_SYMBOL_KIND_OTHER = 4,
6775fd0b74Schristos   /* We currently allocate 3 bits to record the symbol kind.
6875fd0b74Schristos      Give the unused bits a value so gdb will print them sensibly.  */
6975fd0b74Schristos   GDB_INDEX_SYMBOL_KIND_UNUSED5 = 5,
7075fd0b74Schristos   GDB_INDEX_SYMBOL_KIND_UNUSED6 = 6,
7175fd0b74Schristos   GDB_INDEX_SYMBOL_KIND_UNUSED7 = 7
7275fd0b74Schristos } gdb_index_symbol_kind;
7375fd0b74Schristos 
7475fd0b74Schristos #define GDB_INDEX_SYMBOL_KIND_SHIFT 28
7575fd0b74Schristos #define GDB_INDEX_SYMBOL_KIND_MASK 7
7675fd0b74Schristos #define GDB_INDEX_SYMBOL_KIND_VALUE(cu_index) \
7775fd0b74Schristos   ((gdb_index_symbol_kind) (((cu_index) >> GDB_INDEX_SYMBOL_KIND_SHIFT) \
7875fd0b74Schristos 			    & GDB_INDEX_SYMBOL_KIND_MASK))
7975fd0b74Schristos #define GDB_INDEX_SYMBOL_KIND_SET_VALUE(cu_index, value) \
8075fd0b74Schristos   do { \
8175fd0b74Schristos     (cu_index) |= (((value) & GDB_INDEX_SYMBOL_KIND_MASK) \
8275fd0b74Schristos 		   << GDB_INDEX_SYMBOL_KIND_SHIFT); \
8375fd0b74Schristos   } while (0)
8475fd0b74Schristos 
8575fd0b74Schristos #define GDB_INDEX_RESERVED_SHIFT 24
8675fd0b74Schristos #define GDB_INDEX_RESERVED_MASK 15
8775fd0b74Schristos #define GDB_INDEX_RESERVED_VALUE(cu_index) \
8875fd0b74Schristos   (((cu_index) >> GDB_INDEX_RESERVED_SHIFT) & GDB_INDEX_RESERVED_MASK)
8975fd0b74Schristos 
9075fd0b74Schristos /* CU index.  */
9175fd0b74Schristos #define GDB_INDEX_CU_BITSIZE 24
9275fd0b74Schristos #define GDB_INDEX_CU_MASK ((1 << GDB_INDEX_CU_BITSIZE) - 1)
9375fd0b74Schristos #define GDB_INDEX_CU_VALUE(cu_index) ((cu_index) & GDB_INDEX_CU_MASK)
9475fd0b74Schristos #define GDB_INDEX_CU_SET_VALUE(cu_index, value) \
9575fd0b74Schristos   do { \
9675fd0b74Schristos     (cu_index) |= (value) & GDB_INDEX_CU_MASK; \
9775fd0b74Schristos   } while (0)
9875fd0b74Schristos 
9975fd0b74Schristos #endif /* GDB_INDEX_H */
100