Skip to content

Commit

Permalink
methodName -> regex (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnno1962 committed Oct 12, 2022
1 parent 0177a4e commit ad29c21
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
9 changes: 5 additions & 4 deletions SwiftTrace/SwiftInterpose.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by John Holdsworth on 23/09/2020.
// Copyright © 2020 John Holdsworth. All rights reserved.
//
// $Id: //depot/SwiftTrace/SwiftTrace/SwiftInterpose.swift#73 $
// $Id: //depot/SwiftTrace/SwiftTrace/SwiftInterpose.swift#77 $
//
// Extensions to SwiftTrace using dyld_dynamic_interpose
// =====================================================
Expand Down Expand Up @@ -52,7 +52,7 @@ extension SwiftTrace {
}

return interpose(aBundle: bundlePath,
methodName: methodName ?? _typeName(aType)+".",
methodName: methodName ?? "^"+_typeName(aType)+"\\.",
patchClass: patchClass, onEntry: onEntry, onExit: onExit,
replaceWith: replaceWith)
}
Expand All @@ -62,7 +62,7 @@ extension SwiftTrace {
/// requires the linker flags -Xlinker -interposable.
/// - Parameters:
/// - aBundle: Patch to framework containing function
/// - methodName: The full name of the function
/// - methodName: Regex to match against function
/// - patchClass: normally not required
/// - onEntry: closure called on entry
/// - onExit: closure called on exit
Expand All @@ -72,13 +72,14 @@ extension SwiftTrace {
onEntry: EntryAspect? = nil,
onExit: ExitAspect? = nil,
replaceWith: nullImplementationType? = nil) -> Int {
let methodRegex = NSRegularExpression(regexp: methodName)
var interposes = [dyld_interpose_tuple]()
var symbols = [UnsafePointer<Int8>]()

for suffix in traceableFunctionSuffixes {
findSwiftSymbols(aBundle, suffix) { symval, symname, _, _ in
if let theMethod = SwiftMeta.demangle(symbol: symname),
theMethod.hasPrefix(methodName),
methodRegex.matches(theMethod),
interposeEclusions?.matches(theMethod) != true,
let current = interposed(replacee: symval),
let interpose = patchClass.init(name: theMethod,
Expand Down
5 changes: 2 additions & 3 deletions SwiftTrace/SwiftMeta.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/SwiftMeta.swift#103 $
// $Id: //depot/SwiftTrace/SwiftTrace/SwiftMeta.swift#105 $
//
// Requires https://github.com/johnno1962/StringIndex.git
//
Expand Down Expand Up @@ -703,7 +703,6 @@ extension NSRegularExpression {

func matches(_ string: String) -> Bool {
return rangeOfFirstMatch(in: string,
range: NSRange(string.startIndex ..< string.endIndex,
in: string)).location != NSNotFound
range: NSMakeRange(0, string.utf16.count)).location != NSNotFound
}
}
2 changes: 1 addition & 1 deletion 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#314 $
// $Id: //depot/SwiftTrace/SwiftTrace/SwiftTrace.swift#316 $
//

import Foundation
Expand Down

0 comments on commit ad29c21

Please sign in to comment.