xref: /netbsd-src/external/gpl3/binutils/dist/include/gdb/gdb-index.h (revision cb63e24e8d6aae7ddac1859a9015f48b1d8bd90e)
1883529b6Schristos /* Public attributes of the .gdb_index section.
2*cb63e24eSchristos    Copyright (C) 2012-2024 Free Software Foundation, Inc.
3883529b6Schristos 
4883529b6Schristos    This file is part of GDB.
5883529b6Schristos 
6883529b6Schristos    This program is free software; you can redistribute it and/or modify
7883529b6Schristos    it under the terms of the GNU General Public License as published by
8883529b6Schristos    the Free Software Foundation; either version 3 of the License, or
9883529b6Schristos    (at your option) any later version.
10883529b6Schristos 
11883529b6Schristos    This program is distributed in the hope that it will be useful,
12883529b6Schristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
13883529b6Schristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14883529b6Schristos    GNU General Public License for more details.
15883529b6Schristos 
16883529b6Schristos    You should have received a copy of the GNU General Public License
17883529b6Schristos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
18883529b6Schristos 
19883529b6Schristos /* This file contains values for understanding the .gdb_index section
20883529b6Schristos    needed by more than just GDB, e.g. readelf.  */
21883529b6Schristos 
22883529b6Schristos #ifndef GDB_INDEX_H
23883529b6Schristos #define GDB_INDEX_H
24883529b6Schristos 
25883529b6Schristos /* Each symbol in .gdb_index refers to a set of CUs that defines the symbol.
26883529b6Schristos    Each CU is represented by a 32 bit number that is the index of the CU in
27883529b6Schristos    the CU table, plus some attributes of the use of the symbol in that CU.
28883529b6Schristos 
29883529b6Schristos    The values are defined such that if all the bits are zero, then no
30883529b6Schristos    special meaning is assigned to any of them.  This is done to preserve
31883529b6Schristos    compatibility with older indices.  The way this is done is to specify
32883529b6Schristos    that if the GDB_INDEX_SYMBOL_KIND value is zero then all other attribute
33883529b6Schristos    bits must be zero.
34883529b6Schristos 
35883529b6Schristos     0-23  CU index
36883529b6Schristos    24-27  reserved
37883529b6Schristos    28-30  symbol kind
38883529b6Schristos    31     0 == global, 1 == static
39883529b6Schristos 
40883529b6Schristos    Bits 24-27 are reserved because it's easier to relax restrictions than
41883529b6Schristos    it is to impose them after the fact.  At present 24 bits to represent
42883529b6Schristos    the CU index is plenty.  If we need more bits for the CU index or for
43883529b6Schristos    attributes then we have them.  */
44883529b6Schristos 
45883529b6Schristos /* Whether the symbol is in GLOBAL_BLOCK (== 0) or STATIC_BLOCK (== 1).  */
46883529b6Schristos #define GDB_INDEX_SYMBOL_STATIC_SHIFT 31
47883529b6Schristos #define GDB_INDEX_SYMBOL_STATIC_MASK 1
48883529b6Schristos #define GDB_INDEX_SYMBOL_STATIC_VALUE(cu_index) \
49883529b6Schristos   (((cu_index) >> GDB_INDEX_SYMBOL_STATIC_SHIFT) & GDB_INDEX_SYMBOL_STATIC_MASK)
50883529b6Schristos #define GDB_INDEX_SYMBOL_STATIC_SET_VALUE(cu_index, value) \
51883529b6Schristos   do { \
52883529b6Schristos     (cu_index) |= (((value) & GDB_INDEX_SYMBOL_STATIC_MASK) \
53883529b6Schristos 		   << GDB_INDEX_SYMBOL_STATIC_SHIFT); \
54883529b6Schristos   } while (0)
55883529b6Schristos 
56883529b6Schristos /* The kind of the symbol.
57883529b6Schristos    We don't use GDB's internal values as these numbers are published
58883529b6Schristos    so that other tools can build and read .gdb_index.  */
59883529b6Schristos 
60883529b6Schristos typedef enum {
61883529b6Schristos   /* Special value to indicate no attributes are present.  */
62883529b6Schristos   GDB_INDEX_SYMBOL_KIND_NONE = 0,
63883529b6Schristos   GDB_INDEX_SYMBOL_KIND_TYPE = 1,
64883529b6Schristos   GDB_INDEX_SYMBOL_KIND_VARIABLE = 2,
65883529b6Schristos   GDB_INDEX_SYMBOL_KIND_FUNCTION = 3,
66883529b6Schristos   GDB_INDEX_SYMBOL_KIND_OTHER = 4,
67883529b6Schristos   /* We currently allocate 3 bits to record the symbol kind.
68883529b6Schristos      Give the unused bits a value so gdb will print them sensibly.  */
69883529b6Schristos   GDB_INDEX_SYMBOL_KIND_UNUSED5 = 5,
70883529b6Schristos   GDB_INDEX_SYMBOL_KIND_UNUSED6 = 6,
719573673dSchristos   GDB_INDEX_SYMBOL_KIND_UNUSED7 = 7
72883529b6Schristos } gdb_index_symbol_kind;
73883529b6Schristos 
74883529b6Schristos #define GDB_INDEX_SYMBOL_KIND_SHIFT 28
75883529b6Schristos #define GDB_INDEX_SYMBOL_KIND_MASK 7
76883529b6Schristos #define GDB_INDEX_SYMBOL_KIND_VALUE(cu_index) \
77883529b6Schristos   ((gdb_index_symbol_kind) (((cu_index) >> GDB_INDEX_SYMBOL_KIND_SHIFT) \
78883529b6Schristos 			    & GDB_INDEX_SYMBOL_KIND_MASK))
79883529b6Schristos #define GDB_INDEX_SYMBOL_KIND_SET_VALUE(cu_index, value) \
80883529b6Schristos   do { \
81883529b6Schristos     (cu_index) |= (((value) & GDB_INDEX_SYMBOL_KIND_MASK) \
82883529b6Schristos 		   << GDB_INDEX_SYMBOL_KIND_SHIFT); \
83883529b6Schristos   } while (0)
84883529b6Schristos 
85883529b6Schristos #define GDB_INDEX_RESERVED_SHIFT 24
86883529b6Schristos #define GDB_INDEX_RESERVED_MASK 15
87883529b6Schristos #define GDB_INDEX_RESERVED_VALUE(cu_index) \
88883529b6Schristos   (((cu_index) >> GDB_INDEX_RESERVED_SHIFT) & GDB_INDEX_RESERVED_MASK)
89883529b6Schristos 
90883529b6Schristos /* CU index.  */
91883529b6Schristos #define GDB_INDEX_CU_BITSIZE 24
92883529b6Schristos #define GDB_INDEX_CU_MASK ((1 << GDB_INDEX_CU_BITSIZE) - 1)
93883529b6Schristos #define GDB_INDEX_CU_VALUE(cu_index) ((cu_index) & GDB_INDEX_CU_MASK)
94883529b6Schristos #define GDB_INDEX_CU_SET_VALUE(cu_index, value) \
95883529b6Schristos   do { \
96883529b6Schristos     (cu_index) |= (value) & GDB_INDEX_CU_MASK; \
97883529b6Schristos   } while (0)
98883529b6Schristos 
99883529b6Schristos #endif /* GDB_INDEX_H */
100