xref: /dflybsd-src/contrib/gcc-8.0/include/gdb/gdb-index.h (revision 38fd149817dfbff97799f62fcb70be98c4e32523)
1*38fd1498Szrj /* Public attributes of the .gdb_index section.
2*38fd1498Szrj    Copyright (C) 2012-2018 Free Software Foundation, Inc.
3*38fd1498Szrj 
4*38fd1498Szrj    This file is part of GDB.
5*38fd1498Szrj 
6*38fd1498Szrj    This program is free software; you can redistribute it and/or modify
7*38fd1498Szrj    it under the terms of the GNU General Public License as published by
8*38fd1498Szrj    the Free Software Foundation; either version 3 of the License, or
9*38fd1498Szrj    (at your option) any later version.
10*38fd1498Szrj 
11*38fd1498Szrj    This program is distributed in the hope that it will be useful,
12*38fd1498Szrj    but WITHOUT ANY WARRANTY; without even the implied warranty of
13*38fd1498Szrj    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14*38fd1498Szrj    GNU General Public License for more details.
15*38fd1498Szrj 
16*38fd1498Szrj    You should have received a copy of the GNU General Public License
17*38fd1498Szrj    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
18*38fd1498Szrj 
19*38fd1498Szrj /* This file contains values for understanding the .gdb_index section
20*38fd1498Szrj    needed by more than just GDB, e.g. readelf.  */
21*38fd1498Szrj 
22*38fd1498Szrj #ifndef GDB_INDEX_H
23*38fd1498Szrj #define GDB_INDEX_H
24*38fd1498Szrj 
25*38fd1498Szrj /* Each symbol in .gdb_index refers to a set of CUs that defines the symbol.
26*38fd1498Szrj    Each CU is represented by a 32 bit number that is the index of the CU in
27*38fd1498Szrj    the CU table, plus some attributes of the use of the symbol in that CU.
28*38fd1498Szrj 
29*38fd1498Szrj    The values are defined such that if all the bits are zero, then no
30*38fd1498Szrj    special meaning is assigned to any of them.  This is done to preserve
31*38fd1498Szrj    compatibility with older indices.  The way this is done is to specify
32*38fd1498Szrj    that if the GDB_INDEX_SYMBOL_KIND value is zero then all other attribute
33*38fd1498Szrj    bits must be zero.
34*38fd1498Szrj 
35*38fd1498Szrj     0-23  CU index
36*38fd1498Szrj    24-27  reserved
37*38fd1498Szrj    28-30  symbol kind
38*38fd1498Szrj    31     0 == global, 1 == static
39*38fd1498Szrj 
40*38fd1498Szrj    Bits 24-27 are reserved because it's easier to relax restrictions than
41*38fd1498Szrj    it is to impose them after the fact.  At present 24 bits to represent
42*38fd1498Szrj    the CU index is plenty.  If we need more bits for the CU index or for
43*38fd1498Szrj    attributes then we have them.  */
44*38fd1498Szrj 
45*38fd1498Szrj /* Whether the symbol is in GLOBAL_BLOCK (== 0) or STATIC_BLOCK (== 1).  */
46*38fd1498Szrj #define GDB_INDEX_SYMBOL_STATIC_SHIFT 31
47*38fd1498Szrj #define GDB_INDEX_SYMBOL_STATIC_MASK 1
48*38fd1498Szrj #define GDB_INDEX_SYMBOL_STATIC_VALUE(cu_index) \
49*38fd1498Szrj   (((cu_index) >> GDB_INDEX_SYMBOL_STATIC_SHIFT) & GDB_INDEX_SYMBOL_STATIC_MASK)
50*38fd1498Szrj #define GDB_INDEX_SYMBOL_STATIC_SET_VALUE(cu_index, value) \
51*38fd1498Szrj   do { \
52*38fd1498Szrj     (cu_index) |= (((value) & GDB_INDEX_SYMBOL_STATIC_MASK) \
53*38fd1498Szrj 		   << GDB_INDEX_SYMBOL_STATIC_SHIFT); \
54*38fd1498Szrj   } while (0)
55*38fd1498Szrj 
56*38fd1498Szrj /* The kind of the symbol.
57*38fd1498Szrj    We don't use GDB's internal values as these numbers are published
58*38fd1498Szrj    so that other tools can build and read .gdb_index.  */
59*38fd1498Szrj 
60*38fd1498Szrj typedef enum {
61*38fd1498Szrj   /* Special value to indicate no attributes are present.  */
62*38fd1498Szrj   GDB_INDEX_SYMBOL_KIND_NONE = 0,
63*38fd1498Szrj   GDB_INDEX_SYMBOL_KIND_TYPE = 1,
64*38fd1498Szrj   GDB_INDEX_SYMBOL_KIND_VARIABLE = 2,
65*38fd1498Szrj   GDB_INDEX_SYMBOL_KIND_FUNCTION = 3,
66*38fd1498Szrj   GDB_INDEX_SYMBOL_KIND_OTHER = 4,
67*38fd1498Szrj   /* We currently allocate 3 bits to record the symbol kind.
68*38fd1498Szrj      Give the unused bits a value so gdb will print them sensibly.  */
69*38fd1498Szrj   GDB_INDEX_SYMBOL_KIND_UNUSED5 = 5,
70*38fd1498Szrj   GDB_INDEX_SYMBOL_KIND_UNUSED6 = 6,
71*38fd1498Szrj   GDB_INDEX_SYMBOL_KIND_UNUSED7 = 7
72*38fd1498Szrj } gdb_index_symbol_kind;
73*38fd1498Szrj 
74*38fd1498Szrj #define GDB_INDEX_SYMBOL_KIND_SHIFT 28
75*38fd1498Szrj #define GDB_INDEX_SYMBOL_KIND_MASK 7
76*38fd1498Szrj #define GDB_INDEX_SYMBOL_KIND_VALUE(cu_index) \
77*38fd1498Szrj   ((gdb_index_symbol_kind) (((cu_index) >> GDB_INDEX_SYMBOL_KIND_SHIFT) \
78*38fd1498Szrj 			    & GDB_INDEX_SYMBOL_KIND_MASK))
79*38fd1498Szrj #define GDB_INDEX_SYMBOL_KIND_SET_VALUE(cu_index, value) \
80*38fd1498Szrj   do { \
81*38fd1498Szrj     (cu_index) |= (((value) & GDB_INDEX_SYMBOL_KIND_MASK) \
82*38fd1498Szrj 		   << GDB_INDEX_SYMBOL_KIND_SHIFT); \
83*38fd1498Szrj   } while (0)
84*38fd1498Szrj 
85*38fd1498Szrj #define GDB_INDEX_RESERVED_SHIFT 24
86*38fd1498Szrj #define GDB_INDEX_RESERVED_MASK 15
87*38fd1498Szrj #define GDB_INDEX_RESERVED_VALUE(cu_index) \
88*38fd1498Szrj   (((cu_index) >> GDB_INDEX_RESERVED_SHIFT) & GDB_INDEX_RESERVED_MASK)
89*38fd1498Szrj 
90*38fd1498Szrj /* CU index.  */
91*38fd1498Szrj #define GDB_INDEX_CU_BITSIZE 24
92*38fd1498Szrj #define GDB_INDEX_CU_MASK ((1 << GDB_INDEX_CU_BITSIZE) - 1)
93*38fd1498Szrj #define GDB_INDEX_CU_VALUE(cu_index) ((cu_index) & GDB_INDEX_CU_MASK)
94*38fd1498Szrj #define GDB_INDEX_CU_SET_VALUE(cu_index, value) \
95*38fd1498Szrj   do { \
96*38fd1498Szrj     (cu_index) |= (value) & GDB_INDEX_CU_MASK; \
97*38fd1498Szrj   } while (0)
98*38fd1498Szrj 
99*38fd1498Szrj #endif /* GDB_INDEX_H */
100