Last active
December 16, 2019 15:27
-
-
Save bolencki13/c3e6bf6d9bb3e474b3053d5aa45eb376 to your computer and use it in GitHub Desktop.
Log Method Trace
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
#import <dlfcn.h> | |
void logTrace(BOOL on) { | |
typedef void functype(BOOL); | |
void *libobjc = dlopen("/usr/lib/libobjc.dylib", RTLD_LAZY); | |
functype *instrumentObjcMessageSends = dlsym(libobjc, "instrumentObjcMessageSends"); | |
if (!instrumentObjcMessageSends) { | |
NSLog(@"Couldn't get instrumentObjcMessageSends"); | |
exit(1); | |
} | |
instrumentObjcMessageSends(on); | |
NSLog(@"Logging enabled"); | |
} | |
/* | |
This will log all class and instance methods to a file. | |
The file is output in /tmp/msgSends-<PID> | |
This works on the simulator. | |
Tested on Xcode 8.3 iOS 10.3 | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
func logTrace(on: ObjCBool) { | |
let libobjc: UnsafeMutableRawPointer = dlopen("/usr/lib/libobjc.dylib", RTLD_LAZY) | |
guard let sym = dlsym(libobjc, "instrumentObjcMessageSends") else { | |
print("Could not find instrumentObjcMessageSends") | |
exit(1) | |
} | |
typealias instrumentObjcMessageSendsFunc = @convention(c) (_ on: ObjCBool) -> Int | |
let f = unsafeBitCast(sym,to: instrumentObjcMessageSendsFunc.self) | |
_ = f(on) | |
print("Logging enabled") | |
} | |
/* | |
This will log all class and instance methods to a file. | |
The file is output in /tmp/msgSends-<PID> | |
This works on the simulator. | |
Tested on Xcode 8.3 iOS 10.3 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment