]> git.saurik.com Git - apple/objc4.git/blob - runtime/objc-gdb.h
objc4-779.1.tar.gz
[apple/objc4.git] / runtime / objc-gdb.h
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
24 #ifndef _OBJC_GDB_H
25 #define _OBJC_GDB_H
26
27 /*
28 * WARNING DANGER HAZARD BEWARE EEK
29 *
30 * Everything in this file is for debugger and developer tool use only.
31 * These will change in arbitrary OS updates and in unpredictable ways.
32 * When your program breaks, you get to keep both pieces.
33 */
34
35 #ifdef __APPLE_API_PRIVATE
36
37 #ifndef _OBJC_PRIVATE_H_
38 # define _OBJC_PRIVATE_H_
39 #endif
40 #include <stdint.h>
41 #include <objc/hashtable.h>
42 #include <objc/maptable.h>
43
44 __BEGIN_DECLS
45
46
47 /***********************************************************************
48 * Class pointer preflighting
49 **********************************************************************/
50
51 // Return cls if it's a valid class, or crash.
52 OBJC_EXPORT Class _Nonnull
53 gdb_class_getClass(Class _Nonnull cls)
54 #if __OBJC2__
55 OBJC_AVAILABLE(10.6, 3.1, 9.0, 1.0, 2.0);
56 #else
57 OBJC_AVAILABLE(10.7, 3.1, 9.0, 1.0, 2.0);
58 #endif
59
60 // Same as gdb_class_getClass(object_getClass(cls)).
61 OBJC_EXPORT Class _Nonnull gdb_object_getClass(id _Nullable obj)
62 OBJC_AVAILABLE(10.7, 4.3, 9.0, 1.0, 2.0);
63
64 /***********************************************************************
65 * Class inspection
66 **********************************************************************/
67
68 #if __OBJC2__
69
70 // Return the raw, mangled name of cls.
71 OBJC_EXPORT const char * _Nonnull
72 objc_debug_class_getNameRaw(Class _Nullable cls)
73 OBJC_AVAILABLE(10.15, 13.0, 13.0, 6.0, 5.0);
74
75 #endif
76
77 /***********************************************************************
78 * Class lists for heap.
79 **********************************************************************/
80
81 #if __OBJC2__
82
83 // Maps class name to Class, for in-use classes only. NXStrValueMapPrototype.
84 OBJC_EXPORT NXMapTable * _Nullable gdb_objc_realized_classes
85 OBJC_AVAILABLE(10.6, 3.1, 9.0, 1.0, 2.0);
86
87 // A generation count of realized classes. Increments when new classes
88 // are realized. This is NOT an exact count of the number of classes.
89 // It's not guaranteed by how much it increases when classes are
90 // realized, only that it increases by something. When classes are
91 // removed (unloading bundles or destroying dynamically allocated
92 // classes) the number will also increase to signal that there has
93 // been a change.
94 OBJC_EXPORT uintptr_t objc_debug_realized_class_generation_count;
95
96 #else
97
98 // Hashes Classes, for all known classes. Custom prototype.
99 OBJC_EXPORT NXHashTable * _Nullable _objc_debug_class_hash
100 __OSX_AVAILABLE(10.2)
101 __IOS_UNAVAILABLE __TVOS_UNAVAILABLE
102 __WATCHOS_UNAVAILABLE __BRIDGEOS_UNAVAILABLE;
103
104 #endif
105
106
107 /***********************************************************************
108 * Non-pointer isa
109 **********************************************************************/
110
111 #if __OBJC2__
112
113 // Extract isa pointer from an isa field.
114 // (Class)(isa & mask) == class pointer
115 OBJC_EXPORT const uintptr_t objc_debug_isa_class_mask
116 OBJC_AVAILABLE(10.10, 7.0, 9.0, 1.0, 2.0);
117
118 // Extract magic cookie from an isa field.
119 // (isa & magic_mask) == magic_value
120 OBJC_EXPORT const uintptr_t objc_debug_isa_magic_mask
121 OBJC_AVAILABLE(10.10, 7.0, 9.0, 1.0, 2.0);
122 OBJC_EXPORT const uintptr_t objc_debug_isa_magic_value
123 OBJC_AVAILABLE(10.10, 7.0, 9.0, 1.0, 2.0);
124
125 // Use indexed ISAs for targets which store index of the class in the ISA.
126 // This index can be used to index the array of classes.
127 OBJC_EXPORT const uintptr_t objc_debug_indexed_isa_magic_mask;
128 OBJC_EXPORT const uintptr_t objc_debug_indexed_isa_magic_value;
129
130 // Then these are used to extract the index from the ISA.
131 OBJC_EXPORT const uintptr_t objc_debug_indexed_isa_index_mask;
132 OBJC_EXPORT const uintptr_t objc_debug_indexed_isa_index_shift;
133
134 // And then we can use that index to get the class from this array. Note
135 // the size is provided so that clients can ensure the index they get is in
136 // bounds and not read off the end of the array.
137 OBJC_EXPORT Class _Nullable objc_indexed_classes[];
138
139 // When we don't have enough bits to store a class*, we can instead store an
140 // index in to this array. Classes are added here when they are realized.
141 // Note, an index of 0 is illegal.
142 OBJC_EXPORT uintptr_t objc_indexed_classes_count;
143
144 // Absolute symbols for some of the above values are in objc-abi.h.
145
146 #endif
147
148
149 /***********************************************************************
150 * Class structure decoding
151 **********************************************************************/
152 #if __OBJC2__
153
154 // Mask for the pointer from class struct to class rw data.
155 // Other bits may be used for flags.
156 // Use 0x00007ffffffffff8UL or 0xfffffffcUL when this variable is unavailable.
157 OBJC_EXPORT const uintptr_t objc_debug_class_rw_data_mask
158 OBJC_AVAILABLE(10.13, 11.0, 11.0, 4.0, 2.0);
159
160 #endif
161
162
163 /***********************************************************************
164 * Tagged pointer decoding
165 **********************************************************************/
166 #if __OBJC2__
167
168 // Basic tagged pointers (7 classes, 60-bit payload).
169
170 // if (obj & mask) obj is a tagged pointer object
171 OBJC_EXPORT uintptr_t objc_debug_taggedpointer_mask
172 OBJC_AVAILABLE(10.9, 7.0, 9.0, 1.0, 2.0);
173
174 // tagged pointers are obfuscated by XORing with a random value
175 // decoded_obj = (obj ^ obfuscator)
176 OBJC_EXPORT uintptr_t objc_debug_taggedpointer_obfuscator
177 OBJC_AVAILABLE(10.14, 12.0, 12.0, 5.0, 3.0);
178
179
180 // tag_slot = (obj >> slot_shift) & slot_mask
181 OBJC_EXPORT unsigned int objc_debug_taggedpointer_slot_shift
182 OBJC_AVAILABLE(10.9, 7.0, 9.0, 1.0, 2.0);
183 OBJC_EXPORT uintptr_t objc_debug_taggedpointer_slot_mask
184 OBJC_AVAILABLE(10.9, 7.0, 9.0, 1.0, 2.0);
185
186 // class = classes[tag_slot]
187 OBJC_EXPORT Class _Nullable objc_debug_taggedpointer_classes[]
188 OBJC_AVAILABLE(10.9, 7.0, 9.0, 1.0, 2.0);
189
190 // payload = (decoded_obj << payload_lshift) >> payload_rshift
191 // Payload signedness is determined by the signedness of the right-shift.
192 OBJC_EXPORT unsigned int objc_debug_taggedpointer_payload_lshift
193 OBJC_AVAILABLE(10.9, 7.0, 9.0, 1.0, 2.0);
194 OBJC_EXPORT unsigned int objc_debug_taggedpointer_payload_rshift
195 OBJC_AVAILABLE(10.9, 7.0, 9.0, 1.0, 2.0);
196
197
198 // Extended tagged pointers (255 classes, 52-bit payload).
199
200 // If you interrogate an extended tagged pointer using the basic
201 // tagged pointer scheme alone, it will appear to have an isa
202 // that is either nil or class __NSUnrecognizedTaggedPointer.
203
204 // if (ext_mask != 0 && (decoded_obj & ext_mask) == ext_mask)
205 // obj is a ext tagged pointer object
206 OBJC_EXPORT uintptr_t objc_debug_taggedpointer_ext_mask
207 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
208
209 // ext_tag_slot = (obj >> ext_slot_shift) & ext_slot_mask
210 OBJC_EXPORT unsigned int objc_debug_taggedpointer_ext_slot_shift
211 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
212 OBJC_EXPORT uintptr_t objc_debug_taggedpointer_ext_slot_mask
213 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
214
215 // class = ext_classes[ext_tag_slot]
216 OBJC_EXPORT Class _Nullable objc_debug_taggedpointer_ext_classes[]
217 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
218
219 // payload = (decoded_obj << ext_payload_lshift) >> ext_payload_rshift
220 // Payload signedness is determined by the signedness of the right-shift.
221 OBJC_EXPORT unsigned int objc_debug_taggedpointer_ext_payload_lshift
222 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
223 OBJC_EXPORT unsigned int objc_debug_taggedpointer_ext_payload_rshift
224 OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
225
226 #endif
227
228
229 /***********************************************************************
230 * Swift marker bits
231 **********************************************************************/
232 #if __OBJC2__
233 OBJC_EXPORT const uintptr_t objc_debug_swift_stable_abi_bit
234 OBJC_AVAILABLE(10.14.4, 12.2, 12.2, 5.2, 3.2);
235 #endif
236
237
238
239 /***********************************************************************
240 * AutoreleasePoolPage
241 **********************************************************************/
242 OBJC_EXTERN const uint32_t objc_debug_autoreleasepoolpage_magic_offset OBJC_AVAILABLE(10.15, 13.0, 13.0, 6.0, 5.0);
243 OBJC_EXTERN const uint32_t objc_debug_autoreleasepoolpage_next_offset OBJC_AVAILABLE(10.15, 13.0, 13.0, 6.0, 5.0);
244 OBJC_EXTERN const uint32_t objc_debug_autoreleasepoolpage_thread_offset OBJC_AVAILABLE(10.15, 13.0, 13.0, 6.0, 5.0);
245 OBJC_EXTERN const uint32_t objc_debug_autoreleasepoolpage_parent_offset OBJC_AVAILABLE(10.15, 13.0, 13.0, 6.0, 5.0);
246 OBJC_EXTERN const uint32_t objc_debug_autoreleasepoolpage_child_offset OBJC_AVAILABLE(10.15, 13.0, 13.0, 6.0, 5.0);
247 OBJC_EXTERN const uint32_t objc_debug_autoreleasepoolpage_depth_offset OBJC_AVAILABLE(10.15, 13.0, 13.0, 6.0, 5.0);
248 OBJC_EXTERN const uint32_t objc_debug_autoreleasepoolpage_hiwat_offset OBJC_AVAILABLE(10.15, 13.0, 13.0, 6.0, 5.0);
249
250 __END_DECLS
251
252 // APPLE_API_PRIVATE
253 #endif
254
255 // _OBJC_GDB_H
256 #endif