objc-gdb.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /*
  2. * Copyright (c) 2008 Apple Inc. All Rights Reserved.
  3. *
  4. * @APPLE_LICENSE_HEADER_START@
  5. *
  6. * This file contains Original Code and/or Modifications of Original Code
  7. * as defined in and that are subject to the Apple Public Source License
  8. * Version 2.0 (the 'License'). You may not use this file except in
  9. * compliance with the License. Please obtain a copy of the License at
  10. * http://www.opensource.apple.com/apsl/ and read it before using this
  11. * file.
  12. *
  13. * The Original Code and all software distributed under the License are
  14. * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  15. * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  16. * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
  18. * Please see the License for the specific language governing rights and
  19. * limitations under the License.
  20. *
  21. * @APPLE_LICENSE_HEADER_END@
  22. */
  23. #ifndef _OBJC_GDB_H
  24. #define _OBJC_GDB_H
  25. /*
  26. * WARNING DANGER HAZARD BEWARE EEK
  27. *
  28. * Everything in this file is for debugger and developer tool use only.
  29. * These will change in arbitrary OS updates and in unpredictable ways.
  30. * When your program breaks, you get to keep both pieces.
  31. */
  32. #ifdef __APPLE_API_PRIVATE
  33. #ifndef _OBJC_PRIVATE_H_
  34. # define _OBJC_PRIVATE_H_
  35. #endif
  36. #include <stdint.h>
  37. #include <objc/hashtable.h>
  38. #include <objc/maptable.h>
  39. __BEGIN_DECLS
  40. /***********************************************************************
  41. * Class pointer preflighting
  42. **********************************************************************/
  43. // Return cls if it's a valid class, or crash.
  44. OBJC_EXPORT Class _Nonnull
  45. gdb_class_getClass(Class _Nonnull cls)
  46. #if __OBJC2__
  47. OBJC_AVAILABLE(10.6, 3.1, 9.0, 1.0, 2.0);
  48. #else
  49. OBJC_AVAILABLE(10.7, 3.1, 9.0, 1.0, 2.0);
  50. #endif
  51. // Same as gdb_class_getClass(object_getClass(cls)).
  52. OBJC_EXPORT Class _Nonnull gdb_object_getClass(id _Nullable obj)
  53. OBJC_AVAILABLE(10.7, 4.3, 9.0, 1.0, 2.0);
  54. /***********************************************************************
  55. * Class inspection
  56. **********************************************************************/
  57. #if __OBJC2__
  58. // Return the raw, mangled name of cls.
  59. OBJC_EXPORT const char * _Nonnull
  60. objc_debug_class_getNameRaw(Class _Nullable cls)
  61. OBJC_AVAILABLE(10.15, 13.0, 13.0, 6.0, 5.0);
  62. #endif
  63. /***********************************************************************
  64. * Class lists for heap.
  65. **********************************************************************/
  66. #if __OBJC2__
  67. // Maps class name to Class, for in-use classes only. NXStrValueMapPrototype.
  68. OBJC_EXPORT NXMapTable * _Nullable gdb_objc_realized_classes
  69. OBJC_AVAILABLE(10.6, 3.1, 9.0, 1.0, 2.0);
  70. // A generation count of realized classes. Increments when new classes
  71. // are realized. This is NOT an exact count of the number of classes.
  72. // It's not guaranteed by how much it increases when classes are
  73. // realized, only that it increases by something. When classes are
  74. // removed (unloading bundles or destroying dynamically allocated
  75. // classes) the number will also increase to signal that there has
  76. // been a change.
  77. OBJC_EXPORT uintptr_t objc_debug_realized_class_generation_count;
  78. #else
  79. // Hashes Classes, for all known classes. Custom prototype.
  80. OBJC_EXPORT NXHashTable * _Nullable _objc_debug_class_hash
  81. __OSX_AVAILABLE(10.2)
  82. __IOS_UNAVAILABLE __TVOS_UNAVAILABLE
  83. __WATCHOS_UNAVAILABLE __BRIDGEOS_UNAVAILABLE;
  84. #endif
  85. /***********************************************************************
  86. * Non-pointer isa
  87. **********************************************************************/
  88. #if __OBJC2__
  89. // Extract isa pointer from an isa field.
  90. // (Class)(isa & mask) == class pointer
  91. OBJC_EXPORT const uintptr_t objc_debug_isa_class_mask
  92. OBJC_AVAILABLE(10.10, 7.0, 9.0, 1.0, 2.0);
  93. // Extract magic cookie from an isa field.
  94. // (isa & magic_mask) == magic_value
  95. OBJC_EXPORT const uintptr_t objc_debug_isa_magic_mask
  96. OBJC_AVAILABLE(10.10, 7.0, 9.0, 1.0, 2.0);
  97. OBJC_EXPORT const uintptr_t objc_debug_isa_magic_value
  98. OBJC_AVAILABLE(10.10, 7.0, 9.0, 1.0, 2.0);
  99. // Use indexed ISAs for targets which store index of the class in the ISA.
  100. // This index can be used to index the array of classes.
  101. OBJC_EXPORT const uintptr_t objc_debug_indexed_isa_magic_mask;
  102. OBJC_EXPORT const uintptr_t objc_debug_indexed_isa_magic_value;
  103. // Then these are used to extract the index from the ISA.
  104. OBJC_EXPORT const uintptr_t objc_debug_indexed_isa_index_mask;
  105. OBJC_EXPORT const uintptr_t objc_debug_indexed_isa_index_shift;
  106. // And then we can use that index to get the class from this array. Note
  107. // the size is provided so that clients can ensure the index they get is in
  108. // bounds and not read off the end of the array.
  109. OBJC_EXPORT Class _Nullable objc_indexed_classes[];
  110. // When we don't have enough bits to store a class*, we can instead store an
  111. // index in to this array. Classes are added here when they are realized.
  112. // Note, an index of 0 is illegal.
  113. OBJC_EXPORT uintptr_t objc_indexed_classes_count;
  114. // Absolute symbols for some of the above values are in objc-abi.h.
  115. #endif
  116. /***********************************************************************
  117. * Class structure decoding
  118. **********************************************************************/
  119. #if __OBJC2__
  120. // Mask for the pointer from class struct to class rw data.
  121. // Other bits may be used for flags.
  122. // Use 0x00007ffffffffff8UL or 0xfffffffcUL when this variable is unavailable.
  123. OBJC_EXPORT const uintptr_t objc_debug_class_rw_data_mask
  124. OBJC_AVAILABLE(10.13, 11.0, 11.0, 4.0, 2.0);
  125. #endif
  126. /***********************************************************************
  127. * Tagged pointer decoding
  128. **********************************************************************/
  129. #if __OBJC2__
  130. // Basic tagged pointers (7 classes, 60-bit payload).
  131. // if (obj & mask) obj is a tagged pointer object
  132. OBJC_EXPORT uintptr_t objc_debug_taggedpointer_mask
  133. OBJC_AVAILABLE(10.9, 7.0, 9.0, 1.0, 2.0);
  134. // tagged pointers are obfuscated by XORing with a random value
  135. // decoded_obj = (obj ^ obfuscator)
  136. OBJC_EXPORT uintptr_t objc_debug_taggedpointer_obfuscator
  137. OBJC_AVAILABLE(10.14, 12.0, 12.0, 5.0, 3.0);
  138. // tag_slot = (obj >> slot_shift) & slot_mask
  139. OBJC_EXPORT unsigned int objc_debug_taggedpointer_slot_shift
  140. OBJC_AVAILABLE(10.9, 7.0, 9.0, 1.0, 2.0);
  141. OBJC_EXPORT uintptr_t objc_debug_taggedpointer_slot_mask
  142. OBJC_AVAILABLE(10.9, 7.0, 9.0, 1.0, 2.0);
  143. // class = classes[tag_slot]
  144. OBJC_EXPORT Class _Nullable objc_debug_taggedpointer_classes[]
  145. OBJC_AVAILABLE(10.9, 7.0, 9.0, 1.0, 2.0);
  146. // payload = (decoded_obj << payload_lshift) >> payload_rshift
  147. // Payload signedness is determined by the signedness of the right-shift.
  148. OBJC_EXPORT unsigned int objc_debug_taggedpointer_payload_lshift
  149. OBJC_AVAILABLE(10.9, 7.0, 9.0, 1.0, 2.0);
  150. OBJC_EXPORT unsigned int objc_debug_taggedpointer_payload_rshift
  151. OBJC_AVAILABLE(10.9, 7.0, 9.0, 1.0, 2.0);
  152. // Extended tagged pointers (255 classes, 52-bit payload).
  153. // If you interrogate an extended tagged pointer using the basic
  154. // tagged pointer scheme alone, it will appear to have an isa
  155. // that is either nil or class __NSUnrecognizedTaggedPointer.
  156. // if (ext_mask != 0 && (decoded_obj & ext_mask) == ext_mask)
  157. // obj is a ext tagged pointer object
  158. OBJC_EXPORT uintptr_t objc_debug_taggedpointer_ext_mask
  159. OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
  160. // ext_tag_slot = (obj >> ext_slot_shift) & ext_slot_mask
  161. OBJC_EXPORT unsigned int objc_debug_taggedpointer_ext_slot_shift
  162. OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
  163. OBJC_EXPORT uintptr_t objc_debug_taggedpointer_ext_slot_mask
  164. OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
  165. // class = ext_classes[ext_tag_slot]
  166. OBJC_EXPORT Class _Nullable objc_debug_taggedpointer_ext_classes[]
  167. OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
  168. // payload = (decoded_obj << ext_payload_lshift) >> ext_payload_rshift
  169. // Payload signedness is determined by the signedness of the right-shift.
  170. OBJC_EXPORT unsigned int objc_debug_taggedpointer_ext_payload_lshift
  171. OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
  172. OBJC_EXPORT unsigned int objc_debug_taggedpointer_ext_payload_rshift
  173. OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
  174. #endif
  175. /***********************************************************************
  176. * Swift marker bits
  177. **********************************************************************/
  178. #if __OBJC2__
  179. OBJC_EXPORT const uintptr_t objc_debug_swift_stable_abi_bit
  180. OBJC_AVAILABLE(10.14.4, 12.2, 12.2, 5.2, 3.2);
  181. #endif
  182. /***********************************************************************
  183. * AutoreleasePoolPage
  184. **********************************************************************/
  185. OBJC_EXTERN const uint32_t objc_debug_autoreleasepoolpage_magic_offset OBJC_AVAILABLE(10.15, 13.0, 13.0, 6.0, 5.0);
  186. OBJC_EXTERN const uint32_t objc_debug_autoreleasepoolpage_next_offset OBJC_AVAILABLE(10.15, 13.0, 13.0, 6.0, 5.0);
  187. OBJC_EXTERN const uint32_t objc_debug_autoreleasepoolpage_thread_offset OBJC_AVAILABLE(10.15, 13.0, 13.0, 6.0, 5.0);
  188. OBJC_EXTERN const uint32_t objc_debug_autoreleasepoolpage_parent_offset OBJC_AVAILABLE(10.15, 13.0, 13.0, 6.0, 5.0);
  189. OBJC_EXTERN const uint32_t objc_debug_autoreleasepoolpage_child_offset OBJC_AVAILABLE(10.15, 13.0, 13.0, 6.0, 5.0);
  190. OBJC_EXTERN const uint32_t objc_debug_autoreleasepoolpage_depth_offset OBJC_AVAILABLE(10.15, 13.0, 13.0, 6.0, 5.0);
  191. OBJC_EXTERN const uint32_t objc_debug_autoreleasepoolpage_hiwat_offset OBJC_AVAILABLE(10.15, 13.0, 13.0, 6.0, 5.0);
  192. __END_DECLS
  193. // APPLE_API_PRIVATE
  194. #endif
  195. // _OBJC_GDB_H
  196. #endif