gdb-index.h 3.8 KB

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