objc-gdb.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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 lists for heap.
  56. **********************************************************************/
  57. #if __OBJC2__
  58. // Maps class name to Class, for in-use classes only. NXStrValueMapPrototype.
  59. OBJC_EXPORT NXMapTable * _Nullable gdb_objc_realized_classes
  60. OBJC_AVAILABLE(10.6, 3.1, 9.0, 1.0, 2.0);
  61. #else
  62. // Hashes Classes, for all known classes. Custom prototype.
  63. OBJC_EXPORT NXHashTable * _Nullable _objc_debug_class_hash
  64. __OSX_AVAILABLE(10.2)
  65. __IOS_UNAVAILABLE __TVOS_UNAVAILABLE
  66. __WATCHOS_UNAVAILABLE __BRIDGEOS_UNAVAILABLE;
  67. #endif
  68. /***********************************************************************
  69. * Non-pointer isa
  70. **********************************************************************/
  71. #if __OBJC2__
  72. // Extract isa pointer from an isa field.
  73. // (Class)(isa & mask) == class pointer
  74. OBJC_EXPORT const uintptr_t objc_debug_isa_class_mask
  75. OBJC_AVAILABLE(10.10, 7.0, 9.0, 1.0, 2.0);
  76. // Extract magic cookie from an isa field.
  77. // (isa & magic_mask) == magic_value
  78. OBJC_EXPORT const uintptr_t objc_debug_isa_magic_mask
  79. OBJC_AVAILABLE(10.10, 7.0, 9.0, 1.0, 2.0);
  80. OBJC_EXPORT const uintptr_t objc_debug_isa_magic_value
  81. OBJC_AVAILABLE(10.10, 7.0, 9.0, 1.0, 2.0);
  82. // Use indexed ISAs for targets which store index of the class in the ISA.
  83. // This index can be used to index the array of classes.
  84. OBJC_EXPORT const uintptr_t objc_debug_indexed_isa_magic_mask;
  85. OBJC_EXPORT const uintptr_t objc_debug_indexed_isa_magic_value;
  86. // Then these are used to extract the index from the ISA.
  87. OBJC_EXPORT const uintptr_t objc_debug_indexed_isa_index_mask;
  88. OBJC_EXPORT const uintptr_t objc_debug_indexed_isa_index_shift;
  89. // And then we can use that index to get the class from this array. Note
  90. // the size is provided so that clients can ensure the index they get is in
  91. // bounds and not read off the end of the array.
  92. OBJC_EXPORT Class _Nullable objc_indexed_classes[];
  93. // When we don't have enough bits to store a class*, we can instead store an
  94. // index in to this array. Classes are added here when they are realized.
  95. // Note, an index of 0 is illegal.
  96. OBJC_EXPORT uintptr_t objc_indexed_classes_count;
  97. // Absolute symbols for some of the above values are in objc-abi.h.
  98. #endif
  99. /***********************************************************************
  100. * Class structure decoding
  101. **********************************************************************/
  102. #if __OBJC2__
  103. // Mask for the pointer from class struct to class rw data.
  104. // Other bits may be used for flags.
  105. // Use 0x00007ffffffffff8UL or 0xfffffffcUL when this variable is unavailable.
  106. OBJC_EXPORT const uintptr_t objc_debug_class_rw_data_mask
  107. OBJC_AVAILABLE(10.13, 11.0, 11.0, 4.0, 2.0);
  108. #endif
  109. /***********************************************************************
  110. * Tagged pointer decoding
  111. **********************************************************************/
  112. #if __OBJC2__
  113. // Basic tagged pointers (7 classes, 60-bit payload).
  114. // if (obj & mask) obj is a tagged pointer object
  115. OBJC_EXPORT uintptr_t objc_debug_taggedpointer_mask
  116. OBJC_AVAILABLE(10.9, 7.0, 9.0, 1.0, 2.0);
  117. // tagged pointers are obfuscated by XORing with a random value
  118. // decoded_obj = (obj ^ obfuscator)
  119. OBJC_EXPORT uintptr_t objc_debug_taggedpointer_obfuscator
  120. OBJC_AVAILABLE(10.14, 12.0, 12.0, 5.0, 3.0);
  121. // tag_slot = (obj >> slot_shift) & slot_mask
  122. OBJC_EXPORT unsigned int objc_debug_taggedpointer_slot_shift
  123. OBJC_AVAILABLE(10.9, 7.0, 9.0, 1.0, 2.0);
  124. OBJC_EXPORT uintptr_t objc_debug_taggedpointer_slot_mask
  125. OBJC_AVAILABLE(10.9, 7.0, 9.0, 1.0, 2.0);
  126. // class = classes[tag_slot]
  127. OBJC_EXPORT Class _Nullable objc_debug_taggedpointer_classes[]
  128. OBJC_AVAILABLE(10.9, 7.0, 9.0, 1.0, 2.0);
  129. // payload = (decoded_obj << payload_lshift) >> payload_rshift
  130. // Payload signedness is determined by the signedness of the right-shift.
  131. OBJC_EXPORT unsigned int objc_debug_taggedpointer_payload_lshift
  132. OBJC_AVAILABLE(10.9, 7.0, 9.0, 1.0, 2.0);
  133. OBJC_EXPORT unsigned int objc_debug_taggedpointer_payload_rshift
  134. OBJC_AVAILABLE(10.9, 7.0, 9.0, 1.0, 2.0);
  135. // Extended tagged pointers (255 classes, 52-bit payload).
  136. // If you interrogate an extended tagged pointer using the basic
  137. // tagged pointer scheme alone, it will appear to have an isa
  138. // that is either nil or class __NSUnrecognizedTaggedPointer.
  139. // if (ext_mask != 0 && (decoded_obj & ext_mask) == ext_mask)
  140. // obj is a ext tagged pointer object
  141. OBJC_EXPORT uintptr_t objc_debug_taggedpointer_ext_mask
  142. OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
  143. // ext_tag_slot = (obj >> ext_slot_shift) & ext_slot_mask
  144. OBJC_EXPORT unsigned int objc_debug_taggedpointer_ext_slot_shift
  145. OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
  146. OBJC_EXPORT uintptr_t objc_debug_taggedpointer_ext_slot_mask
  147. OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
  148. // class = ext_classes[ext_tag_slot]
  149. OBJC_EXPORT Class _Nullable objc_debug_taggedpointer_ext_classes[]
  150. OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
  151. // payload = (decoded_obj << ext_payload_lshift) >> ext_payload_rshift
  152. // Payload signedness is determined by the signedness of the right-shift.
  153. OBJC_EXPORT unsigned int objc_debug_taggedpointer_ext_payload_lshift
  154. OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
  155. OBJC_EXPORT unsigned int objc_debug_taggedpointer_ext_payload_rshift
  156. OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
  157. #endif
  158. __END_DECLS
  159. // APPLE_API_PRIVATE
  160. #endif
  161. // _OBJC_GDB_H
  162. #endif