xref: /netbsd-src/external/gpl3/gcc.old/dist/include/gdb/gdb-index.h (revision 8feb0f0b7eaff0608f8350bbfa3098827b4bb91b)
136ac495dSmrg /* Public attributes of the .gdb_index section.
2*8feb0f0bSmrg    Copyright (C) 2012-2020 Free Software Foundation, Inc.
336ac495dSmrg 
436ac495dSmrg    This file is part of GDB.
536ac495dSmrg 
636ac495dSmrg    This program is free software; you can redistribute it and/or modify
736ac495dSmrg    it under the terms of the GNU General Public License as published by
836ac495dSmrg    the Free Software Foundation; either version 3 of the License, or
936ac495dSmrg    (at your option) any later version.
1036ac495dSmrg 
1136ac495dSmrg    This program is distributed in the hope that it will be useful,
1236ac495dSmrg    but WITHOUT ANY WARRANTY; without even the implied warranty of
1336ac495dSmrg    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1436ac495dSmrg    GNU General Public License for more details.
1536ac495dSmrg 
1636ac495dSmrg    You should have received a copy of the GNU General Public License
1736ac495dSmrg    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
1836ac495dSmrg 
1936ac495dSmrg /* This file contains values for understanding the .gdb_index section
2036ac495dSmrg    needed by more than just GDB, e.g. readelf.  */
2136ac495dSmrg 
2236ac495dSmrg #ifndef GDB_INDEX_H
2336ac495dSmrg #define GDB_INDEX_H
2436ac495dSmrg 
2536ac495dSmrg /* Each symbol in .gdb_index refers to a set of CUs that defines the symbol.
2636ac495dSmrg    Each CU is represented by a 32 bit number that is the index of the CU in
2736ac495dSmrg    the CU table, plus some attributes of the use of the symbol in that CU.
2836ac495dSmrg 
2936ac495dSmrg    The values are defined such that if all the bits are zero, then no
3036ac495dSmrg    special meaning is assigned to any of them.  This is done to preserve
3136ac495dSmrg    compatibility with older indices.  The way this is done is to specify
3236ac495dSmrg    that if the GDB_INDEX_SYMBOL_KIND value is zero then all other attribute
3336ac495dSmrg    bits must be zero.
3436ac495dSmrg 
3536ac495dSmrg     0-23  CU index
3636ac495dSmrg    24-27  reserved
3736ac495dSmrg    28-30  symbol kind
3836ac495dSmrg    31     0 == global, 1 == static
3936ac495dSmrg 
4036ac495dSmrg    Bits 24-27 are reserved because it's easier to relax restrictions than
4136ac495dSmrg    it is to impose them after the fact.  At present 24 bits to represent
4236ac495dSmrg    the CU index is plenty.  If we need more bits for the CU index or for
4336ac495dSmrg    attributes then we have them.  */
4436ac495dSmrg 
4536ac495dSmrg /* Whether the symbol is in GLOBAL_BLOCK (== 0) or STATIC_BLOCK (== 1).  */
4636ac495dSmrg #define GDB_INDEX_SYMBOL_STATIC_SHIFT 31
4736ac495dSmrg #define GDB_INDEX_SYMBOL_STATIC_MASK 1
4836ac495dSmrg #define GDB_INDEX_SYMBOL_STATIC_VALUE(cu_index) \
4936ac495dSmrg   (((cu_index) >> GDB_INDEX_SYMBOL_STATIC_SHIFT) & GDB_INDEX_SYMBOL_STATIC_MASK)
5036ac495dSmrg #define GDB_INDEX_SYMBOL_STATIC_SET_VALUE(cu_index, value) \
5136ac495dSmrg   do { \
5236ac495dSmrg     (cu_index) |= (((value) & GDB_INDEX_SYMBOL_STATIC_MASK) \
5336ac495dSmrg 		   << GDB_INDEX_SYMBOL_STATIC_SHIFT); \
5436ac495dSmrg   } while (0)
5536ac495dSmrg 
5636ac495dSmrg /* The kind of the symbol.
5736ac495dSmrg    We don't use GDB's internal values as these numbers are published
5836ac495dSmrg    so that other tools can build and read .gdb_index.  */
5936ac495dSmrg 
6036ac495dSmrg typedef enum {
6136ac495dSmrg   /* Special value to indicate no attributes are present.  */
6236ac495dSmrg   GDB_INDEX_SYMBOL_KIND_NONE = 0,
6336ac495dSmrg   GDB_INDEX_SYMBOL_KIND_TYPE = 1,
6436ac495dSmrg   GDB_INDEX_SYMBOL_KIND_VARIABLE = 2,
6536ac495dSmrg   GDB_INDEX_SYMBOL_KIND_FUNCTION = 3,
6636ac495dSmrg   GDB_INDEX_SYMBOL_KIND_OTHER = 4,
6736ac495dSmrg   /* We currently allocate 3 bits to record the symbol kind.
6836ac495dSmrg      Give the unused bits a value so gdb will print them sensibly.  */
6936ac495dSmrg   GDB_INDEX_SYMBOL_KIND_UNUSED5 = 5,
7036ac495dSmrg   GDB_INDEX_SYMBOL_KIND_UNUSED6 = 6,
7136ac495dSmrg   GDB_INDEX_SYMBOL_KIND_UNUSED7 = 7
7236ac495dSmrg } gdb_index_symbol_kind;
7336ac495dSmrg 
7436ac495dSmrg #define GDB_INDEX_SYMBOL_KIND_SHIFT 28
7536ac495dSmrg #define GDB_INDEX_SYMBOL_KIND_MASK 7
7636ac495dSmrg #define GDB_INDEX_SYMBOL_KIND_VALUE(cu_index) \
7736ac495dSmrg   ((gdb_index_symbol_kind) (((cu_index) >> GDB_INDEX_SYMBOL_KIND_SHIFT) \
7836ac495dSmrg 			    & GDB_INDEX_SYMBOL_KIND_MASK))
7936ac495dSmrg #define GDB_INDEX_SYMBOL_KIND_SET_VALUE(cu_index, value) \
8036ac495dSmrg   do { \
8136ac495dSmrg     (cu_index) |= (((value) & GDB_INDEX_SYMBOL_KIND_MASK) \
8236ac495dSmrg 		   << GDB_INDEX_SYMBOL_KIND_SHIFT); \
8336ac495dSmrg   } while (0)
8436ac495dSmrg 
8536ac495dSmrg #define GDB_INDEX_RESERVED_SHIFT 24
8636ac495dSmrg #define GDB_INDEX_RESERVED_MASK 15
8736ac495dSmrg #define GDB_INDEX_RESERVED_VALUE(cu_index) \
8836ac495dSmrg   (((cu_index) >> GDB_INDEX_RESERVED_SHIFT) & GDB_INDEX_RESERVED_MASK)
8936ac495dSmrg 
9036ac495dSmrg /* CU index.  */
9136ac495dSmrg #define GDB_INDEX_CU_BITSIZE 24
9236ac495dSmrg #define GDB_INDEX_CU_MASK ((1 << GDB_INDEX_CU_BITSIZE) - 1)
9336ac495dSmrg #define GDB_INDEX_CU_VALUE(cu_index) ((cu_index) & GDB_INDEX_CU_MASK)
9436ac495dSmrg #define GDB_INDEX_CU_SET_VALUE(cu_index, value) \
9536ac495dSmrg   do { \
9636ac495dSmrg     (cu_index) |= (value) & GDB_INDEX_CU_MASK; \
9736ac495dSmrg   } while (0)
9836ac495dSmrg 
9936ac495dSmrg #endif /* GDB_INDEX_H */
100