Skip to content

Commit

Permalink
Appkit exclusions.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnno1962 committed Oct 16, 2020
1 parent 15a97e4 commit 91baa62
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
11 changes: 3 additions & 8 deletions SwiftTrace/SwiftInterpose.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,15 @@ extension SwiftTrace {
subLevels: Int = 0) {
startNewTrace(subLevels: subLevels)
var interposes = [dyld_interpose_tuple]()
let isGlobal = NSRegularExpression(regexp: "^(\\w+\\.\\w+\\()")
var symbols = [String]()

for suffix in swiftFunctionSuffixes {
findSwiftSymbols(inBundlePath, suffix) {
symval, symname, _, _ in
if let methodName = demangle(symbol: symname),
!"^(\\w+\\.\\w+\\()".stMatches(methodName) &&
isGlobal.firstMatch(in: methodName, options: [],
range: NSMakeRange(0, methodName.utf16.count)) == nil &&
!methodName.contains("SwiftTrace") &&
!(methodName.contains(".getter :") && !methodName.hasSuffix("some")),
let factory = methodFilter(methodName),
Expand Down Expand Up @@ -158,11 +160,4 @@ extension SwiftTrace {
}
}
}

fileprivate extension String {
func stMatches(_ target: String) -> Bool {
return target.replacingOccurrences(of: self,
with: "___", options: .regularExpression) != target
}
}
#endif
7 changes: 5 additions & 2 deletions SwiftTrace/SwiftSwizzle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Copyright © 2020 John Holdsworth. All rights reserved.
//
// Repo: https://github.com/johnno1962/SwiftTrace
// $Id: //depot/SwiftTrace/SwiftTrace/SwiftSwizzle.swift#33 $
// $Id: //depot/SwiftTrace/SwiftTrace/SwiftSwizzle.swift#34 $
//
// Mechanics of Swizzling Swift
// ============================
Expand Down Expand Up @@ -186,7 +186,10 @@ extension SwiftTrace {
intArgs: &invocation.entryStack.pointee.intArg1)
if invocation.shouldDecorate && shouldTrace() {
ThreadLocal.current().caller()?.subLogged = true
print("\(subLogging() ? "\n" : "")\(String(repeating: SwiftTrace.traceIndent, count: invocation.stackDepth))\(entryDecorate(stack: &stack))", terminator: "")
let decorated = entryDecorate(stack: &stack)
let indent = String(repeating: SwiftTrace.traceIndent,
count: invocation.stackDepth)
print("\(subLogging() ? "\n" : "")\(indent)\(decorated)", terminator: "")
}
}
}
Expand Down
17 changes: 15 additions & 2 deletions SwiftTrace/SwiftTrace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Copyright © 2016 John Holdsworth. All rights reserved.
//
// Repo: https://github.com/johnno1962/SwiftTrace
// $Id: //depot/SwiftTrace/SwiftTrace/SwiftTrace.swift#244 $
// $Id: //depot/SwiftTrace/SwiftTrace/SwiftTrace.swift#246 $
//

import Foundation
Expand Down Expand Up @@ -108,6 +108,7 @@ open class SwiftTrace: NSObject {
Default pattern of common/problematic symbols to be excluded from tracing
*/
open class var defaultMethodExclusions: String {
#if !os(macOS)
return """
\\.getter| (?:retain|_tryRetain|release|autorelease|_isDeallocating|.cxx_destruct|_?dealloc|description| debugDescription|contextID)]|initWithCoder|\
^\\+\\[(?:Reader_Base64|UI(?:NibStringIDTable|NibDecoder|CollectionViewData|WebTouchEventsGestureRecognizer)) |\
Expand All @@ -116,6 +117,18 @@ open class SwiftTrace: NSObject {
_UIWindowSceneDeviceOrientationSettingsDiffAction _updateDeviceOrientationWithSettingObserverContext:windowScene:transitionContext:|\
UIColorEffect colorEffectSaturate:|UIWindow _windowWithContextId:|RxSwift.ScheduledDisposable.dispose| ns(?:li|is)_
"""
#else
return """
\\.getter| (?:retain(?:Count)?|_tryRetain|release|autorelease|_isDeallocating|.cxx_destruct|_?dealloc|class|description| debugDescription|\
contextID!undoManager|_animatorClassForTargetClass|cursorUpdate|_isTrackingAreaObject)]|initWithCoder|\
^\\+\\[(?:Reader_Base64|UI(?:NibStringIDTable|NibDecoder|CollectionViewData|WebTouchEventsGestureRecognizer)) |\
^.\\[(?:__NSAtom|NS(?:View|Appearance|AnimationContext|Segment|KVONotifying__)|_NSViewAnimator|UIView|RemoteCapture|BCEvent) |\
_TtGC7SwiftUI|NSTheme|NSTracking|UIDeviceWhiteColor initWithWhite:alpha:|UIButton _defaultBackgroundImageForType:andState:|\
UIImage _initWithCompositedSymbolImageLayers:name:alignUsingBaselines:|\
_UIWindowSceneDeviceOrientationSettingsDiffAction _updateDeviceOrientationWithSettingObserverContext:windowScene:transitionContext:|\
UIColorEffect colorEffectSaturate:|UIWindow _windowWithContextId:|RxSwift.ScheduledDisposable.dispose| ns(?:li|is)_
"""
#endif
}

static var exclusionRegexp: NSRegularExpression? =
Expand Down Expand Up @@ -561,7 +574,7 @@ extension NSRegularExpression {
try self.init(pattern: regexp)
}
catch let error as NSError {
fatalError(error.localizedDescription)
fatalError("Invalid regexp: \(regexp): \(error.localizedDescription)")
}
}

Expand Down

0 comments on commit 91baa62

Please sign in to comment.