brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.9 KiB · 0ec8250 Raw
60 lines · plain
1#import <Foundation/Foundation.h>2 3// Observable side effect that is changed when one of our trap functions is4// called. This should always retain its initial value in a successful test run.5const char *called_function = "none";6 7// Below several trap functions are declared in different scopes that should8// never be called even though they share the name of some of the utility9// functions that LLDB has to call when updating the Objective-C class list10// (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 14namespace N {15void free(void *) { called_function = "N::free"; }16void objc_copyRealizedClassList_nolock(unsigned int *) {17  called_function = "N::objc_copyRealizedClassList_nolock";18}19}20 21struct 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@end33 34@implementation ObjCContext35- (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@end43 44int main(int argc, char **argv) {45  id str = @"str";46  // Make sure all our conflicting functions/methods are emitted. The condition47  // 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 here59}60