1 | #import <Foundation/Foundation.h> |
2 | |
3 | // Observable side effect that is changed when one of our trap functions is |
4 | // called. This should always retain its initial value in a successful test run. |
5 | const char *called_function = "none" ; |
6 | |
7 | // Below several trap functions are declared in different scopes that should |
8 | // never be called even though they share the name of some of the utility |
9 | // functions that LLDB has to call when updating the Objective-C class list |
10 | // (i.e. 'free' and 'objc_copyRealizedClassList_nolock'). |
11 | // All functions just indicate that they got called by setting 'called_function' |
12 | // to their own name. |
13 | |
14 | namespace N { |
15 | void free(void *) { called_function = "N::free" ; } |
16 | void objc_copyRealizedClassList_nolock(unsigned int *) { |
17 | called_function = "N::objc_copyRealizedClassList_nolock" ; |
18 | } |
19 | } |
20 | |
21 | struct Context { |
22 | void free(void *) { called_function = "Context::free" ; } |
23 | void objc_copyRealizedClassList_nolock(unsigned int *) { |
24 | called_function = "Context::objc_copyRealizedClassList_nolock" ; |
25 | } |
26 | }; |
27 | |
28 | @interface ObjCContext : NSObject { |
29 | } |
30 | - (void)free:(void *)p; |
31 | - (void)objc_copyRealizedClassList_nolock:(unsigned int *)outCount; |
32 | @end |
33 | |
34 | @implementation ObjCContext |
35 | - (void)free:(void *)p { |
36 | called_function = "ObjCContext::free" ; |
37 | } |
38 | |
39 | - (void)objc_copyRealizedClassList_nolock:(unsigned int *)outCount { |
40 | called_function = "ObjCContext::objc_copyRealizedClassList_nolock" ; |
41 | } |
42 | @end |
43 | |
44 | int main(int argc, char **argv) { |
45 | id str = @"str" ; |
46 | // Make sure all our conflicting functions/methods are emitted. The condition |
47 | // is never executed in the test as the process is launched without args. |
48 | if (argc == 1234) { |
49 | Context o; |
50 | o.free(nullptr); |
51 | o.objc_copyRealizedClassList_nolock(nullptr); |
52 | N::free(nullptr); |
53 | N::objc_copyRealizedClassList_nolock(nullptr); |
54 | ObjCContext *obj = [[ObjCContext alloc] init]; |
55 | [obj free:nullptr]; |
56 | [obj objc_copyRealizedClassList_nolock:nullptr]; |
57 | } |
58 | return 0; // break here |
59 | } |
60 | |